Create DHCP server on Ubuntu

From PedrosBrainDump

1. Install the DHCP Server

sudo apt update
sudo apt install isc-dhcp-server -y

2. Set the network interface

Edit the default configuration file:

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

Find this line:

INTERFACESv4=""

And replace it with your actual network interface (for example eth0, ens33, or enp0s3):

INTERFACESv4="eth0"

3. Configure the DHCP scope

Edit the main configuration file:

sudo nano /etc/dhcp/dhcpd.conf

Replace the contents with something like this:

default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 192.168.50.0 netmask 255.255.255.0 {
  range 192.168.50.10 192.168.50.100;
  option routers 192.168.50.1;
  option subnet-mask 255.255.255.0;
  option domain-name-servers 8.8.8.8, 1.1.1.1;
}

Explanation:

  • range: IP address pool to be handed out
  • routers: default gateway for clients
  • domain-name-servers: DNS servers provided to clients

4. Restart and enable the service

sudo systemctl restart isc-dhcp-server
sudo systemctl enable isc-dhcp-server

5. Verify it’s running

Check the service status:

sudo systemctl status isc-dhcp-server

Check the leases file for assigned IPs:

tail -f /var/lib/dhcp/dhcpd.leases