07 May 2011

Configuring DHCP Server on Ubuntu

I need to hook up my laptop to my desktop machine machine at home. My laptop also migrates between a number of other networks, all of which assign IP addresses dynamically. So it makes sense to replicate this scenario at home too. The DHCP server does this job and is pretty easy to configure.

Firstly you need to tell DHCP which network card to listen on. In my case this is trivial since my desktop only has one network card. For completeness though, this is achieved by editing /etc/default/dhcp3-server:

INTERFACES="eth0"

Next the DHCP server itself is configured via /etc/dhcp3/dhcpd.conf:

default-lease-time 600; max-lease-time 86400; authoritative; ddns-update-style ad-hoc; log-facility local7; option subnet-mask 255.255.255.0; option broadcast-address 192.168.0.255; option routers 192.168.0.254; option domain-name "noggin.za.org"; option domain-name-servers 192.168.0.1; subnet 192.168.0.0 netmask 255.255.255.0 { range 192.168.0.10 192.168.0.200; } host rockhopper { hardware ethernet 70:5a:b6:b0:00:ac; fixed-address 192.168.0.2; }

This is a very simple setup. The desktop machine has a static IP of 192.168.0.1 and netmask 255.255.255.0. My laptop has a reserved IP address of 192.168.0.2. All other machines that connect will be assigned addresses in the range 192.168.0.10 to 192.168.0.200.

Now all that remains is to start the DHCP server:

# /etc/init.d/dhcp3-server restart

If you are not the root user then you will have to do this with sudo.

Monitoring the behaviour via /var/log/syslog:

May  7 11:29:30 marge dhcpd: DHCPDISCOVER from 70:5a:b6:b0:00:ac via eth0 May  7 11:29:30 marge dhcpd: DHCPOFFER on 192.168.0.2 to 70:5a:b6:b0:00:ac via eth0 May  7 11:29:30 marge dhcpd: DHCPREQUEST for 192.168.0.2 (192.168.0.1) from 70:5a:b6:b0:00:ac via eth0 May  7 11:29:30 marge dhcpd: DHCPACK on 192.168.0.2 to 70:5a:b6:b0:00:ac via eth0

Which is for my laptop, which gets the reserved address. Then when i connected Claire's laptop:

May  7 13:21:44 marge dhcpd: DHCPDISCOVER from 00:1d:72:21:1f:ad via eth0 May  7 13:21:45 marge dhcpd: DHCPOFFER on 192.168.0.11 to 00:1d:72:21:1f:ad (acer-47cbe8a5ed) via eth0 May  7 13:21:45 marge dhcpd: DHCPREQUEST for 192.168.0.11 (192.168.0.1) from 00:1d:72:21:1f:ad (acer-47cbe8a5ed) via eth0 May  7 13:21:45 marge dhcpd: DHCPACK on 192.168.0.11 to 00:1d:72:21:1f:ad (acer-7cbe8a5ed) via eth0 May  7 13:21:50 marge dhcpd: DHCPINFORM from 192.168.0.11 via eth0 May  7 13:21:50 marge dhcpd: DHCPACK to 192.168.0.11 (00:1d:72:21:1f:ad) via eth0
Update to this post. It seems that the latest Ubuntu packages are slightly different. Start the DHCP server using

# /etc/init.d/isc-dhcp-server restart

No comments:

Post a Comment