Installing and configuring isc-dhcp-server in Ubuntu

Here’s an example of installing isc-dhcp-server in Ubuntu Server.

Installation command:

sudo apt-get install isc-dhcp-server

Open the first configuration file:

sudo nano /etc/default/isc-dhcp-server

Specify the name of the interface from which the IP addresses will be sent (for example, eth0):

INTERFACES="eth0"

Suppose that this interface has a static address in /etc/network/interfaces:

auto eth0
iface eth0 inet static
address 192.168.5.1
netmask 255.255.255.0

Let’s make a backup copy of the second configuration file:

sudo mv /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.backup

Create a new one:

sudo nano /etc/dhcp/dhcpd.conf

And we will add the following parameters to it:

default-lease-time 600;
max-lease-time 7200;
authoritative;
log-facility local7;
 
shared-network cable {
 
subnet 192.168.5.0 netmask 255.255.255.0 {
range 192.168.5.10 192.168.5.254;
option domain-name-servers 192.168.5.1, 8.8.4.4;
option domain-name "example.net";
option routers 192.168.5.1;
option time-servers 192.168.5.1;
option broadcast-address 192.168.5.255;
default-lease-time 600;
max-lease-time 7200;
}
}

To reserve an IP address for a specific device, add after “max-lease-time 7200;” (before closing the quote “}”):

host test {
  hardware ethernet 00:01:02:aa:bb:cc;
  fixed-address 192.168.5.101;
}

It is more convenient for several hosts to specify one line:

host test { hardware ethernet 00:01:02:aa:bb:cc; fixed-address 192.168.5.101; }
host test2 { hardware ethernet 00:01:aa:aa:bb:cc; fixed-address 192.168.5.104; }

You can check whether dhcp server is started by the commands:

sudo service isc-dhcp-server status
sudo /etc/init.d/isc-dhcp-server status
sudo netstat -tulpn | grep :67

Restart the server for changes to the configuration files to take effect:

sudo service isc-dhcp-server restart
sudo /etc/init.d/isc-dhcp-server restart

You can see the issued IP by the command:

sudo less /var/lib/dhcp/dhcpd.leases

Logs are written to syslog (log-facility local7) to separate them, open the syslog configuration file in a text editor:

sudo nano /etc/rsyslog.d/50-default.conf

And in the end we add:

local7.*  /var/log/dhcp-server.log

After that they will be written in /var/log/syslog and in /var/log/dhcp-server.log

Let’s check if the DHCP server is running:

sudo netstat -tulpn | grep :67

An example of catching packages for analyzing problems via tcpdump:

sudo tcpdump port 67 or port 68 -e -n
sudo tcpdump ether host e0:cb:4e:c3:7c:44

In real time, you can watch logs like this:

tail -F /var/log/syslog | grep dhcpd
tail -F /var/log/syslog | grep 192.168.1.5
tail -F /var/log/syslog | grep e0:cb:4e:c3:7c:44

See also my articles:

Leave a comment

Leave a Reply