Why DHCP exists
On this page
tablet has just joined the home network. Its cable is connected, but it has no IPv4 address. Give it enough settings to reach another machine, then enough to cross the router. Doing this by hand shows exactly which work an automatic service must replace.
Before you start
Section titled “Before you start”Finish TCP, UDP, and Ports. Use the lab installed in Installing the lab. Leave machine shells and run netlab reset from the VM if needed. Keep other modes off for these experiments. The lab stays closed to the internet.
Return to the first question
Section titled “Return to the first question”The first station asks how laptop got its settings. This module answers that question with tablet, a machine that starts without them.
The lab tool fixes laptop’s settings when it builds the network. It does not obtain them from a server. On a real home network, the router’s settings service from The combined home router would commonly supply them. Tablet lets you watch that service without pretending laptop used it.
Give tablet an address and a prefix
Section titled “Give tablet an address and a prefix”At the VM prompt run netlab mode dhcp on, then netlab shell tablet. The mode adds tablet and enables the router’s settings service. It does not start a client on tablet. Type your Ubuntu password when sudo asks; the terminal shows no characters.
That settings service uses a protocol called DHCP, which is why the mode is named dhcp. This lesson first does the service’s job by hand; its end explains DHCP properly.
learner@rootvolt:~$ netlab mode dhcp on[sudo] password for learner: Mode dhcp is on: router serves leases on the home network; tablet can join.learner@rootvolt:~$ netlab shell tabletlearner@tablet:~$ ip -4 address show eth0learner@tablet:~$ Steps (10)
- Type
netlab mode dhcp on - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
Mode dhcp is on: router serves leases on the home network; tablet can join. - Type
netlab shell tablet - Press Enter
- Type
ip -4 address show eth0 - Press Enter
ip -4 address show eth0 selects IPv4 addresses on that interface. Empty output here means there is none. It does not mean the interface is absent.
Predict: With only an address and a prefix, which lab machines can tablet reach?
Add 10.77.10.90/24 using the next replay. This unused address is outside the server’s pool. ip address add assigns it to eth0. Test phone and web after that single change. ping -c 2 sends two requests.
learner@tablet:~$ sudo ip address add 10.77.10.90/24 dev eth0[sudo] password for learner: learner@tablet:~$ ip -4 address show eth0 # after manual address18: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link-netns sw-home
inet 10.77.10.90/24 scope global eth0
valid_lft forever preferred_lft foreverlearner@tablet:~$ ping -c 2 10.77.10.11PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data.
64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.106 ms
64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.073 ms
--- 10.77.10.11 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1010ms
rtt min/avg/max/mdev = 0.073/0.089/0.106/0.016 mslearner@tablet:~$ ping -c 2 10.77.20.80 # without a gatewayping: connect: Network is unreachablelearner@tablet:~$ Steps (14)
- Type
sudo ip address add 10.77.10.90/24 dev eth0 - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Type
ip -4 address show eth0 # after manual address - Press Enter
- Output:
18: eth0@if17: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link-netns sw-home inet 10.77.10.90/24 scope global eth0 valid_lft forever preferred_lft forever - Type
ping -c 2 10.77.10.11 - Press Enter
- Output:
PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data. 64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.106 ms 64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.073 ms --- 10.77.10.11 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1010ms rtt min/avg/max/mdev = 0.073/0.089/0.106/0.016 ms - Type
ping -c 2 10.77.20.80 # without a gateway - Press Enter
- Output:
ping: connect: Network is unreachable
Check your answer
Phone is local under this prefix. Web is beyond the router. Tablet knows its local network but has no route for web yet.
Add the way out
Section titled “Add the way out”Run sudo ip route add default via 10.77.10.1. It adds the default route through router. Test web again before changing anything else.
learner@tablet:~$ sudo ip route add default via 10.77.10.1learner@tablet:~$ ping -c 2 10.77.20.80 # with a gatewayPING 10.77.20.80 (10.77.20.80) 56(84) bytes of data.
64 bytes from 10.77.20.80: icmp_seq=1 ttl=63 time=0.141 ms
64 bytes from 10.77.20.80: icmp_seq=2 ttl=63 time=0.062 ms
--- 10.77.20.80 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1010ms
rtt min/avg/max/mdev = 0.062/0.101/0.141/0.039 mslearner@tablet:~$ ip routedefault via 10.77.10.1 dev eth0
10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.90 learner@tablet:~$ Steps (8)
- Type
sudo ip route add default via 10.77.10.1 - Press Enter
- Type
ping -c 2 10.77.20.80 # with a gateway - Press Enter
- Output:
PING 10.77.20.80 (10.77.20.80) 56(84) bytes of data. 64 bytes from 10.77.20.80: icmp_seq=1 ttl=63 time=0.141 ms 64 bytes from 10.77.20.80: icmp_seq=2 ttl=63 time=0.062 ms --- 10.77.20.80 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1010ms rtt min/avg/max/mdev = 0.062/0.101/0.141/0.039 ms - Type
ip route - Press Enter
- Output:
default via 10.77.10.1 dev eth0 10.77.10.0/24 dev eth0 proto kernel scope link src 10.77.10.90
This time web answers. You changed the route, not the destination or its service. Ping times vary; your number will differ. Keep the result and the setting that changed together in your notes.
| Setting | What it is for | What fails without it |
|---|---|---|
| Address | Names this interface | Tablet cannot exchange ordinary IPv4 traffic with phone |
| Prefix | Identifies local destinations | Tablet cannot tell which addresses belong to its own network |
| Gateway | Provides a path beyond the local network | Reaching web reports Network is unreachable |
| Name server | Answers name lookups | Names such as web.lab.test cannot be looked up |
The fourth row describes a role, rather than a test performed here. All tests above use addresses. How DNS Finds Services teaches the name server and how a name becomes an address.
Replace repeated hand configuration
Section titled “Replace repeated hand configuration”Imagine doing this for fifty devices and their guests. You must choose unused addresses, enter the right prefix, and keep gateway and name-server settings consistent. A typing error can affect one device while the others work.
DHCP, the Dynamic Host Configuration Protocol, is the settings service from The combined home router. It carries settings automatically. A DHCP server offers them. A DHCP client asks for them and applies the answer. In this lab, those programs run on router and tablet.
DHCP is a different service from DNS. DHCP supplies configuration, which can include the address of a name server. DNS answers name questions. Receiving configuration does not itself answer those questions.
Mistakes to recognize
Section titled “Mistakes to recognize”“DHCP and DNS are the same thing.” One supplies settings; the other looks up names.
“DHCP gives you Internet.” A lease cannot create an outside path. Our lab remains isolated even when local configuration is correct.
Good to know
Section titled “Good to know”Manual configuration is still useful when a device needs fixed settings. Automatic configuration moves repeated choices into a service; it does not remove the need for correct choices.
Try it yourself
Section titled “Try it yourself”Predict whether phone and web will answer after removing only the default route. Run sudo ip route del default via 10.77.10.1, then test ping -c 2 10.77.10.11 and ping -c 2 10.77.20.80 before removing anything else. Compare both results with your prediction. Then run sudo ip address del 10.77.10.90/24 dev eth0, read ip -4 address show eth0 and ip route, and exit. The next lesson needs these manual settings removed.
Solution
Phone still answers because its local route remains. Web reports Network is unreachable after the default route is removed. Removing the address afterward removes the connected route too. The final empty readings confirm cleanup.
learner@tablet:~$ sudo ip route del default via 10.77.10.1learner@tablet:~$ ping -c 2 10.77.10.11 # after removing the gatewayPING 10.77.10.11 (10.77.10.11) 56(84) bytes of data.
64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.061 ms
--- 10.77.10.11 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.033/0.047/0.061/0.014 mslearner@tablet:~$ ping -c 2 10.77.20.80 # after removing the gatewayping: connect: Network is unreachablelearner@tablet:~$ sudo ip address del 10.77.10.90/24 dev eth0learner@tablet:~$ ip -4 address show eth0 # manual address removedlearner@tablet:~$ ip route # manual route removedlearner@tablet:~$ exitlogoutlearner@rootvolt:~$ Steps (17)
- Type
sudo ip route del default via 10.77.10.1 - Press Enter
- Type
ping -c 2 10.77.10.11 # after removing the gateway - Press Enter
- Output:
PING 10.77.10.11 (10.77.10.11) 56(84) bytes of data. 64 bytes from 10.77.10.11: icmp_seq=1 ttl=64 time=0.033 ms 64 bytes from 10.77.10.11: icmp_seq=2 ttl=64 time=0.061 ms --- 10.77.10.11 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1009ms rtt min/avg/max/mdev = 0.033/0.047/0.061/0.014 ms - Type
ping -c 2 10.77.20.80 # after removing the gateway - Press Enter
- Output:
ping: connect: Network is unreachable - Type
sudo ip address del 10.77.10.90/24 dev eth0 - Press Enter
- Type
ip -4 address show eth0 # manual address removed - Press Enter
- Type
ip route # manual route removed - Press Enter
- Type
exit - Press Enter
- Output:
logout
- Address and prefix support local delivery.
- A gateway supplies the default path beyond it.
- DHCP hands out settings, including the name server’s address; DNS answers name questions.
Next, The initial lease exchange shows tablet asking for settings.
Further reading
Section titled “Further reading”- RFC 2131: Dynamic Host Configuration Protocol, for the client and server roles.