Blog IndexPosts by TagHome

More Complexity - dhcpd

Posted <2017-08-26 Sat 19:44> by Aaron S. Jackson.

The other day dhcpd stopped working on my ER-Lite 3 after adding a static assignment. Up until this point it had been seemingly flawless. I haven't really bothered investigating as to why this happened. The only thing I can remember changing prior to dhcpd being restarted is the order of the interface addresses, so I will assume that is the problem.

Anyway, it resulted in me having some more fun. Some DHCP servers will read /etc/ethers and /etc/hosts and produce static bindings. Unfortunately isc_dhcpd does not, and I would rather edit my zone file instead of the host file anyway. So, I built another little script called mkdhcpd.

This reads the /etc/ethers file and looks via the host name its IP address.

echo "# Built with /etc/mkdhcp.sh on" $(date) > /etc/dhcpd.conf
echo "# Define global settings in dhcpd-global.conf" >> /etc/dhcpd.conf
echo >> /etc/dhcpd.conf

cat /etc/dhcpd-global.conf >> /etc/dhcpd.conf

echo "# End of global settings" >> /etc/dhcpd.conf
echo >> /etc/dhcpd.conf

cat /etc/ethers | while read mac hostname ; do
    ip=$(cat /etc/named/rhwyd.co.uk.zone \
                | awk -v host=$hostname '$1 == host { print $4 }')

    if [ -z $ip ]; then continue; fi

    echo "host $hostname { hardware ethernet $mac ; fixed-address $ip; }" \
         >> /etc/dhcpd.conf
done

I define the subnets and any other global settings in dhcpd-global.conf, which is then copied into dhcpd.conf, and host declarations are appended to the end.

Pretty useless but easier than editing the static bindings on a router or switch. Which leads me to my final point: why are static bindings so disgusting on Cisco IOS? Prior to doing it with dhcpd on escher, I thought I would try it on my C2950 switch and was instantly reminded of the horrors. You essentially create pool for each binding. Why not a repeatable command (e.g. static-binding) inside the DHCP pool?

There is another way of doing it, which I think is nicer, but not supported on the version of IOS running on my switch. You basically have a fixed format file which can be loaded over tftp, some other protocol or of the local storage. However, the format is also quite disgusting and requires version headers etc.

Related posts:

Tags: networking

Blog IndexPosts by TagHome

Copyright 2007-2017 Aaron S. Jackson (modified: Sat 26 Aug 19:56:40 BST 2017)