Sub topic 1
What a host needs before it can talk on a network
Before a device can send a single packet to another machine, it needs a small set of configuration values. DHCP exists to deliver those values automatically. This chapter defines them and shows how a host uses each one. It also lists the failures you see when one is wrong. Later chapters build on this, because you can only judge what DHCP must deliver once you know what the client needs.
Prerequisites
This chapter assumes you already know the following:
- How an IPv4 address is written (dotted decimal, four octets) and what a subnet mask or prefix length such as
/24means. - What a default gateway and a DNS server do, at the level of "the gateway forwards traffic off my network" and "DNS turns names into addresses".
- What a LAN, a router and a broadcast are.
- The client-server model: one program asks, another answers.
You do not need to know anything about DHCP itself yet.
The four required values
A host with an IPv4 interface needs four values to be useful on a typical network. The first two are required for any communication at all. The last two are required for communication beyond the local network and for using names.
| Value | Example | What it answers |
|---|---|---|
| IP address | 192.168.1.50 | Who am I? |
| Subnet mask (or prefix length) | 255.255.255.0 (/24) | Which addresses are on my own network? |
| Default gateway | 192.168.1.1 | Where do I send traffic for everything else? |
| DNS server | 192.168.1.1 | How do I turn a name into an address? |
Each value is covered below.
IP address
The IP address identifies the interface at the network layer. It must be unique within the network it is used on. If two hosts use the same address, each one sees traffic meant for the other, and connections to that address fail unpredictably. Note that an address belongs to an interface, not to a machine. A laptop with Wi-Fi and Ethernet has two interfaces and can have two addresses.
Subnet mask
The mask splits the address into a network part and a host part. With 192.168.1.50/24, the first 24 bits are the network (192.168.1) and the last 8 bits identify the host. The mask matters because it lets the host make a routing decision for every packet it sends. It must compare the destination with its own network and decide whether the destination is reachable directly or only through a router.
Default gateway
The default gateway is the address of a router on the local network. The host sends to it any packet whose destination is outside its own network. The gateway must be inside the host's own subnet, because the host has to reach it directly. A gateway address outside the local subnet is a configuration error that the host cannot use.
DNS server
Applications use names such as example.com, but IP packets carry numeric addresses. The host asks a DNS server to resolve names. DNS is not needed to exchange packets, so a host with no DNS server can still ping 93.184.216.34 but cannot browse by name. Hosts usually receive more than one DNS server, so a failure of the first does not break name resolution.
The decision every outgoing packet goes through
The host combines the address, mask and gateway into one decision for each packet. It checks whether the destination lies inside its own network.
The following Python program implements the same decision with the standard ipaddress module. It runs as shown with Python 3.
import ipaddress
host = ipaddress.ip_interface("192.168.1.50/24")
gateway = ipaddress.ip_address("192.168.1.1")
# The gateway must be reachable directly, so it must be on-link.
assert gateway in host.network, "gateway is outside the local subnet"
def next_hop(destination: str) -> str:
dst = ipaddress.ip_address(destination)
if dst in host.network:
return f"{dst} is on-link: ARP for {dst}, send directly"
return f"{dst} is off-link: ARP for {gateway}, send to the gateway"
for target in ["192.168.1.77", "192.168.1.200", "8.8.8.8"]:
print(next_hop(target))The output is:
192.168.1.77 is on-link: ARP for 192.168.1.77, send directly
192.168.1.200 is on-link: ARP for 192.168.1.200, send directly
8.8.8.8 is off-link: ARP for 192.168.1.1, send to the gatewayNow change the first line to use /25 instead of /24. The network becomes 192.168.1.0/25, which covers only .0 to .127. The destination 192.168.1.200 is now treated as off-link, and the host sends the packet to the gateway instead of to the neighbor. Whether that still works depends on whether the gateway forwards it back. This is why a wrong mask often produces confusing, partial failures rather than a complete outage.
ARP and the link layer
On Ethernet, a frame needs a destination MAC address, not an IP address. The host uses ARP (Address Resolution Protocol) to learn the MAC address that goes with an on-link IP address. For off-link destinations, the host resolves the gateway's MAC address, and the frame carries the gateway's MAC while the IP packet still carries the final destination's IP address. This is the reason the gateway must be on-link: ARP only works within the local broadcast domain.
Values beyond the basic four
Real networks hand out more than four values. You will meet these in the chapter on DHCP options, but it helps to know now that they exist:
- A DNS search domain, so that typing
printercan expand toprinter.corp.example. - NTP servers, so devices agree on the time.
- A hostname or domain name.
- Vendor-specific settings, such as the address of a provisioning server for IP phones.
A host can work without these, but each saves manual work or enables a feature.
Looking at the values on a real host
You can read all four values on a machine you already use.
# Linux: address and prefix length
ip -4 addr show
# Linux: routing table, including the default gateway
ip route show
# Linux: DNS servers (systemd-resolved systems)
resolvectl status
# Linux: DNS servers (plain resolver file)
cat /etc/resolv.confIn the output of ip route show, the line beginning with default via gives the gateway, for example default via 192.168.1.1 dev eth0. A second line such as 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.50 shows the on-link network that the address and mask created.
On Windows, one command shows everything:
ipconfig /allLook for the IPv4 Address, Subnet Mask, Default Gateway and DNS Servers lines. On a DHCP-configured host, the same output also shows a DHCP Server address and lease times, which later chapters explain.
Common errors and how they look
Each missing or wrong value produces a recognizable symptom. Learning these symptoms makes later DHCP troubleshooting much faster.
| Wrong or missing value | Typical symptom | Quick check |
|---|---|---|
| Duplicate IP address | Intermittent connectivity, warnings about address conflicts | `arp -a` shows the same IP with two different MACs over time |
| Mask too long (for example /25 instead of /24) | Some local hosts unreachable, others work | Compare the host's mask with its neighbors' masks |
| Mask too short | Host treats distant addresses as local and sends ARP requests that no one answers | Compare the network in `ip route` with the real subnet |
| No default gateway | Local hosts reachable, internet and other subnets not | `ip route show` has no `default` line |
| Wrong gateway | Same as above, or the packets reach the wrong device | Ping the gateway, then check it is the router |
| No DNS server, or an unreachable one | Pinging `8.8.8.8` works, pinging `example.com` fails | Test with an IP address first, then a name |
Why this list leads to DHCP
You now have a concrete list of what a client must know. Every item must be right for that specific network, and every item can change. Setting these values by hand on one device is easy, but doing it correctly for hundreds of devices is where static configuration starts to fail. The next chapter describes that problem, and the rest of the tutorial shows how DHCP delivers these same values automatically.
Exercise
A host is configured with 10.0.4.130/25 and a default gateway of 10.0.4.1. It can reach the internet only intermittently. Using the mask, explain what is wrong with this configuration.
Show answer
A /25 mask makes the host's network 10.0.4.128/25, which covers 10.0.4.128 to 10.0.4.255. The gateway 10.0.4.1 is outside that range, so it is not on-link. The host cannot ARP for it, so it cannot use it as a gateway. Either the address and mask are wrong for this subnet (a /24 with network 10.0.4.0/24 would contain both), or the gateway is on a different subnet.
Exercise
From a Linux host, ping 8.8.8.8 succeeds but ping example.com fails with "Temporary failure in name resolution". Which of the four values is most likely wrong, and which command shows it?
Show answer
The DNS server setting. Routing works, because the packet to 8.8.8.8 reached its destination, so the address, mask and gateway are usable. Run resolvectl status or cat /etc/resolv.conf to see which DNS servers the host uses, and check that they are correct and reachable.