Skip to content

Why DHCP exists

Module
Getting Network Settings Automatically
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS, netlab 1.0, GNU Bash 5.2.21
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.

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.

Seven questions from laptop to web A horizontal line joins laptop to web through seven numbered circles. Station 1 is the focus: who gives the client its settings. laptop web 1 2 3 4 5 6 7
Seven questions from laptop to web A horizontal line joins laptop to web through seven numbered circles. Station 1 is the focus: who gives the client its settings. laptop web 1 2 3 4 5 6 7
Station 1 is the focus: who gives a machine its network settings.

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.

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.

Enable DHCP and inspect tablet
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:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Enable the settings service, enter tablet, and find no IPv4 address on eth0.
Steps (10)
  1. Type netlab mode dhcp on
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Output: Mode dhcp is on: router serves leases on the home network; tablet can join.
  7. Type netlab shell tablet
  8. Press Enter
  9. Type ip -4 address show eth0
  10. 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.

Add an address and test both destinations
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:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. An address and prefix allow two replies from phone, but the attempt to reach web reports Network is unreachable.
Steps (14)
  1. Type sudo ip address add 10.77.10.90/24 dev eth0
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter
  6. Type ip -4 address show eth0 # after manual address
  7. Press Enter
  8. 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
  9. Type ping -c 2 10.77.10.11
  10. Press Enter
  11. 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
  12. Type ping -c 2 10.77.20.80 # without a gateway
  13. Press Enter
  14. 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.

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.

Add the gateway and test again
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:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. After adding the default route, tablet receives both replies from web and lists its two routes.
Steps (8)
  1. Type sudo ip route add default via 10.77.10.1
  2. Press Enter
  3. Type ping -c 2 10.77.20.80 # with a gateway
  4. Press Enter
  5. 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
  6. Type ip route
  7. Press Enter
  8. 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.

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.

“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.

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.

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.

Remove the manual settings
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:~$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, networking lab (netlab 1.0), GNU Bash 5.2.21. Remove the gateway, test phone and web, then remove the address and verify cleanup.
Steps (17)
  1. Type sudo ip route del default via 10.77.10.1
  2. Press Enter
  3. Type ping -c 2 10.77.10.11 # after removing the gateway
  4. Press Enter
  5. 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
  6. Type ping -c 2 10.77.20.80 # after removing the gateway
  7. Press Enter
  8. Output: ping: connect: Network is unreachable
  9. Type sudo ip address del 10.77.10.90/24 dev eth0
  10. Press Enter
  11. Type ip -4 address show eth0 # manual address removed
  12. Press Enter
  13. Type ip route # manual route removed
  14. Press Enter
  15. Type exit
  16. Press Enter
  17. 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.