How to assign DHCP leases from a script

dhcp

I have an environment where there is one DHCP server servicing a number of different hosts/vlans. The switches are configured to forward the DHCP requests over (via ip-helper) and include information about the port (option 82). I'd like to take that information and translate it into an actual lease for the server.

I don't think it's particularly feasible for me to pregenerate a list of available leases, but I should be able to determine an address for a lease as it comes in.

Is there an DHCP server that can execute a script when it receives a request? (Note: I'm looking to assign the IP from the script, not have the DHCP server assign an IP then execute the script)

Edit: So, ultimately I'm trying to provide DHCP/PXE services over a large number of distinct vlans. This is so we can do OS installs via PXE booting without having to have a separate PXE vlan. I've got the switch config down no problem, and I have the DHCP server recognizing option 82.

I need a way to pull DHCP assignments from another system (this other system would know what subnet to use on what vlan), but I do not want to have to pregenerate a list of vlan:DHCP range pairs.

Best Answer

Maybe you should take a look at dnsmasq. It can execute external and internal (LUA) scripts. The option --leasefile-ro should be what you are looking for.

http://www.thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html