Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Short Answer

DHCP hands out network settings so that nobody has to type them in on every device. A device that joins a network asks for an address, a DHCP server offers one, and the device uses it for the length of the lease. The server keeps track of which address is lent to which device, so that two devices do not get the same one.

The Four-Message Exchange

A device without an address does not know where the DHCP server is, so the exchange starts with a broadcast. The client uses UDP port 68 and the server UDP port 67.

  1. Discover: the client broadcasts a request for any DHCP server.
  2. Offer: each server that hears it offers an address and settings.
  3. Request: the client picks one offer and asks for it; because this is broadcast too, the other servers learn that their offers were declined.
  4. Acknowledge: the chosen server confirms, and the client configures its interface.

The initials give the common name, DORA. Many clients check with ARP that no other device already uses the address before they apply it.

Leases and Renewal

An address is lent, not given. The server sets the lease time, from minutes on busy guest networks to days on stable ones. The client renews before the lease ends: by default it first asks the same server about halfway through the lease, and if that server does not answer, it asks any server later in the lease. If the lease runs out without renewal, the client must stop using the address. A device that comes back after a short absence usually asks for its previous address and gets it again.

What DHCP Hands Out

SettingExample
Address and mask192.168.10.50/24
Gateway192.168.10.1
DNS servers192.168.10.1
Lease time24 hours
Domain, NTP, othersOptional

How the address, mask, and gateway fit together is explained in what is a subnet.

Reservations

A reservation tells the DHCP server to give one device the same address every time, matched by its MAC address or a client identifier. It keeps the address stable while the settings stay managed in one place, which is common for printers, access points, and lab machines. See what is a MAC address.

DHCP or a Static Address on a Server?

A server's address has to stay the same, because DNS records, firewall rules, and clients point to it. Two ways give that: a static configuration on the server, or DHCP with a reservation that never changes. Virtual servers often use the second, or cloud-init writes a static configuration at first boot; it varies by provider. If your server receives its address by DHCP, leave that in place unless your provider's documentation says otherwise.

Never start a DHCP server of your own on a network segment you share with others: a second server that answers requests can give other machines wrong settings.

The Linux Client Side

On Ubuntu, Netplan describes the interface. DHCP for IPv4 looks like this in a file under /etc/netplan/:

network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true

Apply changes with sudo netplan try, which rolls them back after a timeout (120 seconds by default) unless you confirm, so a mistake is less likely to lock you out. Keep the console in your provider's control panel at hand all the same. Then check the result:

networkctl status eth0
ip -br a

networkctl applies where systemd-networkd manages the interface, the usual case on Ubuntu Server. On AlmaLinux and Rocky Linux, NetworkManager does the job:

nmcli device show eth0
nmcli connection show

A connection whose ipv4.method is auto uses DHCP; manual means a static address. Debian servers that use ifupdown mark a DHCP interface with iface eth0 inet dhcp in /etc/network/interfaces. To move from DHCP to a fixed address, see Netplan static IP or nmcli static IP.

DHCPv6 and SLAAC

IPv6 has two ways to configure addresses automatically: SLAAC, where the host builds its own address from the /64 prefix its router announces, and DHCPv6, which works much like DHCP for IPv4 with its own messages. Many networks use SLAAC for addresses and announce DNS servers in router advertisements or through DHCPv6. In Netplan the matching key is dhcp6.

Was this answer helpful?
Loading...