DHCP Configuration

DHCP (Dynamic Host Configuration Protocol) automatically assigns IP addresses, subnet masks, default gateways, and DNS servers to clients on a network. For Ubuntu servers, DHCP is typically used in development/test environments while production servers use static IPs. However, understanding how DHCP works and how to set up a DHCP server is an essential networking skill for managing lab environments, infrastructure networks, and bare-metal provisioning.

How DHCP works

DHCP DORA process:
  Client ──[DISCOVER]──────────────→ Broadcast (255.255.255.255)
  Server ──[OFFER: 192.168.1.50]──→ Client
  Client ──[REQUEST: I want .50]──→ Broadcast
  Server ──[ACK: .50 is yours]────→ Client

  Client now has:
    IP: 192.168.1.50
    Mask: 255.255.255.0
    Gateway: 192.168.1.1
    DNS: 8.8.8.8
    Lease time: 86400 seconds (24 hours)

Configuring an interface for DHCP

# In Netplan, DHCP is the simplest configuration:
# /etc/netplan/00-installer-config.yaml
network:
  version: 2
  ethernets:
    ens3:
      dhcp4: true           # Enable IPv4 DHCP
      dhcp6: false          # Disable IPv6 DHCP (optional)
      dhcp4-overrides:
        use-dns: true        # Accept DNS from DHCP
        use-routes: true     # Accept routes from DHCP

sudo netplan apply

DHCP lease files

# systemd-networkd stores DHCP lease info here:
ls /run/systemd/netif/leases/

# View the current lease
cat /run/systemd/netif/leases/2    # 2 = interface index for ens3

# dhclient stores leases here (if using dhclient):
cat /var/lib/dhcp/dhclient.leases

Lease file contents (key fields)

ADDRESS=192.168.1.50
NETMASK=255.255.255.0
ROUTER=192.168.1.1
DNS=8.8.8.8 1.1.1.1
LEASETIME=86400

Renewing and releasing leases

# Force DHCP renewal via networkctl (systemd-networkd)
sudo networkctl renew ens3

# Via dhclient (if using dhclient):
sudo dhclient -r ens3    # Release current lease
sudo dhclient ens3        # Request new lease

# If you changed DHCP server configuration:
sudo networkctl down ens3
sudo networkctl up ens3

Setting up isc-dhcp-server

sudo apt install -y isc-dhcp-server

# Configure the DHCP server
sudo nano /etc/dhcp/dhcpd.conf

/etc/dhcp/dhcpd.conf — basic configuration

option domain-name "lab.local";
option domain-name-servers 8.8.8.8, 1.1.1.1;

default-lease-time 86400;     # 24 hours
max-lease-time 604800;         # 7 days

# Which interface to listen on:
# /etc/default/isc-dhcp-server: INTERFACESv4="ens3"

subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.50 192.168.1.200;    # IP pool
  option routers 192.168.1.1;          # Default gateway
  option subnet-mask 255.255.255.0;
}
# Specify which interface to listen on
sudo nano /etc/default/isc-dhcp-server
# Set: INTERFACESv4="ens3"

sudo systemctl enable --now isc-dhcp-server
sudo systemctl status isc-dhcp-server

# View current leases
cat /var/lib/dhcpd/dhcpd.leases

Static DHCP reservations

# Assign a fixed IP to a specific MAC address
# Add inside /etc/dhcp/dhcpd.conf:
host server01 {
  hardware ethernet 52:54:00:12:34:56;    # Client's MAC address
  fixed-address 192.168.1.10;             # Always gets this IP
  option host-name "server01";
}

host printer01 {
  hardware ethernet 00:11:22:33:44:55;
  fixed-address 192.168.1.20;
}

# Reload DHCP server after config changes
sudo systemctl reload isc-dhcp-server    # If supported
sudo systemctl restart isc-dhcp-server  # Or full restart

Conclusion

For Ubuntu servers, configure DHCP in Netplan with dhcp4: true. For running a DHCP server on a local network, install isc-dhcp-server and configure the subnet block in /etc/dhcp/dhcpd.conf. Static DHCP reservations (fixed IP by MAC address) are better than hardcoding IPs on clients because the DHCP server remains the single source of truth for address assignments. Check /var/lib/dhcpd/dhcpd.leases to see which MAC addresses have received leases.

FAQ

Is DHCP Configuration important for Ubuntu administrators?+

Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.

Should I practice this on a live server?+

Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.

What should I do after reading this article?+

Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Hire Me for Support