Sub topic 1
What a host needs before it can talk on a network
Prerequisites
This chapter assumes you already know the following:
- How an IPv4 address and a subnet mask are written, for example 192.168.1.20 and 255.255.255.0.
- What a default gateway and a DNS server do, at a basic level.
- What a LAN, a router and a broadcast are.
- That client-server communication means one program asks and another answers.
You do not need to know anything about DHCP yet. This chapter explains the problem that DHCP solves.
The four settings every host needs
A host is any device on a network, such as a laptop, phone or printer. Before it can exchange traffic beyond its own cable or Wi-Fi link, it needs four pieces of configuration.
| Setting | Example | What it does |
|---|---|---|
| IP address | 192.168.1.20 | Identifies this host on its network. |
| Subnet mask | 255.255.255.0 | Tells the host which addresses are on its own subnet. |
| Default gateway | 192.168.1.1 | The router that receives traffic for other networks. |
| DNS server | 192.168.1.1 | Turns names such as example.com into IP addresses. |
Each setting answers a different question. The address says who the host is. The mask says who is nearby. The gateway says where to send everything else. The DNS server says how to find a destination by name.
How the host uses them
Every time the host sends a packet, it compares the destination address with its own address, using the mask. The result decides where the packet goes next.
import ipaddress
host = ipaddress.ip_interface("192.168.1.20/255.255.255.0")
gateway = ipaddress.ip_address("192.168.1.1")
for destination in ["192.168.1.77", "93.184.216.34"]:
dest = ipaddress.ip_address(destination)
if dest in host.network:
print(f"{dest}: same subnet, deliver directly")
else:
print(f"{dest}: other network, send to gateway {gateway}")The first destination is inside 192.168.1.0/24, so the host delivers it directly on the local link. The second is outside, so the host hands it to the gateway.
Where DNS fits in
Applications usually know a name, not an address. When you open a web page, the host first asks its DNS server for the address that belongs to the name. Only then can it build a packet. If the DNS server setting is missing, pinging an IP address may work while names fail.
What goes wrong when a setting is wrong or missing
The symptoms point to the faulty setting. They also help later when you troubleshoot DHCP.
- No address: the host cannot send normal IP traffic at all.
- Wrong mask: the host misjudges which addresses are local. It may try to reach a remote host directly, or send local traffic to the gateway.
- Missing or wrong gateway: local devices work, but nothing outside the subnet does.
- Missing or wrong DNS server: raw IP addresses work, but names fail to resolve.
- Duplicate address: two hosts claim the same address and both see intermittent failures.
The question this tutorial answers
The host gets these four values from somewhere. You could type them in on every device, but that approach has costs. The next chapter looks at why it fails as a network grows. After that, the tutorial shows how DHCP delivers all four values automatically when a device joins.
Exercise
A laptop has the address 192.168.1.20, the mask 255.255.255.0 and a correct gateway, but no DNS server. It can ping 8.8.8.8 but cannot open https://example.com. Which setting is missing, and why do the two tests give different results?
Show answer
The DNS server setting is missing. Pinging 8.8.8.8 uses an IP address, so no name lookup is needed and the packet goes through the gateway. Opening example.com needs a DNS lookup first, and without a DNS server the laptop cannot get the address for that name.
Exercise
A host has the address 10.0.5.20 and the mask 255.255.255.0. Does it deliver a packet for 10.0.6.9 directly or send it to the gateway?
Show answer
It sends the packet to the gateway. With a /24 mask the local subnet is 10.0.5.0 to 10.0.5.255, and 10.0.6.9 is outside it.