All lessons are free · No login · No trackingStart learning

Network Stories 9 · Beginner

Out the Front Door: Router and Default Gateway

Octo can't deliver to other networks. So who should the letter be handed to?

Starring: Rue, Octo, PipAbout 10 min read

Recommended first: Lesson 4, Story 3: “ARP”

1. The Story

Press "Next" to go through it step by step. In each step, one character comes on stage and explains what they are doing.

Prologue: a quick recap

Step 1 of 13

How delivery works inside a LAN

Inside a LAN (Local Area Network), I deliver by MAC Address, each device's built-in name tag. If a device doesn't know the other side's MAC Address, it asks with an ARP (Address Resolution Protocol) Broadcast to everyone. That's how Mac sends photos to the TV.

Animation text version (all steps)
  1. Prologue: a quick recap
  2. How delivery works inside a LAN · Octo: Inside a LAN (Local Area Network), I deliver by MAC Address, each device's built-in name tag. If a device doesn't know the other side's MAC Address, it asks with an ARP (Address Resolution Protocol) Broadcast to everyone. That's how Mac sends photos to the TV.
  3. Act 1: The destination isn't at home
  4. Where is example.com? · Pip: Mac wants to open example.com, and Dr. Lookup says its IP Address is 192.0.2.80. But it isn't in Octo's notebook, and even asking with ARP gets no answer, because it isn't in this LAN at all!
  5. Enter Rue · Rue: Leave it to me! I'm a Router, connecting the home LAN to the Internet outside. My inside address is 192.168.1.1, and my outside address is 203.0.113.1. Any Pip heading to another network, just hand him to me!
    • A Router reads IP Addresses and forwards Packets between different networks
    • Each Port belongs to a different network: inside 192.168.1.1, outside 203.0.113.1
  6. Same network? · Pip: Before setting off, Mac compares the network parts. His Subnet Mask is /24, meaning the first three numbers: his own are 192.168.1, the other side's are 192.0.2. They're different! So it has to go to the Default Gateway.
    • Mac's settings: IP 192.168.1.10, Subnet Mask 255.255.255.0 (/24), Default Gateway 192.168.1.1
    • Starting with 192 doesn't make it a Private IP: only addresses starting with 192.168 are
  7. Using ARP to ask for Rue's name tag · Pip: Mac doesn't use ARP to ask about 192.0.2.80. Instead he asks: "Who is 192.168.1.1?" Rue answers: "That's me, MAC Address 00:00:5E:00:53:FE."
  8. Two layers of addresses on the backpack · Pip: I'm off! The recipient MAC on the Frame, my delivery bag, is Rue's …:FE, because he's the next stop. But the IP recipient in my backpack is 192.0.2.80, because that's the final destination.
    • Frame recipient MAC: 00:00:5E:00:53:FE (Rue)
    • IP recipient: 192.0.2.80 (example.com)
    • TTL (Time to Live): 64
  9. Act 2: Rue at work
  10. Remove the delivery bag, read the IP · Rue: When Pip arrives, I first remove the Frame, his "delivery bag", and read the IP recipient inside: 192.0.2.80. It isn't in a network I'm directly connected to, so I check my map and hand him to the next stop: ISP Router 203.0.113.254.
    • The map is called a Routing Table; Story 12, "Rue's Map: Routing Tables and Static Routes", covers it in detail
    • At every Router, the TTL goes down by 1: 64 → 63
  11. A new delivery bag · Rue: I put a new Frame on Pip: the recipient is the ISP Router's MAC, and the sender is the MAC of my outside Port. The IP recipient is still 192.0.2.80, not a single character changed.
    • MAC Addresses: change on every leg
    • IP recipient: stays the same from start to finish
    • (A home Router also uses NAT to change the sender IP to 203.0.113.1; more in Story 14, "The Building Office: NAT and Port Forwarding")
  12. Arriving stop by stop · Pip: The ISP Router is another Rue. It also reads the IP recipient and hands me to the next stop. After passing through several Routers on the Internet, I finally reach the example.com server!
  13. The same on the way back · Rue: The server's reply is passed back along the way to me. I see the IP recipient is Mac at home, so I use ARP to find his MAC Address and hand the reply to Octo, who delivers it to Mac.
  14. Act 3: What Rue stays out of
  15. Home matters are Octo's job · Octo: Mac is sending photos to the TV at 192.168.1.11. The network part is the same, so he uses ARP to find the TV directly, and I deliver them. Rue doesn't need to step in at all.
    • Same network → send directly (via the Switch)
    • Different network → hand it to the Default Gateway (Router)
  16. Broadcasts stop here · Rue: I don't forward Broadcasts. Mac's Broadcast stops when it reaches me and never runs off to the Internet. So behind each of my Ports is a separate Broadcast Domain, the area a Broadcast can reach.
  17. Summary: out the front door · Rue: Remember: same network, send directly; different network, hand it to the Default Gateway. Passing through a Router, the MAC Addresses change on every leg and the TTL goes down by 1, but the IP recipient stays the same. This way, this is the fastest route!

2. Where Is the Problem

Inside the home LAN (Local Area Network), Octo the Switch delivers by MAC Address, the name tag every device is born with. If a device doesn't know the other side's MAC Address, it uses ARP (Address Resolution Protocol) to send out a Broadcast, a message to everyone, asking: "Who is so-and-so?"

But Mac wants to open example.com. Dr. Lookup tells him that the server's IP Address, its network address, is 192.0.2.80.

Note: an address starting with 192 isn't necessarily a Private IP. Only addresses starting with 192.168 are. 192.0.2.80 is an address on the Internet, and it isn't in the home at all.

So:

  • it isn't in Octo's notebook;
  • even if Mac used ARP to ask "Who is 192.0.2.80?", nobody would ever answer (in fact, a computer would never ask this).

Octo only knows how to deliver inside the same LAN. To reach another network, we need a different helper.

3. How the Network Solves It

Imagine you live in a big apartment block. To send a letter to a neighbour on the same floor, you just carry it over yourself. To send one to another city, you hand it to the post office downstairs.

A Router is that post office. It reads IP Addresses and forwards Packets, the small parcels data travels in, between different networks. The Router that home devices hand their "going to another network" data to is called the Default Gateway.

Every time before sending, Mac asks himself one question: "Is the other side in the same network as me?" If yes, he sends it directly. If not, he hands it to the Default Gateway.

4. A Closer Look

Rue has two addresses

Each Port on a Router connects to a different network, so each Port has its own IP Address:

Rue's Port IP Address Which network it connects to
Inside: home LAN 192.168.1.1, MAC Address 00:00:5E:00:53:FE 192.168.1.0/24
Outside: to the ISP (Internet Service Provider) 203.0.113.1 The Internet

The Default Gateway on home devices is set to Rue's inside address, 192.168.1.1.

Mac's settings

Mac's network settings contain three important items (usually handed out automatically by DHCP (Dynamic Host Configuration Protocol)):

IP Address:       192.168.1.10
Subnet Mask:      255.255.255.0 (/24)
Default Gateway:  192.168.1.1

A Subnet Mask of /24 means the first 24 bits, that is, the first three numbers, are the network part.

Deciding before setting off

Recipient Mac's network part Recipient's network part Result
TV 192.168.1.11 192.168.1 192.168.1 Same → use ARP to find the TV directly, and send via Octo
example.com 192.0.2.80 192.168.1 192.0.2 Different → hand it to the Default Gateway

Note: when handing data to the Default Gateway, Mac uses ARP to ask "Who is 192.168.1.1?", not "Who is 192.0.2.80?". He needs Rue's MAC Address, because Rue is the next stop.

Two layers of addresses on the backpack

Pip actually carries two layers of addresses. The outer Frame is a "delivery bag" that only covers the current leg of the trip. Inside is the IP Header, Pip's "backpack", which holds the final destination.

Leg 1: Mac → Rue Leg 2: Rue → ISP Router
Frame sender MAC Mac 00:00:5E:00:53:01 MAC of Rue's outside Port
Frame recipient MAC Rue 00:00:5E:00:53:FE ISP Router's MAC
IP sender 192.168.1.10 203.0.113.1 (rewritten by NAT)
IP recipient 192.0.2.80 192.0.2.80 (unchanged)
TTL (Time to Live) 64 63

At every Router:

  1. The old Frame is removed, and the IP recipient inside is read.
  2. The Routing Table is checked to decide the next stop. Rue's next stop is the ISP Router 203.0.113.254. In the industry, this "next stop" is called the Next Hop.
  3. The TTL goes down by 1. If it reaches 0, the Packet is thrown away.
  4. A new Frame is put on. The sender is the MAC Address of the Router's own outgoing Port, and the recipient is the MAC Address of the next stop.

