0

I have a device that can be used in two different scenarios.

  1. One is that it is hooked up to an ordinary Ethernet LAN company network. This network has a DHCP server and the device is expected to be a DHCP client and automatically receive an IP address.

  2. The second scenario is that the device is plugged directly into a PC/Laptop using an Ethernet LAN cable. In that case, it is expected that the device chooses its own IP and also gives the PC/Laptop an IP. In that case, the device must assume the role of a DHCP server.

You probably already see where this is going. I don't want the user of the device to have to configure anything. They should be able to just plug it in and it works for them. Now, the problem is, reliably finding out whether there is another DHCP server in your network is hard. Yes I can make DHCP requests and so on. I'll find the server 99% of the time. But this one time where I don't find it (e.g. due to packet loss or long packet travel times), if my device then becomes DHCP server, it poisons the entire company network by giving out IP addresses in the wrong range. How can I solve this problem? Are there any protocols or safety measures I can take to be guaranteed to not interfere with a company network?

My device is a client device offering a service, kind of like a printer. It runs OpenWRT. I compile it myself and I control all the config files. The users typically run Windows 7,8 or 10. How can I enable APIPA on OpenWRT? Or can I enable AVAHI and is that compatible with Windows' APIPA?

5
  • 1
    First of all, Welcome to Super User! We always appreciate the contributions from our community members, but please do not submit a proposed edit as an answer. If it actually does answer the question, submit an answer accordingly. Please see the following Stack Exchange guidance regarding this scenario: Why do I need 50 reputation to comment? What can I do instead? Thanks for your help!
    – Run5k
    Commented Jun 7, 2018 at 22:42
  • The problem isn't establishing connections where there is no DHCP server, it is being aware of the services offered over the network in such cases. The DHCP and DNS servers on networks also advertise the services available. So knowing WHAT you're hoping to communicate over such networks will be helpful towards finding your a solution. Commented Jun 7, 2018 at 22:54
  • Perhaps you could alter the internal dhcp server on the device to only respond to requests from the first mac address it hears (and only in that case where it doesn't detect another dhcp server already active). Commented Jun 8, 2018 at 20:24
  • for #2. Is the pc/laptop a specific device or is any location?
    – cybernard
    Commented Jun 9, 2018 at 13:39
  • @cybernard It's any location. Imagine it is something like a printer. Plug it into a company network, plug it into a PC, anywhere, anytime. It should be plug and play.
    – Kenji
    Commented Jun 9, 2018 at 15:31

2 Answers 2

0

This is already built into most IP clients and it's called APIPA: Automatic Private IP Addressing.

When devices connect to a LAN where there is no DHCP server they talk amongst themselves and decide upon APIPA addresses. These are usually identified easily because they begin with 169.254... and often indicate there is no LAN management or internet access available.

They also mean, when you know you're connected to a network of some sort, that you can find the APIPA addresses of the other devices on the network and communicate with them using their addresses.

6
  • Thanks, this answer helped me a lot! Is there a way to use APIPA on a device running OpenWRT? While my Windows machines go to 169.254.x.x, my device runs OpenWRT which just stays at 0.0.0.0 when the DHCP Client cannot get an address, and I cannot seem to activate APIPA neither over uci nor the command line.
    – Kenji
    Commented Jun 8, 2018 at 9:56
  • APIPA makes more sense on client devices than it does on routers and modems, so I would guess that your OpenWRT device does not do APIPA by default, or at all. The best thing for your networking device would be to set it up with a static IP. Commented Jun 8, 2018 at 15:10
  • Well, I agree with you, but the thing is: My device is a client device. It has a little OpenWRT board inside that does a bit of switching and contains a WLAN access point, but it is not a router or a modem. You can think of it like a printer, it is essentially offering a service and the user can either plug it directly into their PC/Laptop or they can plug it into their home/company network.
    – Kenji
    Commented Jun 8, 2018 at 15:28
  • So, you may be using the device as a "client" device, but using the OpenWRT controller/software means the default network state of the device is not likely to contain the feature you want. I assume it is possible to configure or modify OpenWRT in order to handle APIPA when DHCP fails or is non-existent. I'd begin by researching OpenWRT and APIPA, and by modifying your question to focus it more narrowly based on what you've learned here. Commented Jun 8, 2018 at 15:33
  • Yes, I know it's not a default feature. I compile OpenWRT myself and I control all the config files so I can choose any configuration I want. I will modify my question to account for these details.
    – Kenji
    Commented Jun 8, 2018 at 15:36
0

On the router

iptables -I INPUT 1 -i eth0 -p udp -m mac  ! --mac-source XX:XX:XX:XX:XX:XX -j DROP

Change eth0 to your NIC.

Change the mac address.

The ! means NOT. This creates a white list of who your DHCP server will speak to. You could add the sport and/or dport options if necessary.

Turn on your DHCP server.

1
  • And how do I know what to whitelist? My device may be plugged into any company network, just like a printer (it's not a router or modem). I must make sure I don't start a DHCP server when there is already one in the network, even if it's a slow or sometimes unreachable DHCP server.
    – Kenji
    Commented Jun 9, 2018 at 11:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .