4

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.

devicenull
  • 5,572
  • 1
  • 25
  • 31
  • Can you please add additional information on your networking setup? With the relay-agent on the switch dhcpd already knows for which subnet the request is, so why do you need to choose the subnet based on option 82? – Andreas Rogge May 10 '17 at 12:27

4 Answers4

2

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

bjoern
  • 21
  • 2
  • Based on my understanding of DNSMasq, the Lua functions are only executed *after* an IP is assigned. It's not possible to use the Lua functions to assign an IP. – devicenull Oct 19 '12 at 21:08
  • You are correct. I'm sorry, it seems I overlooked that in the manual. – bjoern Oct 20 '12 at 04:52
2

I guess you can do this with the hook-system supported by ISC Kea (which is the meant-to-be replacement for ISC dhcpd). In KEA you can write your own hooks that run at specific stages. In this case the subnet4_select and lease4_select hooks would have to be implemented. In subnet4_select you make KEA choose the right subnet and in lease4_select you make it offer the right IP-Adress. However, this way you will have to write quite an amount of C++ code.

Andreas Rogge
  • 2,670
  • 10
  • 24
  • This seems more of a comment than an answer. Would you care to expand? – chicks May 09 '17 at 18:31
  • In KEA you can write your own hooks that run at specific stages. In this case the `subnet4_select` and `lease4_select` hooks would have to be implemented. In `subnet4_select` you make KEA choose the right subnet and in `lease4_select` you make it offer the right IP-Adress. However, this way you _will_ have to write quite an amount of C++ code – Andreas Rogge May 10 '17 at 12:20
  • Kea could be the right answer, but this answer is close to being link-only. https://meta.stackexchange.com/questions/8231/are-answers-that-just-contain-links-elsewhere-really-good-answers If are going for the bounty I would hope you would make your answer more complete. – chicks May 10 '17 at 12:24
  • Your edited comment sounds like a step in the right direction. Why not add it to your answer? – chicks May 10 '17 at 12:24
1

I would use ISC dhcpd/Kea and configure different IPs using conditions based on options set in the DHCP request.

See also:

Mircea Vutcovici
  • 16,706
  • 4
  • 52
  • 80
0

See this ServerFault question to give you some starting points if your DHCP server is Windows. 198383 ISC has functionalility for this. There is a lot of info on their web-site. Google will help.

Anyway this is quite complicated as the relay info you will get from the switch is very vendor specific.
For a small network you can probably get a much easier setup by simply setting up DHCP reservations for all your clients. If that is not feasible, which you seem to imply, be prepared for a lot of work figuring out how to do this.

Tonny
  • 6,252
  • 1
  • 17
  • 31
  • I updated my initial post a bit. Getting Option 82 configured isn't really the problem, the problem is using that information without pregenerating a list of DHCP pools. – devicenull Oct 03 '12 at 21:29
  • I think I understand your intent, but I wonder if its worth the effort? It might be a lot simpler to pre-generate that list. If you can script the on-the-fly assignment you should be able to apply the same logic to generate that list. – Tonny Oct 03 '12 at 21:44
  • Well, the problem I have with the pregenerated stuff is that can be up to an hour out of date for us (that's the time between RANCID runs). Maybe it's worth investigating speeding up RANCID so we can pregenerate though. – devicenull Oct 03 '12 at 22:12
  • I'm very much interested in the details of your use-case. I have a hard time imagining any scenario in which you have a such fast-changing environment that you need to run RANCID that often and at the same time need to reshuffle your ip address-space across your VLAN's. About the only thing I can think of is that you are using multiple VLAN's to separate L2 traffic while you only have 1 L3 subnet (of limited size) spread across those vlans and equipment and access-ports get moved between vlans every couple of minutes. – Tonny Oct 04 '12 at 15:18
  • We run a datacenter. We'd like new machines to get provisioned (networking wise), then installed shortly after via PXE. There may not be a lot of time between the network setup and the machine needing an OS install. It's not so much that everything is constantly shifting, instead it's that changes need to be noticed fairly quickly. – devicenull Oct 05 '12 at 00:44