2

I have a handful of devices which are normally in separate networks (or perhaps not even connected to a network), and they use DHCP to get their IP addresses. Now I would like to run some script on each of them, eg. to update their firmware.

I want to connect them one at a time to my PC and run an update script, for which I need the device's IP address. One attractive solution would be for my script to always use the same IP and to configure my DHCP server to just offer the same IP address to every DHCPDISCOVER request it gets.

In pseudo dhcpd.conf, I want to say this:

host device-to-update {
    hardware ethernet *;
    fixed-address 192.168.1.100;
}

I've played around with classes a bit, but I haven't found a way to use them with fixed-address. The man page ominously says:

Please be aware that only the dhcp-client-identifier option and the hardware address can be used to match a host declaration

... so I suspect it might not be possible. Currently my workaround is to manage a pool of 1 address with a short lease time, which works OK, but has other drawbacks.

This is on Ubuntu 14.4 with isc-dhcp-server.

2
  • You can match the hardware with classes, but you'll still be back to a "1 lease pool" to assign the address. (Could you elaborate on the the other drawbacks you have about this?) Or you could send a dhcp-client-identifier and match that in a host declaration (simply replacing the hardware match with the dhcp-client-identifier). But this approach requires you to touch every client machine 2x (once to add it, once to remove it) -- if you're doing that might as well just can in a fixed ip and forget dhcp. I'll be happy to post an answer for either method if you like. Aug 25, 2015 at 12:29
  • The "other drawbacks" was really just that I have to pick an arbitrary lease duration. If I pick 60s, I can't plug one device in right after another (say, before having run the update script). If I pick something tiny, the device has to renew its IP constantly. I guess since network performance isn't important here, it doesn't matter anyway. And its certainly better than modifying the hosts. Aug 25, 2015 at 14:38

2 Answers 2

0

Another approach to this would be to use dnsmasq with a small range IP addresses with a really short lease time and then a dhcp-script option.

The script will be fired each time a new device connects and has the IP address assigned to the new device as an argument.

The arguments are:

  • operation (add, old, del which map to new, existing leases at restart , release iirc)
  • mac address
  • assigned IP address

Man page entry:

--dhcp-script=

Whenever a new DHCP lease is created, or an old one destroyed, or a TFTP file transfer completes, the executable specified by this option is run. must be an absolute pathname, no PATH search occurs. The arguments to the process are "add", "old" or "del", the MAC address of the host (or DUID for IPv6) , the IP address, and the hostname, if known. "add" means a lease has been created, "del" means it has been destroyed, "old" is a notification of an existing lease when dnsmasq starts or a change to MAC address or hostname of an existing lease (also, lease length or expiry and client-id, if --leasefile-ro is set and lease expiry if --script-on-renewal is set). If the MAC address is from a network type other than ethernet, it will have the network type prepended, eg "06-01:23:45:67:89:ab" for token ring. The process is run as root (assuming that dnsmasq was originally run as root) even if dnsmasq is configured to change UID to an unprivileged user.

This can be used to kick off the firmware upload to the device.

This method also means you should be able to do multiple devices at the same time as they can all be assigned different IP addresses by the DHCP server but have the firmware script know which device to connect to at any given time.

0

I solved this with the following rules:

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.100;
}

host device-to-update {
    host-identifier option dhcp-message-type 3;
    fixed-address 192.168.1.100;
}

Despite what the man page says, the host-identifier directive can indeed match one of a limited number of DHCPv4 variables. My rule says to use the fixed address when processing any message with DHCPv4 message type 3, which is DHCPREQUEST, which covers all new address leases.

For reference, the complete list of DHCPv4 message types is:

 1 = DHCPDISCOVER
 2 = DHCPOFFER
 3 = DHCPREQUEST
 4 = DHCPDECLINE
 5 = DHCPACK
 6 = DHCPNAK
 7 = DHCPRELEASE
 8 = DHCPINFORM
 9 = DHCPFORCERENEW
10 = DHCPLEASEQUERY
11 = DHCPLEASEUNASIGNED
12 = DHCPLEASEUNKNOWN
13 = DHCPLEASEACTIVE

You must log in to answer this question.

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