Skip to content

Instantly share code, notes, and snippets.

@danielmacuare
Last active April 15, 2019 05:42
Show Gist options
  • Save danielmacuare/34c58827f95c565f724f16ea1311e242 to your computer and use it in GitHub Desktop.
Save danielmacuare/34c58827f95c565f724f16ea1311e242 to your computer and use it in GitHub Desktop.

isc-dhcp-server

The following commands have been tested on Ubuntu 16.04
uname -a
Linux ubuntu 4.4.0-145-generic #171-Ubuntu SMP Tue Mar 26 12:43:40 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Process

0 - Install the tool sudo apt-get install isc-dhcp-server

1 - You need to edit /etc/default/isc-dhcp-server to specify the interfaces dhcpd should listen to. By default it listens to eth0. /etc/default/isc-dhcp-server

2 - Configure your dhcp scope, subnets, options etc. /etc/dhcp/dhcpd.conf

3 - Restart the service ------------ SystemD ------------

$ sudo systemctl stop isc-dhcp-server.service
$ sudo systemctl start isc-dhcp-server.service
$ sudo systemctl restart isc-dhcp-server.service
$ sudo systemctl status isc-dhcp-server.service
$ sudo systemctl enable isc-dhcp-server.service

------------ SysVinit ------------

$ sudo service isc-dhcp-server.service start
$ sudo service isc-dhcp-server.service enable

4 - Thsoot if needed

sudo systemctl status rsyslogd
sudo systemctl restart rsyslogd
ps aux | grep dhcp
sudo tcpdump -i ens38 -c 40 port 67 and port 68             # Received requests from the clients - Checl DORA Process
cat var/log/syslog | grep dhcpd                # Check the DORA Process here. - dhcpd in Ubuntu will logging messages to /var/log/syslog by default
cat /var/lib/dhcp/dhcpd.leases\~               # Check leases

5 - Examples

5.1 - cat /etc/dhcp/dhcpd.conf

log-facility local7;
default-lease-time 600;
max-lease-time 7200;
#option domain-name-servers 192.168.1.1, 192.168.1.2;
option domain-name "danielmacuare.com";
subnet 192.168.10.0 netmask 255.255.255.0 {
    range                 192.168.10.100 192.168.10.160;
    option routers        192.168.10.254;
    option subnet-mask    255.255.255.0;
    option broadcast-address 192.168.10.255;
    default-lease-time    86400;
    max-lease-time        86400;
    host r4 {
        hardware ethernet aa:bb:cc:00:06:21;
        fixed-address 192.168.10.133;
    }
    host r3 {
        hardware ethernet aa:bb:cc:00:05:21;
        fixed-address 192.168.10.134;
    }
    host r2 {
        hardware ethernet aa:bb:cc:00:04:21;
        fixed-address 192.168.10.135;
    }
    host r1 {
        hardware ethernet aa:bb:cc:00:03:21;
        fixed-address 192.168.10.136;
    }
    host internet {
        hardware ethernet aa:bb:cc:00:09:21;
        fixed-address 192.168.10.137;
    }
}

5.2 - cat /etc/default/isc-dhcp-server

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#    Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="ens38"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment