Where we are
Each chapter so far uses the one before it, so the order matters:
- IP structurech 2
- Network vs hostch 3
- Subnet maskch 4
- Default gatewaych 5 · here
- MAC and ARPcoming
The two outcomes of the mask check
Same network
Send straight to the target, using its MAC address (found with ARP, coming soon).
Laptop → printer 192.168.1.60. Easy.
Different network
We have an address, but no direct path to it.
Laptop → kade-api. DNS gave us 34.87.120.15, but that machine is not on our network, so we cannot reach it ourselves.
The first case is solved. The second is the interesting one: how do you send something to an address you cannot reach?
The default gateway
The answer is the default gateway. On a home network, that is your router. When a device does not know how to reach an IP directly, it hands the packet to its default gateway and in effect says: "I don't know where this is, but I assume you do. Please pass it on."
Amber: anything for outside 192.168.1.0/24 goes through one door. Green: local traffic never touches it.
Wide by design - scroll it sideways.
Where the gateway lives: the routing table
Your laptop keeps a small routing table: a list of "for these addresses, send this way". For the home WiFi it has just two lines that matter:
| Destination | Send to | Meaning |
|---|---|---|
| 192.168.1.0/24 | directly, on en0 | My own networkthe "same network" case from chapter 4 |
| 0.0.0.0/0 shown as "default" | 192.168.1.1 | Everything elsethe default gateway |
So the mask check from chapter 4 and this table are two views of the same thing. The table is what the OS actually looks at.
What the gateway does next
The router has a routing table too, and it also has a default gateway: the ISP's router. That router has its own, and so on. Each device only needs to know its next step. Nobody holds the full path.
Wide by design - scroll it sideways.
The home router's own table looks like this:
| Destination | Send to | Meaning |
|---|---|---|
| 192.168.1.0/24 | directly, LAN side | The home network |
| 203.0.113.0/24 | directly, WAN side | The small network shared with the ISP router |
| 0.0.0.0/0 | 203.0.113.1 | Everything else: the ISP |
The destination IP does not change
A common mistake is to think the laptop sends the packet "to 192.168.1.1". It does not. The packet still says kade-api. Only the frame, the outer wrap from chapter 1, is addressed to the router:
| Field | Value | Points to |
|---|---|---|
| Destination IP | 34.87.120.15 | kade-api, the real targetstays the same the whole way |
| Destination MAC | 3c:84:6a:10:ee:01 | The home router, the next stepchanges at every hop |
Where the gateway setting comes from
You do not set it yourself. The laptop got it from DHCP when it joined the WiFi (chapter 3), in the same offer as its IP and mask. It is usually the router's own address, very often the first usable one (.1), though some routers use .254.
One rule is fixed: the gateway must be on your own network. The laptop has to reach the gateway directly, because it is the one step it cannot hand to anyone else. A laptop on 192.168.1.0/24 with its gateway set to 192.168.2.1 cannot send anything outside its network.
When the gateway is the problem
"The printer works but websites don't" is a classic gateway-shaped problem. Check one step at a time, closest first:
| # | Command | If it works | If it fails |
|---|---|---|---|
| 1 | ip routemacOS: netstat -rn · Windows: route print | A default via 192.168.1.1 line exists. Go to 2. | No default line: the laptop has no gateway. Reconnect so DHCP runs again. |
| 2 | ping 192.168.1.1 | The laptop can reach its gateway. Go to 3. | Wrong gateway, or the router itself is down. |
| 3 | ping 1.1.1.1 | The router can reach the internet. Go to 4. | The router's WAN side or the ISP is down. Not your laptop. |
| 4 | ping api.kade.lk | Everything works, including DNS. | Only names fail: a DNS problem, not a gateway one. |
In the cloud
kade-api's default gateway is 10.10.1.1, one of the 4 addresses GCP keeps in each subnet (chapter 3). GCP hands it out with DHCP, just like the home router. But it is not a box. In GCP there is no physical router and no shared cable: the network is software running on every machine that hosts VMs, and 10.10.1.1 is an address that software answers for. You cannot log in to it or see it. GCP even sets things up so that the VM sends almost everything to the gateway, including traffic to its own subnet (GCP chapter 1.2 shows how).
kade-api hands every packet to 10.10.1.1. The VPC's route table then decides where it really goes: a packet for kade-db stays inside the VPC; a packet for the internet goes to the default internet gateway, and needs a public address to get any further.
Wide by design - scroll it sideways.
The VPC's route table is created for you:
| Destination | Next hop | Meaning |
|---|---|---|
| 10.10.1.0/24 | the VPC network | Subnet route for sn-appadded automatically for each subnet |
| 10.10.2.0/24 | the VPC network | Subnet route for sn-data |
| 0.0.0.0/0 | default-internet-gateway | Everything else: the internetthe VPC's "default gateway" |
It works like the laptop's table: the most specific match wins. A packet from kade-api to kade-db (10.10.2.5) matches two routes:
| # | Route | Does 10.10.2.5 fall in it? | Prefix |
|---|---|---|---|
| 1 | 10.10.1.0/24 | No | |
| 2 | 10.10.2.0/24 | Yes | /24 |
| 3 | 0.0.0.0/0 | Yes, it matches every address | /0 |
/24 is more specific than /0, so it wins and the packet stays inside the VPC. 0.0.0.0/0 has zero network bits, so it matches every address. That is why it is the default route: it is used only when nothing more specific matches (chapter 12 goes deeper).
On GCP1.2. The VM sends everything to the gateway4. The VPC route table5.1. Firewalls inside a subnet3. How an external IP works7. The full picture
Summary
| # | Idea | In one line | New terms |
|---|---|---|---|
| 1 | The problem | We know the target's IP but it is not on our network | |
| 2 | The answer | Hand it to the default gateway: "you know the way" | default gateway |
| 3 | Routing table | Own network → direct; 0.0.0.0/0 → gateway; most specific match wins | routing table, default route, longest prefix match |
| 4 | A chain | Every router has its own next step; nobody knows the full path | next hop |
| 5 | Addresses | Destination IP stays kade-api; only the MAC points to the gateway | |
| 6 | Setup | Comes from DHCP; must be inside your own network | |
| 7 | Debugging | Check route → gateway → internet → DNS, closest first | |
| 8 | Cloud | Gateway .1 is software; the VPC route table decides; a route, a firewall rule and a public address must all line up | subnet route |
Try it yourself
Your gateway from DHCP
- What to look for:
192.168.1.1 - Runs on: macOS · Windows: ipconfig (Default Gateway line)
- From section: 7. Where the gateway setting comes from
ipconfig getoption en0 routerYour routing table
- What to look for: A
default(or 0.0.0.0) line and a line for your own network. - Runs on: Linux · macOS: netstat -rn -f inet · Windows: route print -4
- From section: 4. Where the gateway lives: the routing table
ip routeEvery router on the way
- What to look for: Hop 1 is your gateway (192.168.1.1). Hop 2 is usually the ISP.
- Runs on: Windows: tracert 1.1.1.1
- From section: 5. What the gateway does next
traceroute 1.1.1.1A VPC's route table
- What to look for: Subnet routes plus the default route with next hop
default-internet-gateway. - From section: 9. In the cloud
gcloud compute routes list --filter="network:kade-vpc"