The Kadé office
Staff computers and warehouse devices are kept on separate networks, so a problem on a warehouse device stays in the warehouse. Both networks use the mask 255.255.255.0. One router sits between them, with an address in each.
- devices
- router and switches: they pass traffic on
- the internet side, where kade-api is
Three networks meet at the router: staff on eth1, warehouse on eth2, the ISP on eth0.
| Staff network · 172.16.1.0/24 | Warehouse network · 172.16.2.0/24 |
|---|---|
| Front desk PC · 172.16.1.10 | Stock scanner · 172.16.2.10 |
| Manager laptop · 172.16.1.11 | Packing PC · 172.16.2.11 |
| Office printer · 172.16.1.20 | Label printer · 172.16.2.20 |
| gateway 172.16.1.1 (router eth1) | gateway 172.16.2.1 (router eth2) |
A router has several interfaces
This is the key idea of the chapter. A router has more than one network interface (chapter 2), and each has its own IP on a different network. That is what lets one box join separate networks.
| Interface | IP | Network | Faces |
|---|---|---|---|
| eth0 | 198.51.100.20 | 198.51.100.0/24 | The ISP (WAN)ISP router at 198.51.100.1 |
| eth1 | 172.16.1.1 | 172.16.1.0/24 | Staff networkstaff devices' default gateway |
| eth2 | 172.16.2.1 | 172.16.2.0/24 | Warehouse networkwarehouse devices' default gateway |
Switch and router
Inside each network, devices are joined by a switch. The switch and the router do different jobs:
| Switch | Router | |
|---|---|---|
| Joins | Devices inside one network | Separate networks |
| Reads | MAC addresses (the frame) | IP addresses (the packet) |
| Used when | Target is on the same network | Target is on a different network |
| Speed cost | Tiny, microseconds | Small, but it does more work |
Case 1: same network
The front desk PC prints an order on the office printer.
- sender
- target and path
- router used
- Front desk PC first checks: is the office printer on my own network? Its mask, 255.255.255.0, says only the first three numbers name the network. Its own address gives
172.16.1.0; the office printer’s gives172.16.1.0. They match: same network. - It sends straight to the office printer (172.16.1.20). The staff switch passes the frame across.
- The router is not used.
Case 2: the other office network
The front desk PC sends a shipping label to the label printer in the warehouse.
- sender
- target and path
- router used
- Front desk PC first checks: is the label printer on my own network? Its mask, 255.255.255.0, says only the first three numbers name the network. Its own address gives
172.16.1.0; the label printer’s gives172.16.2.0. They differ: different networks. - It hands the packet to its default gateway, 172.16.1.1 (router eth1).
- The router looks up 172.16.2.20:
172.16.2.0/24is directly connected on eth2. - The router sends it out eth2, and the warehouse switch delivers it to the label printer.
Step 3 is where the router uses its own routing table (chapter 5). It knows both office networks because it is directly connected to them:
| Destination | Send to | Why |
|---|---|---|
| 172.16.1.0/24 | directly, out eth1 | Connected: eth1 is on this network |
| 172.16.2.0/24 | directly, out eth2 | Connected: eth2 is on this network |
| 198.51.100.0/24 | directly, out eth0 | Connected: the link to the ISP |
| 0.0.0.0/0 | 198.51.100.1, out eth0 | Everything else: the router's own default gateway |
Case 3: out to the internet
The front desk PC loads an order from Kadé's API.
- sender
- target and path
- router used
- Front desk PC first checks: is kade-api on my own network? Its mask, 255.255.255.0, says only the first three numbers name the network. Its own address gives
172.16.1.0; kade-api’s gives34.87.120.0. They differ: different networks. - It hands the packet to its default gateway, 172.16.1.1 (router eth1).
- The router looks up 34.87.120.15. None of its connected networks match, so it uses its default route
0.0.0.0/0→ the ISP (198.51.100.1), out eth0. - The ISP’s routers pass it on, hop by hop, to kade-api in GCP. On the way out, NAT swaps the private source 172.16.1.10 for 198.51.100.20.
Try any pair
Pick a sender and a target. The map shows the path and the steps below it explain each decision.
- sender
- target and path
- router used
- Packing PC first checks: is the office printer on my own network? Its mask, 255.255.255.0, says only the first three numbers name the network. Its own address gives
172.16.2.0; the office printer’s gives172.16.1.0. They differ: different networks. - It hands the packet to its default gateway, 172.16.2.1 (router eth2).
- The router looks up 172.16.1.20:
172.16.1.0/24is directly connected on eth1. - The router sends it out eth1, and the staff switch delivers it to the office printer.
The three cases side by side
| # | From front desk PC to | Target AND mask | Same network? | First step | Router's job |
|---|---|---|---|---|---|
| 1 | Office printer 172.16.1.20 | 172.16.1.0 | yes | Straight to the printer, via the switch | none |
| 2 | Label printer 172.16.2.20 | 172.16.2.0 | no | Gateway 172.16.1.1 | Connected route → out eth2 |
| 3 | kade-api 34.87.120.15 | 34.87.120.0 | no | Gateway 172.16.1.1 | Default route → ISP, out eth0 |
What we skipped
A few things were quietly assumed in this chapter. Each gets its own chapter next:
| MAC address | To put a frame on the wire toward the next device, we need that device's physical address. In case 2 the PC's frame goes to eth1's MAC, and the router builds a new frame for the label printer's MAC. |
| ARP | How the PC finds a MAC from an IP: the printer's in case 1, the router's (172.16.1.1) in cases 2 and 3. |
| NAT | 172.16.1.10 is private. In case 3 the router swaps it for 198.51.100.20 before the packet leaves eth0, and swaps it back on the reply. |
| Hop-by-hop routing | How the ISP and the routers after it find their way to 34.87.120.15, and what changes in the packet at each hop. |
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | The setup | Two /24 networks joined by one router | |
| 2 | Interfaces | A router has one interface per network, each with its own IP | router interface |
| 3 | Switch vs router | Switch joins devices in a network (MAC); router joins networks (IP) | switch |
| 4 | Same network | AND results match → direct, through the switch | |
| 5 | Other network | No match → gateway → router's connected route | connected route |
| 6 | Internet | No match → gateway → router's default route → ISP | |
| 7 | Next | MAC, ARP, NAT and hop-by-hop routing fill the gaps |
Try it yourself
Path to a same-network device
- What to look for: One hop: the device itself. No router in between.
- Runs on: Windows: tracert · any device on your own network
- From section: 4. Case 1: same network
traceroute 192.168.1.60Path out to the internet
- What to look for: Hop 1 is your gateway, then the ISP.
- From section: 6. Case 3: out to the internet
traceroute 1.1.1.1Which way a packet would go
- What to look for:
via 172.16.1.1for another network; noviafor your own. - Runs on: Linux, on a machine with these networks
- From section: 5. Case 2: the other office network
ip route get 172.16.2.20 from 172.16.1.10One line per interface
- What to look for: Several interfaces, each with an address on a different network.
- Runs on: Linux, run on a router or a VM with several NICs
- From section: 2. A router has several interfaces
ip -brief addr