Chapter 4 · Hands-on labs
Six small, beginner-friendly labs using only built-in Linux commands. Read a real IP header, bend the TTL to see a router drop a packet, force fragmentation, and work out a network address — type the command, read the output.
sudo apt install -y ipcalc. The ❯ is just the prompt — Copy grabs only the command. Replace eth0 with your interface if it differs.Your local neighbours (MAC only works between these — same link):
ip neigh
Your gateway — the only way off your LAN:
ip route | grep default
Reach a host across the world by IP — it works even though it shares no link with you:
ping -c 2 8.8.8.8
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.3 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=12.1 ms
ip neigh list and has no MAC you know — yet IP still reaches it, hop by hop, starting at your gateway. That’s the whole point of IP: a routable, cross-network address that MAC can’t provide.ip neigh output? If not, how did your ping still reach it? (answer below)Capture with full detail in Terminal A (-v prints the IP header):
sudo tcpdump -i any -v -c 1 -nn icmp
Send one ping in Terminal B:
ping -c 1 8.8.8.8
Read the header in Terminal A:
IP (tos 0x0, ttl 64, id 1, offset 0, flags [none], proto ICMP (1), length 28)
192.168.1.23 > 8.8.8.8: ICMP echo requestThere they are: ttl (hop budget), id (fragment group), flags (DF/MF), proto (what’s inside — ICMP/TCP/UDP), length, and the two stars: source & destination IP.
Send a packet that can only take ONE hop (-t 1 sets TTL = 1):
ping -c 1 -t 1 8.8.8.8
From 192.168.1.1 icmp_seq=1 Time to live exceeded
Your gateway decremented TTL 1 → 0, dropped the packet, and sent back an ICMP “Time exceeded”. That’s a router dropping a packet, live.
Now let it go further (TTL = 2 reaches the second router):
ping -c 1 -t 2 8.8.8.8
Traceroute IS this trick — TTL 1, 2, 3… reveals every router on the way:
traceroute -n 8.8.8.8
-t 1 ping — and is it the same as your default gateway from Lab 1? (answer below)Find your link’s MTU (the biggest a frame can be — usually 1500):
ip link show eth0
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 ...
Send a packet bigger than the MTU (-s 2000 = 2000-byte payload) — it gets split:
ping -c 1 -s 2000 8.8.8.8
Watch it as fragments in another terminal: sudo tcpdump -i any -nn 'icmp' shows two pieces of one packet.
Now forbid fragmentation (-M do sets the DF flag) — the kernel refuses:
ping -c 1 -M do -s 2000 8.8.8.8
ping: local error: message too long, mtu=1500
eth0 MTU, and why did the 2000-byte ping need to be fragmented? (answer below)Find your IP & mask:
ip -br addr show eth0
Let ipcalc apply the mask (it does the AND and shows everything):
ipcalc 192.168.100.23/24
Address: 192.168.100.23 Netmask: 255.255.255.0 = 24 Network: 192.168.100.0/24 HostMin: 192.168.100.1 HostMax: 192.168.100.254 Broadcast: 192.168.100.255 Hosts/Net: 254 Class C, Private Internet
The Network (.0) is the IP AND the mask; Broadcast is the .255; there are 254 usable hosts; and it’s Class C.
Try a Class A address and compare the scale:
ipcalc 10.0.0.5/8
10.0.0.5/8, what class is it and roughly how many hosts? (answer below)Talk to yourself — the loopback address tests your own NIC, no network needed:
ping -c 2 127.0.0.1
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.03 ms
Check your real IP — is it a private (RFC 1918) address?
ip -br addr show eth0
If it starts with 10., 172.16–31., or 192.168., it’s private — your router uses NAT to reach the Internet for you (that’s Chapter 5).
See the loopback interface itself — its address is always 127.0.0.1:
ip -br addr show lo
eth0 address public or private? Which RFC 1918 range (if any) does it fall in? (answer below)Lab 1. No — 8.8.8.8 isn’t a neighbour. Your ping reached it because IP is routable: the packet went to your gateway first, which forwarded it across networks (MAC alone could never do that).
Lab 2. Whatever your ttl line showed at the sender (Linux usually starts at 64; Windows 128). It counts down by 1 at each router.
Lab 3. The device that replied to the -t 1 ping is your default gateway — the first router, one hop away (the same IP as ip route’s default).
Lab 4. Your MTU is typically 1500 bytes. A 2000-byte ping is bigger than that, so IP must split it into fragments to fit the link — unless DF is set, in which case it’s dropped.
Lab 5. 10.0.0.5/8 → first octet 10 → Class A; a /8 has about 16.7 million hosts (16,777,214 usable).
Lab 6. Most likely private — if it begins with 10., 172.16–31., or 192.168., it’s an RFC 1918 address and needs NAT to reach the public Internet.
| This lab’s tool | Returns in… |
|---|---|
| TTL / traceroute (Lab 3) | Chapter 5 — ICMP Time Exceeded & how traceroute works |
| private addresses (Lab 6) | Chapter 5 — NAT translates private → public |
| masks / ipcalc (Lab 5) | Chapter 6 — subnetting (splitting a network up) |
| tcpdump IP header (Lab 2) | Every later chapter — your packet X-ray |