Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 9 of 46

Lesson: DHCP OverviewSwitch
โ† Linux Foundations

Network operations

DHCP Overview

How hosts get an address and other settings automatically with DHCP.

A host needs an address, a prefix length, a gateway and usually DNS servers before it can use a network. Typing these by hand on every device does not scale. DHCP, the Dynamic Host Configuration Protocol, hands them out automatically.

What you receive

A DHCP server can supply:

  • an IP address
  • the subnet mask
  • the default gateway (called the router option)
  • DNS servers
  • a lease time, how long you may use the address

In many homes the router is the DHCP server.

The four steps

For IPv4, a new client usually goes through this exchange, often remembered as DORA:

  1. Discover: the client broadcasts to find servers.
  2. Offer: a server proposes an address and settings.
  3. Request: the client says which offer it accepts.
  4. Acknowledge: the server confirms the lease.

DHCP uses UDP. Servers listen on port 67 and clients on port 68.

Broadcasts stay on the local network, so a server elsewhere needs a DHCP relay, often a function of the router.

Leases

An address is borrowed, not owned. The client tries to renew before the lease ends, by default starting about halfway through. If it cannot renew and the lease expires, it must stop using the address.

A reservation on the server gives the same address to a particular client every time, often matched by MAC address.

On Linux

Which program acts as the client depends on the distribution: NetworkManager, systemd-networkd, dhclient or dhcpcd, among others.

$ ip address show dev enp1s0
    inet 192.168.1.20/24 brd 192.168.1.255 scope global dynamic enp1s0
       valid_lft 85960sec preferred_lft 85960sec

Output is shortened. dynamic and the counting-down lifetime suggest the address was assigned with a time limit, typically by DHCP.

With NetworkManager, nmcli device show enp1s0 lists the settings. To read its logs:

$ journalctl -u NetworkManager
$ journalctl -u systemd-networkd

If no server answers, some systems assign themselves a 169.254.x.x link-local address, while others have none.

IPv6 can configure addresses through router advertisements (SLAAC), DHCPv6, or both.

Try it

Run ip address and look for dynamic. Compare your gateway from ip route with your router's address. Avoid releasing the lease on a remote machine, since you may lose your connection. The networking and SSH lab is a place to practise inspecting settings.

Check your understanding

DHCP Overview

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.