The MAC Addresses change on every leg, but the IP recipient stays the same from start to finish. As for the sender IP changing from 192.168.1.10 to 203.0.113.1, that is something extra the home Router does, called NAT (Network Address Translation). Story 14, "The Building Office: NAT and Port Forwarding", explains it in detail.

Routers don't forward Broadcasts

A Switch sends a Broadcast out of every other Port, but a Router does not forward Broadcasts. So behind each of Rue's Ports is a separate Broadcast Domain, the area a Broadcast can reach.

If Routers forwarded Broadcasts too, ARP questions from every device in the world would flood the Internet, and the network would collapse straight away.

What if the Default Gateway is set wrong?

If Mac's Default Gateway is entered incorrectly, or Rue is switched off:

  • Mac can still send photos to the TV, because it's in the same network;
  • but no website will open, because nobody is there to take the "outgoing letters".

If "devices at home can share files with each other but can't get online", the Default Gateway is one of the things worth checking.

5. Try It Yourself

Task: Find your Default Gateway and its MAC Address

  1. On a computer, open "Command Prompt" (Windows) or "Terminal" (Mac) and type ipconfig (Windows) or netstat -rn (Mac) to find the Default Gateway (Windows shows it as "Default Gateway"). On a phone, you can check it in the Wi-Fi settings; an iPhone shows it as "Router".
  2. Open a web page first, then type arp -a.
  3. Find the Default Gateway's IP Address in the list and see which MAC Address it matches. That's the name tag of your home's "Rue"!
  4. Think about it: does the list include the IP Address of an outside website such as example.com? Why not? (Hint: Mac only uses ARP to find devices in the same network.)

Mini game

Send directly, or hand it to Rue?

Mac's address is 192.168.1.10/24. For each recipient below, will he send it directly, or hand it to the Default Gateway?

  1. 1192.168.1.11 (TV)

  2. 2192.0.2.80 (example.com)

  3. 3192.168.1.12 (desktop computer)

  4. 4203.0.113.2 (the neighbour's Router)

  5. 5192.168.20.10 (a computer in the guest zone)

  6. 6198.51.100.1 (the coffee shop's Router)

6. Where the Analogy Breaks

  • Rue doesn't really "unpack" Pip. After reading the Frame Header, a Router throws away the old Frame Header and puts on a new one. In the IP Packet inside, it only changes a few fields such as the TTL, and it never looks at the data itself.
  • The return trip actually goes through NAT. In the animation, the server's reply is addressed straight to Mac. In reality, the reply's IP recipient is 203.0.113.1, and Rue then uses NAT to change it back to 192.168.1.10. Story 14, "The Building Office: NAT and Port Forwarding", explains this.
  • The Default Gateway isn't always that "home router" box. A home router is really a Router, a Switch and an Access Point combined into one device. In a company network, the Default Gateway can be a Layer 3 Switch, as Story 10, "A Bridge Between Zones: Inter-VLAN Routing", explains.
  • There are more than "a few" Routers on the Internet. Going from your home to a website usually passes through ten or more Routers, and the route there and the route back aren't always the same.
  • ARP doesn't have to ask every time. Mac remembers Rue's MAC Address in his ARP Cache, so he doesn't need to ask again for a while.

7. Quiz

Question 1 of 3Mac (192.168.1.10/24) wants to send data to 192.0.2.80. Whose MAC Address will he put as the Frame's recipient?
Question 2 of 3After Pip passes through a Router, which of these does NOT change? (Ignoring NAT)
Question 3 of 3Why doesn't Mac's Broadcast reach the example.com server?

8. Key Notes

  • A Router reads IP Addresses and forwards Packets between different networks. Each of its Ports belongs to a different network and has its own IP Address.
  • Before sending, compare the network parts: same network, send directly; different network, hand it to the Default Gateway.
  • When handing data to the Default Gateway, a device uses ARP to find the Default Gateway's MAC Address, not the final destination's.
  • When passing through a Router, the MAC Addresses change on every leg and the TTL goes down by 1, but the IP recipient stays the same from start to finish.
  • Routers don't forward Broadcasts. Behind each Router Port is a separate Broadcast Domain.

Further reading

Rue has led Pip out the front door: same network, send directly; different network, hand it to the Default Gateway. But the home is already split into two VLANs (Virtual LANs), a family zone and a guest zone. How do the two zones talk to each other? In the next story, Rue and Octo team up to build a bridge: "A Bridge Between Zones: Inter-VLAN Routing".