linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
Intro
Lessons
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
home/linux/how/routing

how/network

Routing and TTL

How does a packet reach Google from your laptop in 10-15 hops? Each router knows only "where to pass it next", and that is enough.

When you ping 8.8.8.8, the packet passes through 5-15 routers before it reaches Google. Odd: the internet is huge, so how do routers manage to "know the way"?

The simple answer: nobody knows "the whole map of the internet". Each router knows only its own little piece: "network X is on my interface Y, and everything else, hand it to that neighbor over there". This hop-by-hop logic is what makes the internet scale.

Press ▶ to watch one packet pass through 3 routers, how each of them makes a decision, and why TTL must be decremented.

step 1/5·00 · client prepares a packet for a foreign network
client10.0.0.5ROUTERR110.0.0.1 / 172.16.0.1ROUTERR2172.16.0.2 / 192.0.2.1server203.0.113.4510.0.0.0/24172.16.0.0/16192.0.2.0/24клиент в 10.0.0.0/24 хочет отправить пакет на 203.0.113.45 - это «не моя сеть», идём в default gateway

§ steps

  1. A client with IP 10.0.0.5 wants to send a packet to 203.0.113.45. The stack looks in the routing-table:

    • 10.0.0.0/24 dev eth0, our network
    • default via 10.0.0.1, everything else goes through gateway R1

    The address 203.0.113.45 does not fall under our /24, so we use the default-gateway. The packet leaves for R1 with a starting TTL=64 (the Linux default).

recap

What to remember:

  • Routing works hop-by-hop: no router knows "the whole way to the end", only the next step. Each one makes its own choice independently
  • TTL (Time To Live) protects against loops: each router decrements it by 1, and at TTL=0 the packet is dropped and an ICMP time-exceeded flies back to the sender. traceroute is built on this
  • Longest prefix match: if several routes in the table match the destination, the "longest" (most specific) one wins. /24 beats /16, /16 beats /0
  • Connected routes, networks physically attached to our interfaces, land in the routing-table automatically. You do not need to add them by hand
  • In Linux the table is ip route. You can play with routes without a reboot: add one with ip route add, remove one with ip route del

If you want to get your hands on it, there is a lab where a topology of 3 nodes is built and the packet travels through them with tcpdump observation.

§ dig into the knowledge base

  • routing-tablerouting table, structure and commands
  • default-gatewaydefault gateway, where we go by default
  • traceroutetraceroute, see the packet's path with your own eyes
  • ip-forwardingip_forward, how Linux becomes a router

§ try it hands-on

  • ›intermediate-03-three-node-routing- Three-node routing, build the topology by hand
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies