Routers and the gateway
A router joins one network to another. Your laptop sends packets for its own network straight to the device they are for. It sends every other packet to one router, its default gateway. Each router then passes the packet one step closer, until it arrives. No router knows the whole way, only the next step.
Near or far: the first decision
Each time a device sends a packet, it first compares the destination's network part with its own, as in Reading an IP address. There are only two answers:
- The same network: the device sends the packet straight to the receiver. It puts the packet in a frame for the receiver's hardware address, and the switch delivers it, as in Switches.
- A different network: the device sends the packet to its default gateway.
The default gateway
The The router on your own network that a device sends every packet for other networks to. is the router on your own network: the one way out. A device gets the gateway's address together with its own address when it joins the network. At home, the gateway is the home router, often at an address such as 192.168.1.1.
Think of a building with a mail room. You take a note for a colleague on your floor to them yourself. Every letter for anywhere else goes to the mail room. But the mail room does not carry your letter all the way. It passes the letter to the next sorting office, which passes it on again. Routers work the same way.
A router sits on more than one network, so it has an address on each of them. In the office below, the main router is 192.168.1.1 on the office network. It is 10.0.0.1 on the cable to the library, and 198.51.100.2 on the cable to the internet provider. The laptop only needs to know the first one, its gateway.
The laptop: address 192.168.1.20/24, gateway 192.168.1.1
Send a packet to the printer, then to the library desktop, and compare what the laptop does with each.
Main router: routing table
| Network | Send to |
|---|---|
| 192.168.1.0/24 | Directly, office side |
| 10.0.0.0/30 | Directly, library side |
| 198.51.100.0/30 | Directly, provider side |
| 172.16.8.0/24 | 10.0.0.2, the library router |
| Anything else | 198.51.100.1, the provider |
Library router: routing table
| Network | Send to |
|---|---|
| 172.16.8.0/24 | Directly, library side |
| 10.0.0.0/30 | Directly, main side |
| Anything else | 10.0.0.1, the main router |
To reach its gateway, the laptop puts the packet in a frame for the main router's hardware address. Each router then puts the packet in a new frame for the next stop, as in Addresses.
Finding a hardware address with ARP
A frame needs the receiver's hardware address, but a device usually knows only the receiver's IP address. It finds the hardware address with Address Resolution Protocol: how a device finds the hardware address that belongs to an IP address on its own network. It asks every device at once, with a broadcast., the broadcast question from Switches: "who has 192.168.1.30?". Only the device with that address answers. The asker keeps the answer in its The list a device keeps of the hardware address behind each IP address on its own network, so it does not have to ask every time. Old entries are forgotten after a while. for a while, so the next frame goes out at once.
A device asks only on its own network. For a far address, it does not ask for the far device at all. It asks for its gateway's hardware address and sends the frame there.
Send to the printer twice, then to the far server, and watch the laptop's ARP table.
The laptop's ARP table
| IP address | Hardware address | Who that is |
|---|---|---|
| Empty | ||
The routing table
A router's The list a router keeps of the networks it can reach, and where to send a packet for each. is a list of networks. For each network, it says where to send a packet for it. There are two kinds of answer:
| Send to | Means |
|---|---|
| Directly | The network is on one of the router's own sides. The router delivers the packet to the device itself. |
| The address of another router | The network is farther away. The router passes the packet to that router, the next step on the way. |
Most tables end with a row for anything else: where to send a packet whose network is on no other row. For the main router, that is the internet provider. This row is the router's own default gateway, and it works the same way as the laptop's.
When a packet arrives, the router looks for the row whose network holds the destination address. If no row does, it uses the row for anything else. If it has no such row either, it drops the packet.
A packet from your home to a website far away may take ten or twenty hops, and every router on the way does the same.
The TTL: a counter against loops
People write routing tables, and people make mistakes. Say one router sends a packet to a second router, and the second sends it back to the first. The packet goes round and round. Without something to stop it, it would circle forever and keep the cable busy.
So every packet carries a number called the Time to live: a counter in every IP packet that each router lowers by one. At zero the packet is dropped, so it cannot loop forever., short for time to live. Most devices start it at 64 or 128. Every router that passes the packet on lowers it by one. A router that lowers it to 0 drops the packet instead of passing it on.
In the next drawing, the main router still has a row for a reading room in the library that closed last year. The library router no longer knows that network. So it sends anything for it back to the main router, which sends it to the library again.
The laptop: address 192.168.1.20/24, gateway 192.168.1.1
Send a packet to the old reading room and watch the TTL. Then send one to the library desktop.
Main router: routing table
| Network | Send to |
|---|---|
| 192.168.1.0/24 | Directly, office side |
| 10.0.0.0/30 | Directly, library side |
| 198.51.100.0/30 | Directly, provider side |
| 172.16.8.0/24 | 10.0.0.2, the library router |
| 172.16.9.0/24(old reading room) | 10.0.0.2, the library router |
| Anything else | 198.51.100.1, the provider |
Library router: routing table
| Network | Send to |
|---|---|
| 172.16.8.0/24 | Directly, library side |
| 10.0.0.0/30 | Directly, main side |
| Anything else | 10.0.0.1, the main router |
The TTL does not fix the mistake. The packet is still lost, and the old row stays in the table until someone removes it. But the TTL limits the damage: a lost packet disappears after a few dozen hops instead of circling forever.
Notes from the network
A router that drops a packet usually sends a short note back to the sender, saying why. These notes are called Internet Control Message Protocol: short messages about delivery itself, such as a ping and its reply, or a router saying that a packet's TTL ran out.. They carry no data of their own. They say what happened to other packets on the way. Two common tools are built on ICMP: ping and traceroute, which Windows calls tracert.
Start with ping to the gateway, then the far server, then the two that stay silent. Finish with tracert.
ping sends an ICMP echo request, and the device answers with an echo reply. Each reply line says how long the round trip took, in ms (thousandths of a second). It also says the TTL the reply had left when it arrived.
No reply says less than it seems. Request timed out. only means that no answer came back. The device may be off, or nobody may have the address. Or a A filter on a router that checks each packet against its rules, read from the top, and lets the packet pass or drops it. on the device may throw echo requests away.
traceroute finds the routers on the way by letting the TTL run out on purpose:
- It sends packets with a TTL of 1. The first router lowers the TTL to 0 and drops them. It sends back an ICMP "time exceeded" note from its own address. That address, and the time the note took, are hop 1.
- It sends packets with a TTL of 2. The first router lowers the TTL to 1 and passes them on. The second router lowers it to 0 and sends the notes. That is hop 2.
- It goes on, one more each time, until a packet has enough TTL to reach the destination. The destination answers directly, and that is the last row.
A row of * * * means no note came back from that hop. Many routers send no ICMP notes, or only a few a second, to save work. Some networks filter the notes out. So stars in the middle do not mean the way is broken, as long as later hops answer. Stars point at a real problem only when they never stop and the destination never answers. Even then, a firewall at the destination may be the reason.
So a firewall often lets ICMP through on purpose. A network that drops every ICMP note is harder to fix when something breaks.