AiTechWorlds
AiTechWorlds
A GPS app does not just find a route from A to B — it finds the best route based on distance, traffic, and road conditions. It recalculates when a road is closed. When you take a wrong turn, it adapts instantly.
Routers do exactly the same thing for network packets. Every packet arriving at a router carries a destination IP address, and the router must decide: Which interface do I forward this out of? The answer comes from a routing table, built and maintained by routing algorithms.
Every router holds a routing table — a structured list of destinations and instructions for reaching them.
| Field | Description |
|---|---|
| Destination | Network address (e.g., 192.168.10.0/24) |
| Next Hop | IP of the next router toward the destination |
| Interface | Local port to send the packet out |
| Metric | Cost of this route (lower = better) |
| Source | How this route was learned (static, RIP, OSPF, BGP) |
On Windows, run route print to see your machine's routing table. On Linux, use ip route show.
Static routing means an administrator manually enters routes. The router does not adapt — if a link fails, packets are dropped until a human updates the table.
Dynamic routing means routers exchange information with neighbors and automatically build their tables. When topology changes, they converge on new paths.
Distance Vector protocols work on a simple principle: each router tells its neighbors "I can reach destination X at cost Y." Routers collect these advertisements and pick the lowest-cost path.
The underlying algorithm is Bellman-Ford:
For each destination D:
best_cost[D] = min over all neighbors N of (cost_to_N + neighbor_cost_to_D)
RIP (Routing Information Protocol) is the classic distance vector protocol:
When a link fails, routers can enter a loop where they keep incrementing the hop count believing a route exists through each other.
Router A thinks: "I can reach X through B (cost 2)"
Router B thinks: "I can reach X through A (cost 3)"
→ Both increment indefinitely until 16
Fix — Split Horizon: Never advertise a route back to the router you learned it from. This eliminates most routing loops in simple topologies.
Link State protocols take a fundamentally different approach: every router floods the network with information about its own directly connected links. Each router collects this information into a Link State Database (LSDB) — a complete map of the entire network.
With the full map, each router independently runs Dijkstra's Shortest Path First (SPF) algorithm to compute the optimal path to every destination.
OSPF (Open Shortest Path First):
Distance vector routers only know their neighbors' claims about the world. Link state routers have the actual map. When a link fails:
All the protocols above work within a single organization's network (an Autonomous System, or AS). But the internet connects thousands of autonomous systems — ISPs, universities, companies — each with their own routing policies.
BGP (Border Gateway Protocol) is the protocol that routes between autonomous systems.
BGP is what makes the internet's routing resilient and policy-aware. When a major ISP announces or withdraws routes, BGP propagates those changes globally — sometimes causing brief outages visible worldwide.
| Protocol | Type | Algorithm | Convergence Speed | Scale | Standard |
|---|---|---|---|---|---|
| RIP v2 | Distance Vector | Bellman-Ford | Slow (minutes) | Small (<15 hops) | RFC 2453 |
| OSPF | Link State | Dijkstra (SPF) | Fast (seconds) | Large (use areas) | RFC 2328 |
| EIGRP | Hybrid (Cisco) | DUAL | Very fast | Large | RFC 7868 |
| BGP | Path Vector | Policy-based | Slow (minutes) | Internet-scale | RFC 4271 |
| IS-IS | Link State | Dijkstra | Fast | ISP core networks | ISO 10589 |
Windows:
route print
Look for the IPv4 Route Table section. The default route is 0.0.0.0 with mask 0.0.0.0 — this is where packets go when no more specific route matches.
Linux:
ip route show
or the older:
netstat -rn
Key entry to understand:
0.0.0.0/0 via 192.168.1.1 dev eth0
Translation: For any destination not matched by a more specific route, forward to 192.168.1.1 on interface eth0 (your gateway/router).
When multiple routing protocols provide routes to the same destination, routers use Administrative Distance (AD) to break the tie:
| Source | Administrative Distance |
|---|---|
| Directly connected | 0 |
| Static route | 1 |
| OSPF | 110 |
| RIP | 120 |
| BGP (eBGP) | 20 |
Lower AD wins. A static route always beats OSPF. A directly connected network always wins.
route print (Windows) or ip route show (Linux) to inspect routing decisions on any machineGet this course's notes on Telegram!
Free cheat sheets, summaries & practice exercises