Routing¶
Exercise routing-annex.pdf · PDF
You open a web page hosted in California. Your packet leaves your PC, crosses maybe fifteen boxes in different countries, and arrives in a fraction of a second. Here is the surprising part: none of those boxes knows the whole way to California. Each one only knows which way to push the packet next. So how does it ever arrive?
For a week your group has lived on an island: 10.G.0.0/24. There are eight islands in this classroom and no bridges between them. Your PC cannot reach the PC of the group next to you, even though the cable runs under the same table. Today you build the roads.
What you will learn
- Read a routing table on Linux (
ip route) and on RouterOS (/ip route print) - Explain how a host decides between direct delivery and its default gateway
- Choose the route a packet takes when several match: the most specific wins
- Add static routes on RouterOS so that two LANs reach each other
- Follow a packet hop by hop with
tracerouteand find where it stops - Why a correct route can still give a failed ping: routes are needed in both directions
The signpost¶
Routing is the job of choosing where to send a packet next so that, junction after junction, it reaches its destination.
We keep one analogy for the whole page: road signs at a junction.
A router is a junction. It does not know the whole trip to anywhere. It only has a signpost: "for these addresses, take that exit". The next junction has its own signpost, and decides again. A packet crosses the world one signpost at a time. Each router it passes through is called a hop.
The signpost has a technical name:
A routing table is the list of rules a device uses to decide where each packet goes next. Each line says: "for this destination network, send it out this way".
flowchart LR
PC["<b>Your PC</b><br>first signpost"] -->|"hop 1"| R1["<b>Router A</b><br>a junction"]
R1 -->|"hop 2"| R2["<b>Router B</b><br>another junction"]
R2 -->|"hop 3"| DST["<b>Destination</b>"]
Your PC has a signpost too¶
Every host has a routing table, not only routers. Look at yours on Linux:
default via 10.3.0.1 dev enp3s0 proto dhcp metric 100
10.3.0.0/24 dev enp3s0 proto kernel scope link src 10.3.0.199 metric 100
Two lines, two signs. Read them from the bottom:
| Line | What it says | What the PC does |
|---|---|---|
10.3.0.0/24 dev enp3s0 |
"That is my own street." | Direct delivery: find the destination's MAC with ARP and send it straight there |
default via 10.3.0.1 |
"Everything else." | Hand the packet to 10.3.0.1, the default gateway |
default is short for 0.0.0.0/0: the network that contains every address. It is the sign that says "all other directions".
You can ask the kernel which sign it would use for a given address:
The answer for 10.3.0.50 has no via: it is in your own network, so it goes direct. The answer for 10.5.0.20 says via 10.3.0.1: it goes to the gateway. That is the whole decision a PC ever makes. How does it know whether an address is "in my network"? It applies its mask, exactly as you did by hand in Subnetting.
A router has more signs¶
A router works the same way, it just has more lines. On RouterOS:
DST-ADDRESS GATEWAY DISTANCE
DAC 10.3.0.0/24 bridge-lan 0
DAC 10.3.10.0/24 vlan10 0
DAC 10.3.20.0/24 vlan20 0
The letters on the left are flags:
| Flag | Means | How the line got there |
|---|---|---|
| C | Connected route: the router has an address in that network | It appeared by itself when you added the address |
| A | Active: the route is being used | |
| D | Dynamic: created by the router, not typed | |
| S | Static route: typed by a person | You will add some today |
Now a packet for 10.5.0.20 arrives. Which line matches? None. The router has no sign for it, so it drops the packet. That is exactly why the islands are islands.
When several lines match: the most specific wins¶
Often more than one line contains the destination. The router does not take the first one in the list. It takes the line with the longest mask, the most precise one:
Think of a signpost that says "Palma" and another that says "Palma, Calle Sindicato". If you are going to Calle Sindicato, you follow the more precise one. The default route only wins when nothing else matches.
Careful: looking local is not a route
A router has connected routes for 10.3.0.0/24, 10.3.10.0/24 and 10.3.20.0/24, plus a default route. A packet for 10.4.0.1 arrives. It looks like a neighbour, but no line contains it except 0.0.0.0/0. So it goes to the default gateway. The router only knows what is written on its signpost.
Joining the islands: static routes¶
To connect the classroom, every group's router gets a second leg in a shared network in the middle: the backbone, 172.16.0.0/24. Each group router has the address 172.16.0.G on ether1; the teacher's router is 172.16.0.254.
flowchart LR
subgraph G3 ["Group 3 island"]
LAN3["<b>10.3.0.0/16</b><br>LAN + VLANs"]
R3["<b>G3 router</b><br>172.16.0.3"]
LAN3 --- R3
end
subgraph BB ["Backbone 172.16.0.0/24"]
SW["<b>Backbone switch</b>"]
T["<b>Teacher router</b><br>172.16.0.254"]
SW --- T
end
subgraph G5 ["Group 5 island"]
R5["<b>G5 router</b><br>172.16.0.5"]
LAN5["<b>10.5.0.0/16</b><br>LAN + VLANs"]
R5 --- LAN5
end
R3 ---|"ether1"| SW
SW ---|"ether1"| R5
Group 3 wants to reach group 5. Group 3's router needs one new sign:
Read it aloud: "for anything in 10.5.0.0/16, hand it to 172.16.0.5". Two details matter:
- The gateway must be directly reachable.
172.16.0.5is on the backbone, a network the G3 router touches. Writinggateway=10.5.0.1would not work: the G3 router cannot reach that address directly, and RouterOS shows the route as inactive. - Why
/16and not/24? Group 5 has three subnets:10.5.0.0/24,10.5.10.0/24(dev) and10.5.20.0/24(design). One/16sign covers all three. That is subnetting, read backwards.
In WinBox the same route is IP → Routes → +: Dst. Address 10.5.0.0/16, Gateway 172.16.0.5. Afterwards /ip route print shows it with the flags AS: active and static.
The idea of the day: a route back is needed
"I added the route, so the ping must work." No. A ping is a question and an answer. Your route takes the question there. The answer is a new packet travelling the other way, from 10.5.0.x to 10.3.0.x, and it needs a sign on their router pointing back to you. If group 5 has no route to 10.3.0.0/16, the answer is dropped at their router and your ping fails.
Routes are needed in both directions. To make your ping work, you have to go and talk to another team.
That last sentence is the Internet in miniature: tens of thousands of networks, each run by different people, that agreed to tell each other which addresses they have.
flowchart LR
A["<b>PC in group 3</b><br>10.3.0.199"] -->|"question: route on G3 router"| B["<b>PC in group 5</b><br>10.5.0.199"]
B -->|"answer: needs a route<br>on G5 router too"| A
Following the packet: traceroute¶
How do you see the junctions a packet crosses? Every IP packet carries a counter called the TTL (Time To Live). Each router subtracts one from it. When it reaches zero, the router throws the packet away and sends a small note back to the sender: "it died here".
traceroutesends packets with TTL 1, then 2, then 3... and collects the notes. The result is one line per router on the way.
Three lines: your own router, the partner's router, and the PC itself. Three hops, two junctions. The -n option shows numbers only, without looking up names.
If a line shows * * * (stars), no note came back from that hop. On Windows the same tool is called tracert.
What traceroute does not show
- Switches and access points are invisible to it: they do not touch the TTL.
tracerouteonly shows routers. - Stars do not always mean "it stopped here". They mean no note came back. The break may be on the way back, as you will see in the lab.
Finding the break: three routers in a line¶
In the virtual lab you build this chain alone, with three blank routers:
pc1 --- ether3 [r1] ether2 ----- ether2 [r2] ether3 ----- ether2 [r3] ether3 --- pc3
10.1.0.0/24 172.16.12.0/30 172.16.23.0/30 10.3.0.0/24
The links between routers are /30 networks: they hold exactly two usable addresses, .1 and .2, one for each end. Each router needs a sign for every network it does not touch:
| Router | Touches | Needs routes to |
|---|---|---|
r1 |
10.1.0.0/24, 172.16.12.0/30 |
10.3.0.0/24 |
r2 |
172.16.12.0/30, 172.16.23.0/30 |
10.1.0.0/24 and 10.3.0.0/24 |
r3 |
172.16.23.0/30, 10.3.0.0/24 |
10.1.0.0/24 |
When it works, traceroute -n 10.3.0.11 from pc1 prints four lines: 10.1.0.1, 172.16.12.2, 172.16.23.2, 10.3.0.11.
Then you break it on purpose: remove the route to 10.1.0.0/24 on r3. The ping fails. But a capture on pc3 shows the requests arriving:
So the way there is fine. The way back is broken: r3 has no route to 10.1.0.0/24 and drops the answers. That is how a technician thinks: find the exact junction where the packet dies, and in which direction.
Edge routers only need one sign
r1 and r3 sit at the edge of the network: everything that is not local goes the same way. Each can replace its specific route by a single default route (/ip route add gateway=172.16.12.2 on r1). r2, in the middle, still needs two specific routes, because traffic can leave it in two different directions. Your home router is an edge router: one default route towards your Internet provider.
Do the whole practice on the Exercise sheet: first read a table on paper, then join your group with a partner group, then the three-router lab.
Careful: the default gateway is not the Internet
The default gateway is simply the nearest router. Today it leads to the other classroom islands and nowhere else. Nobody has Internet yet: that needs one more trick, on the next page.
Key takeaways¶
- A routing table is a signpost: each line says "for this network, go that way". Hosts and routers both have one.
- A host delivers directly inside its own network and sends everything else to its default gateway (
0.0.0.0/0). - When several lines match, the most specific (longest mask) wins; with no matching line, the packet is dropped.
- Connected routes appear by themselves; static routes are typed by you, and their gateway must be directly reachable.
- A ping needs a route there and back: the answer is a new packet.
tracerouteuses the TTL to list one line per router (hop) on the way; switches are invisible to it.
Quick check¶
1. A PC sends a packet to an address outside its own network. Who does it hand the packet to?
- Its default gateway
- Its DNS server
- The destination, directly
- Every PC in the LAN
A host only delivers directly inside its own network. For anything else it uses the default line of its routing table and hands the packet to the default gateway, the nearest router.
2. What does the route dst-address=10.5.0.0/16 gateway=172.16.0.5 mean?
- For any address in 10.5.x.x, hand the packet to 172.16.0.5
- 172.16.0.5 is the address of this router
- Block all traffic coming from 10.5.x.x
- 10.5.0.0 is the DNS server of the network
A static route is one sign on the signpost: destination network 10.5.0.0/16, next junction 172.16.0.5. The gateway must be an address the router can reach directly.
3. A router has the lines 10.5.0.0/16 via A and 0.0.0.0/0 via B. Where does a packet for 10.5.20.9 go?
- Via A, because it is the most specific match
- Via B, because the default route always wins
- To both A and B, to be safe
- Nowhere, because there is no /24 for it
Both lines contain 10.5.20.9, but the router picks the longest mask. /16 is more specific than /0, so A wins. The default route is used only when nothing else matches.
4. Group 3 has a correct route to group 5, but a ping from group 3 to a group 5 PC fails. What is the most likely cause?
- Group 5's router has no route back to group 3
- The network cable is longer than 10 metres
- The DNS server of group 3 is down
- The route uses a /16 mask instead of /24
A ping is a question and an answer. The answer is a new packet going from group 5 to group 3, and it needs a route on their router. Routes are needed in both directions.
5. What does each line of the output of traceroute show?
- One router the packet passed through on the way
- One switch the packet passed through on the way
- One line of the local routing table
- One open port on the destination
traceroute sends packets with TTL 1, 2, 3... and each router that throws one away sends a note back. So each line is a hop, a router. Switches do not touch the TTL and stay invisible.
6. Why does group 3 route to group 5 with a /16 instead of a /24?
- One /16 covers group 5's LAN, dev and design subnets at once
- A /16 route is faster than a /24 route
- RouterOS does not accept /24 static routes
- A /16 also gives Internet access to group 5
Group 5 has 10.5.0.0/24, 10.5.10.0/24 and 10.5.20.0/24. All three are inside 10.5.0.0/16, so one sign is enough for all of them.
7. In a chain pc1 – r1 – r2 – r3 – pc3, the ping from pc1 to pc3 fails, but tcpdump on pc3 shows the requests arriving. Pick the two that are true.
- The way from pc1 to pc3 works
- A router on the way back has no route to pc1's network
- pc3 is switched off
- r1 has no route to pc3's network
If the requests arrive at pc3, every router on the way there has the right sign, and pc3 is alive. The problem must be the answers: some router on the way back, here r3, has no route to 10.1.0.0/24 and drops them.
Next: your islands are joined, but nobody can reach the Internet yet. Find out why the world uses a clever trick instead of routes — NAT and Internet access.