I'm planning a new feature on our product to support a LAN. Since the installation will be done by relatively non-technical people (it's for boats) I was thinking it would be useful to automatically detect whether we needed to provide a DHCP server or not, depending on one was already on the network. Is there an official way of checking whether there's already a DHCP server (or more than one) on the network?
We use Embedded Linux on the product.
fedora seems to have the following package in the repos "dhcp_probe"
Looks like the
man dhcp_probe
has some good pointers for DHCP discovery strategy that might be worth a look, even if you decided to go for crafting the packets yourself.Let's not confuse the word "official" with the concept of "generally accepted method".
One generally accepted method would be to issue a DHCPDiscover packet and look for a response.
If you have "dhcpcd" installed, you can use the "-T" flag, to get the "test" mode, which just echoes the settings, but does not actually set the IP address and the gateway.
and the output:
You could do your own DHCPDISCOVER to see if anything out there is configured to answer, but if the DHCP server is locked down to specifics MACS you may not get a response.
You could in theory do a UDP port scan for UDP67 and UDP68, but I'm not so sure that's a great idea as it's more likely to get flagged as possibly malicious behavior.
Generally speaking, products that are not network equipment should not be offering DHCP. It makes an actual sysadmin's job harder, especially if it has a tendency to turn on by default if it loses its settings.
That's one thing that always drove me batty about the old crappy Hawking Ethernet to USB "print server" converter boxes.
Send a DHCP request and wait to see if you get a DHCP offer.
Cruder method - set up a NIC so it recives an IP address via DHCP then check after a period whether it receives an APIPA address. If it receives an APIPA address it is unlikely there is an existing DHCP server connected to the network in question.