Configuring a DHCP server on FreeBSD
First, I had to install a suitable DHCP server:
# pkg install isc-dhcp44-server
Now enable it at boot time:
# cat >> /etc/rc.conf
dhcpd_enable="YES"
dhcpd_flags="-q"
dhcpd_conf="/usr/local/etc/dhcpd.conf"
dhcpd_ifaces="re0"
dhcpd_withumask="022"
^d
And write out a suitable configuration file:
# cat > /usr/local/etc/dhcpd.conf
option domain-name "home.fwaggle.org";
option domain-name-servers 10.0.0.1;
default-lease-time 600;
max-lease-time 7200;
authoritative;
ddns-update-style interim;
update-static-leases on;
subnet 10.0.0.0 netmask 255.0.0.0 {
range 10.0.1.1 10.0.1.254;
option routers 10.0.0.1;
}
key dhcpupdate {
algorithm hmac-md5;
secret SUPER_SECRET_KEY==;
}
zone home.fwaggle.org {
primary 10.0.0.1;
key dhcpupdate;
}
zone 10.in-addr.arpa {
primary 10.0.0.1;
key dhcpupdate;
}
group {
use-host-decl-names on;
option domain-name "home.fwaggle.org";
ddns-domainname "home.fwaggle.org";
include "/usr/local/etc/static-leases.conf";
}
^d
I generate static-leases.conf with this script:
#! /bin/sh
echo -n '' > static-leases.conf
while read line
do
host=$(echo "$line" | awk '{ print $1 }')
ip=$(echo "$line" | awk '{ print $3 }')
mac=$(echo "$line" | awk '{ print $2 }')
if [ "$host" != "" ]
then
echo -n " host $host { " >> static-leases.conf
echo -n "hardware ethernet $mac; " >> static-leases.conf
echo -n "fixed-address $ip; " >> static-leases.conf
echo "}" >> static-leases.conf
fi
done < static-leases.txt
But you can specify static host entries yourself fairly easy:
host fwaggle-desktop { hardware ethernet 2c:4d:54:d5:a5:da; fixed-address 10.0.0.2; }
Now start the DHCP server:
# service isc-dhcpd start
… and go try one of your devices which is not configured for a static IP - make sure there are no other DHCP servers on your LAN. Check /var/log/messages for any issues with Dynamic DNS, it should work as configured but I did a terrible job of documenting that portion.