How To Install DHCP Server In Linux

Apr 4, 2021 · 1 min read
How To Install DHCP Server In Linux

In the video below, we show you how to install DHCP server in Linux using Ubuntu 20.04 LTS and ISC DHCP server


We’ll also set up a DHCP Relay Agent and firewall rules to service DHCP requests in a different subnet

Useful links:
https://ubuntu.com/download/server

Installation and configuration example:

  1. Install Ubuntu and update the OS

  2. Install the ISC ( Internet Systems Consortium) DHCP service

    sudo apt install isc-dhcp-server

  3. Bind DHCP to a specific interface

    cd /etc/default  
    sudo cp isc-dhcp-server isc-dhcp-server.bak
    Check the interface name
    ip addr  
    Edit the config file
    sudo nano isc-dhcp-server

    INTERFACESv4="ens192"
    INTERFACESv6="ens192"

  4. Configure the DHCP service

    cd /etc/dhcp
    sudo cp dhcpd.conf dhcpd.conf.bak
    sudo nano dhcpd.conf

    # Global settings
    option domain-name "templab.lan";
    option domain-name-servers 172.16.17.10;
    
    default-lease-time 600;
    max-lease-time 7200;
    
    # Disable DDNS
    ddns-update-style none;
    
    # Server is the authoritative DHCP server i.e. the only one
    authoritative;
    
    # Local subnet for network topology
    subnet 172.16.17.0 netmask 255.255.255.0 {
    }
    
    # Pool to lease IP addresses from
    subnet 172.16.19.0 netmask 255.255.255.0 {
     range 172.16.19.100 172.16.19.250;
     option routers 172.16.19.254;
    }
    
    # Reserved IP address for a specific host
    host PC2 {
     hardware ethernet 00:0c:29:a9:d1:4c;
     fixed-address 172.16.19.40;
    }

  5. Start and check DHCP service

    sudo systemctl start isc-dhcp-server
    sudo systemctl status isc-dhcp-server

  6. DHCP Relay Agent
    Configure a DHCP Relay Agent on Layer 3 gateways to point to the DHCP server

  7. Firewall Rules to allow DHCP traffic
    Allow UDP traffic from the LAN subnet, source port 68, to the DHCP server, destination port 67

  8. Check leasing

    sudo dhcp-lease-list
    NOTE: This does not show reserved IPs. Check the config file for that

Sharing is caring!