Routing
Routing is the process of selecting the best path for data packets to travel from a source device to a destination device across a network.
Key Components
- Routers - Devices that forward packets between networks
- Routing Tables - Store information about network paths
- Routing Protocols - Rules for determining best paths
Types of Routing
| Type | Description |
|---|---|
| Static Routing | Manually configured paths |
| Dynamic Routing | Automatic path selection |
Routing Protocols Overview
Routing protocols decide HOW routers choose paths.
Two Main Categories
flowchart TD
subgraph AS1["🏢 Autonomous System 1 (AS 100 - e.g., Enterprise LAN)"]
R1["Router A"] <-->|"OSPF (IGP)"| R2["Router B"]
R2 <-->|"OSPF (IGP)"| Border1["🚪 Border Router 1"]
end
subgraph AS2["🌐 Autonomous System 2 (AS 200 - ISP Backbone)"]
Border2["🚪 Border Router 2"] <-->|"OSPF / IS-IS"| Core["Core ISP Routers"]
Core <--> Border3["🚪 Border Router 3"]
end
subgraph AS3["🏢 Autonomous System 3 (AS 32934 - Facebook DC)"]
Border4["🚪 Border Router 4"] <-->|"OSPF"| WebServer["🖥️ Facebook Web Servers"]
end
Border1 <==>|"BGP (EGP - AS-PATH: 100 → 200)"| Border2
Border3 <==>|"BGP (EGP - AS-PATH: 200 → 32934)"| Border4
| Type | Example | Used For |
|---|---|---|
| Interior Gateway Protocol (IGP) | OSPF | Inside one network |
| Exterior Gateway Protocol (EGP) | BGP | Between networks |
OSPF – Open Shortest Path First
- Used INSIDE one organization or ISP
- Calculates shortest path using Dijkstra algorithm
- Based on cost, bandwidth, and speed
- Fast and dynamic
Used In
- Company networks
- University networks
- Internal ISP routing
Goal
Find the best path inside a single network.
BGP – Border Gateway Protocol
- Used BETWEEN different networks and ISPs
- Runs the entire internet
- Policy-based routing
- Does NOT care about speed or distance
What BGP Cares About
- Business agreements
- Policies
- Stability
- AS-PATH
Difference Between OSPF and BGP
| Feature | OSPF | BGP |
|---|---|---|
| Type | Interior (IGP) | Exterior (EGP) |
| Used In | Inside a network | Between networks |
| Goal | Shortest path | Best policy path |
| Algorithm | Dijkstra | Path Vector |
| Internet Usage | No | Yes |
Protocol Comparison
| Protocol | Cares About |
|---|---|
| OSPF | Speed / cost / shortest path |
| RIP | Hop count (distance) |
| BGP | Policies and preferences |
Autonomous System (AS)
Definition
An Autonomous System is a large network under single administrative control.
AS Number (ASN)
- Unique identifier for each network on the internet
- Examples:
- Google: AS15169
- Facebook: AS32934
AS-PATH in BGP
- AS-PATH is a list of AS numbers a packet passes through
- Used for:
- Loop prevention
- Path selection
Example AS-PATH
flowchart LR
AS100["🏢 AS100 (Client ISP)"] --> AS200["🌐 AS200 (Transit Provider)"] --> AS32934["🏢 AS32934 (Facebook)"]
What Happens When You Ping a Website
Example: ping facebook.com
flowchart TD
D1["1. DNS Lookup: facebook.com → 57.144.56.1"] --> D2["2. Build ICMP Echo Request Packet"]
D2 --> D3["3. Check Routing Table (Gateway: 192.168.1.1)"]
D3 --> D4["4. ARP Resolution (Find Gateway MAC)"]
D4 --> D5["5. Forward to Default Router"]
D5 --> D6["6. Internet Routers Forward Across BGP Paths"]
D6 --> D7["7. Facebook Server Receives & Sends ICMP Echo Reply"]
D7 --> D8["8. Reply Delivered to Local Device (Calculates RTT ms)"]
Traceroute
Traceroute shows the path packets take across the internet.
Command
traceroute facebook.comWhat Traceroute Shows
- Each router hop
- Latency between hops
- Network path structure
Important Notes
- Some hops show
* * *due to ICMP blocking - Final hops may be hidden for security
Packets
Data in network travels in small chunks called packets.
A packet contains:
- Source IP
- Destination IP
- Data payload
Important Commands
View Routing Table
ip routeTrace Route
traceroute facebook.comView ARP Table
ip neighQuick Reference
| Concept | Description |
|---|---|
| Routing | Selecting best path for packets |
| Router | Device that forwards packets |
| OSPF | Interior routing protocol (shortest path) |
| BGP | Exterior routing protocol (policy-based) |
| AS | Network under single admin control |
| Traceroute | Shows path packets take |
| Static Routing | Manually configured |
| Dynamic Routing | Automatically determined |
Summary
- OSPF is used inside networks
- BGP is used between networks
- Traceroute shows path, not protocol
- Internet routing is mostly BGP
- Your PC only knows next hop, not full path