DHCP

Configuring a DHCP server

Install the DHCP server

Note if using LDAP, there is a DHCP LDAP package (dhcp3-server-ldap) that uses LDAP as the backend

sudo apt-get install -y dhcp3-server

Configure the DHCP Server interface

If you have more than one network interface, define the interfaces that DHCP should listen on. By default it listens on eth0.

sudo vi /etc/default/dhcp3-server
...
INTERFACES="eth1"

Configure DHCP pool

sudo vi /etc/dhcp3/dhcpd.conf
...
# option definitions common to all supported networks...
option domain-name "internal";
option domain-name-servers 10.0.0.1, 10.0.0.7;
default-lease-time 600;
max-lease-time 7200;
# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
authoritative;
...
# Define the default network
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.200 10.0.0.225;
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.0.255;
option routers 10.0.0.254;
option ntp-servers 10.0.0.1;
option time-offset 0;
#	option netbios-name-servers 10.0.0.1;
}
# Servers
host marge {
hardware ethernet 00:24:21:26:61:FF;
fixed-address marge.internal;
}
host printer {
hardware ethernet 00:21:5A:B6:5E:88;
fixed-address printer.internal;
}
host wireless {
hardware ethernet 00:14:6C:E0:F1:3F;
fixed-address wireless.internal;
}
host myth {
hardware ethernet 00:15:17:C0:29:E6;
fixed-address myth.internal;
}
host frame {
hardware ethernet 00:12:0E:B3:C5:9F;
fixed-address frame.internal;
}
host annex {
hardware ethernet 00:80:2D:ED:02:AD;
fixed-address annex.internal;
}
# Clients
host bart {
hardware ethernet 00:30:1B:BC:83:A6;
fixed-address bart.internal;
}
host barney-fixed {
hardware ethernet 00:01:4A:F7:0E:05;
fixed-address barney-fixed.internal;
}
host barney-wireless {
hardware ethernet 00:13:02:1D:B2:E0;
fixed-address barney-wireless.internal;
}
host itchy-fixed {
hardware ethernet 00:0D:60:89:77:F1;
fixed-address itchy-fixed.internal;
}
host itchy-wireless {
hardware ethernet 00:17:F2:EB:B4:4C;
fixed-address itchy-wireless.internal;
}
host maggie-fixed {
hardware ethernet 00:16:CB:A2:F9:66;
fixed-address maggie-fixed.internal;
}
host maggie-wireless {
hardware ethernet 00:14:51:EF:91:D2;
fixed-address maggie-wireless.internal;
}
host atom-fixed {
hardware ethernet E0:CB:4E:01:F8:0D;
fixed-address atom-fixed.internal;
}
host mini-fixed {
hardware ethernet D4:9A:20:D9:4A:F6;
fixed-address mini-fixed.internal;
}
host mini-wireless {
hardware ethernet F8:1E:DF:F5:E1:72;
fixed-address mini-wireless.internal;
}
host shell-fixed {
hardware ethernet 00:1B:38:F0:A4:B2;
fixed-address shell-fixed.internal;
}
host shell-wireless {
hardware ethernet 00:1D:E0:BD:31:7D;
fixed-address shell-wireless.internal;
}
# Mobile clients
host rob-phone {
hardware ethernet 90:84:0D:65:A2:3D;
fixed-address rob-phone.internal;
}
host tanya-phone {
hardware ethernet 00:22:AA:13:63:5F;
fixed-address tanya-phone.internal;
}
# Routers, etc
host vodafone {
hardware ethernet 00:0E:59:18:9C:C7;
fixed-address vodafone.internal;
}

Restart DHCP

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

Storing files in a different location

If you want to keep the dhcp files on a different device, say a RAID device there’s a few more steps. It is assumed that the structure will be:\\

dhcp3\etc
sudo chown -R root:root dhcp3

The files that change are:

  • etc\dhcpd.conf

I have used symbolic links from the default /etc/dhcp3 directory

cd /etc/dhcp3
sudo mv dhcpd.conf dhcpd.conf.old
sudo ln -s /media/store/apps/dhcp3/etc/dhcpd.conf

Last job to do is update app-armor to allow /usr/sbin/dhcp3 access to these directories

sudo vi /etc/apparmor.d/usr.sbin.dhcpd3
...
/etc/dhcp3/ r,
/etc/dhcp3/** r,
/etc/dhcpd.conf r,
/etc/dhcpd_ldap.conf r,
# DHCP files are on RAID
/media/store/apps/etc/dhcp3/ r,
/media/store/apps/etc/dhcp3/** r,
...

Now update the profile

sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.dhcpd3

Finally restart DHCP

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

References

Ubuntugeek – how to install and configure dhcp server in ubuntu server
Yolinux – DHCP Server

Administration

View the leases:

ls -lrt /var/lib/dhcp3/