online posts 15
networking 101, part 2: hands on

task 2.2 · chapter 2 of 3: your network · 30 min

One wrong number

objective

Find out why broken-pc can reach the printer but not web, using only ip addr, ip route, ping and ip neigh. Then fix its prefix and give it a default gateway.

given
Lessons used3.2 CIDR, 2.1 the router and the gateway
Log inclick broken-pc on the Topology tab (and laptop to compare)
Nothing to writethe checker looks at broken-pc itself, and pings from it
new to this? step by stepbeginner
  1. Click broken-pc on the Topology tab. In the broken-pc tab: ip addr show eth1, ip route, ping -c 3 192.168.2.10 and ip neigh.
  2. Fix the prefix: ip addr del 192.168.1.30/16 dev eth1, then ip addr add 192.168.1.30/24 dev eth1.
  3. Challenge: web still doesn’t answer. Find out why, and fix it.
  4. Check task 2.2, under the guide.

more in meet the lab

1 explain

When a computer can reach some things and not others

The story

Somebody set up broken-pc by hand, instead of letting DHCP do it. They typed its IP address right: 192.168.1.30. But they typed the prefix as /16 instead of /24, and they forgot the gateway completely. Now its owner says: “I can print, but I can’t get to the website.”

That’s a real kind of fault, and it’s worth knowing well: a wrong prefix doesn’t break everything, which makes it harder to spot. You’ll find it the way an engineer would: look at what the computer believes, test, and compare with a computer that works.

What the prefix decides

From lesson 3.2: before sending anything, a host compares the destination’s network part with its own.

  • Same network? Send it straight there: ARP for the destination’s MAC address (task 2.1).
  • Different network? Send it to the default gateway.

The prefix decides where the network part ends, so it decides the answer. With /24, broken-pc’s network is 192.168.1.0/24: 192.168.1.0 to 192.168.1.255. With /16 it’s 192.168.0.0/16: everything from 192.168.0.0 to 192.168.255.255. That includes the printer, which is right, but it also includes web, at 192.168.2.10, which is wrong.

in one sentence The prefix decides which addresses a host thinks are on its own network, and so whether it ARPs for them or uses the gateway.

Two different error messages

ping tells you how it failed, and the two messages mean different things:

MessageWhat the computer is telling you
Destination Host UnreachableI think that address is on my network, I asked with ARP, and nobody answered.
Network is unreachableI have no idea where that network is: no route for it, and no default gateway.

in one sentence Host unreachable: it ARPed and got no answer. Network unreachable: it has no route at all.

2 show

What broken-pc believes

broken-pc:~# ip addr show eth1
...
    inet 192.168.1.30/16 scope global eth1

broken-pc:~# ip route
192.168.0.0/16 dev eth1 proto kernel scope link src 192.168.1.30

Compare with the laptop’s ip route from task 1.2:

laptop:~# ip route
default via 192.168.1.1 dev eth1
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.50
broken-pclaptop
its own network192.168.0.0/16: far too big192.168.1.0/24
default viamissing192.168.1.1, r1

The 192.168.0.0/16 dev eth1 line says: every address from 192.168.0.0 to 192.168.255.255 is right here on eth1. So for web, broken-pc ARPs, and nobody on its network has 192.168.2.10:

broken-pc:~# ping -c 3 192.168.2.10
PING 192.168.2.10 (192.168.2.10) 56(84) bytes of data.
From 192.168.1.30 icmp_seq=1 Destination Host Unreachable
From 192.168.1.30 icmp_seq=2 Destination Host Unreachable
From 192.168.1.30 icmp_seq=3 Destination Host Unreachable

broken-pc:~# ip neigh
192.168.2.10 dev eth1 FAILED

FAILED: it asked who has 192.168.2.10? and nobody answered.

3 follow along

Find it, then fix the prefix

  1. Log in to broken-pc: click broken-pc on the Topology tab. In the broken-pc tab, look at what it believes:

    run in the broken-pc tab
    ip addr show eth1
    ip route
    
  2. Test both directions of the complaint. The printer first, then web:

    run in the broken-pc tab
    ping -c 3 192.168.1.20
    ping -c 3 192.168.2.10
    ip neigh
    

    The printer answers. web gives Destination Host Unreachable, and the neighbour table has 192.168.2.10 ... FAILED. broken-pc thinks web is next door.

  3. Fix the prefix. An address and its prefix go together, so you remove the wrong one and add the right one:

    run in the broken-pc tab
    ip addr del 192.168.1.30/16 dev eth1
    ip addr add 192.168.1.30/24 dev eth1
    ip route
    

    ip route now says 192.168.1.0/24 dev eth1. Right size.

  4. Try web again:

    run in the broken-pc tab
    ping -c 3 192.168.2.10
    

    A different error now: ping: connect: Network unreachable. That’s progress. broken-pc knows web isn’t on its network, so it doesn’t ARP for it any more. But it doesn’t know where else to send it either.

    (Changes you make with ip last until the lab restarts. A real computer keeps its settings in a file, so they come back after a restart; here, Reset network in the top bar puts broken-pc back how it was.)

in one sentence ip addr del and ip addr add change an address and its prefix; ip route shows the effect straight away.

4 challenge

Get broken-pc to web

Make ping -c 3 192.168.2.10 work from broken-pc. The printer must still work too. Then click Check task 2.2, under the guide.

hint

Network is unreachable means no route. Which line does the laptop’s ip route have that broken-pc’s doesn’t? (Click laptop on the Topology tab to compare, in a tab of its own.)

hint

The command to add a route starts ip route add. A default route is written default via <gateway>.

show the solution
broken-pc:~# ip route add default via 192.168.1.1
broken-pc:~# ip route
default via 192.168.1.1 dev eth1
192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.30
broken-pc:~# ping -c 3 192.168.2.10
64 bytes from 192.168.2.10: icmp_seq=1 ttl=62 time=0.749 ms
...

Now broken-pc’s ip route matches the laptop’s, apart from its own address. That’s what DHCP would have given it in the first place: this is why most hosts use DHCP instead of being typed in by hand.

Look at ttl=62 in the answer. Every router a packet crosses takes 1 off its time to live. web sent its answer with 64, and two routers later it’s 62. Task 3.1 uses that.

5 check: run it, then prove it

Check task 2.2 under the guide, in the lab app

when it's right, you'll see

╭─ task 2.2 · one wrong number
│  ✓ broken-pc's address is 192.168.1.30/24 (follow along): it's 192.168.1.30/24
│  ✓ broken-pc's default gateway is r1, 192.168.1.1 (challenge): it's 192.168.1.1
│  ✓ broken-pc reaches the printer, on its own network (challenge)
│  ✓ broken-pc reaches web, two routers away (challenge)
╰─ 4/4 checks passed  verified