IP Routing: How Data Finds Its Way Across Networks
IP routing is the process of forwarding packets from a source to a destination across one or more networks. Understanding routing is fundamental to comprehending how the internet works and troubleshooting network connectivity issues. This comprehensive guide explains IP routing, routing protocols, and how routers make forwarding decisions.
What is IP Routing?
IP routing is the mechanism by which data packets are forwarded from their source to their destination through intermediate networks. Routers examine packet headers and use routing tables to determine the best path for each packet.
Basic Concept
Routing vs Switching: ``` Switching (Layer 2): - Forwards frames based on MAC addresses - Within same network/VLAN - Fast, hardware-based - No routing decisions
Routing (Layer 3): - Forwards packets based on IP addresses - Between different networks - Routing table lookups - Path selection ```
Learn more about MAC addresses and subnets.
How routing works:
1. Packet arrives at router
2. Router examines destination IP
3. Consults routing table
4. Determines next hop
5. Forwards packet to next router
6. Process repeats until destination reached
Routing Tables
Routing Table Structure
Components:
Destination Network: Where packet is going
Subnet Mask/Prefix: Network size
Next Hop/Gateway: Where to send packet
Interface: Which router interface to use
Metric: Cost/preference of route
Learn more about subnet masks, default gateways, and BGP routing.
Example routing table:
Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.1.1 eth0 1
192.168.1.0 255.255.255.0 0.0.0.0 eth0 0
10.0.0.0 255.0.0.0 192.168.1.254 eth0 10
172.16.0.0 255.240.0.0 192.168.1.253 eth0 20
CIDR notation:
Destination Gateway Interface Metric
0.0.0.0/0 192.168.1.1 eth0 1 (default route)
192.168.1.0/24 0.0.0.0 eth0 0 (directly connected)
10.0.0.0/8 192.168.1.254 eth0 10
172.16.0.0/12 192.168.1.253 eth0 20
Viewing Routing Tables
Linux: ```bash
Traditional
route -n
Modern
ip route show
IPv6
ip -6 route show ```
Windows: ```cmd route print
Or
netstat -r ```
macOS: ```bash netstat -nr
Or
route -n get default ```
Cisco IOS:
show ip route
show ipv6 route
Routing Decision Process
Longest Prefix Match
Principle: Most specific route wins
Example: ``` Routing table: 10.0.0.0/8 → Gateway A 10.1.0.0/16 → Gateway B 10.1.2.0/24 → Gateway C
Destination: 10.1.2.50 Match 1: 10.0.0.0/8 (8 bits match) Match 2: 10.1.0.0/16 (16 bits match) Match 3: 10.1.2.0/24 (24 bits match) ← Winner (longest prefix)
Packet sent to Gateway C ```
Why it matters:
Allows specific routes to override general routes
Enables efficient route aggregation
Supports hierarchical addressing
Default Route
Purpose: Catch-all for unknown destinations
Notation:
0.0.0.0/0 (IPv4)
::/0 (IPv6)
Example: ``` Routing table: 192.168.1.0/24 → Local (directly connected) 10.0.0.0/8 → Gateway A 0.0.0.0/0 → Gateway B (default)
Destination: 8.8.8.8 No specific match found Uses default route → Gateway B ```
Typical use:
Home router: Points to ISP
Corporate router: Points to internet gateway
Server: Points to local gateway
Types of Routing
Static Routing
Definition: Manually configured routes
Configuration:
Linux: ```bash
Add static route
sudo ip route add 10.0.0.0/8 via 192.168.1.254
Add default route
sudo ip route add default via 192.168.1.1
Delete route
sudo ip route del 10.0.0.0/8
Make permanent (Debian/Ubuntu)
Edit /etc/network/interfaces
```
Windows: ```cmd
Add static route
route add 10.0.0.0 mask 255.0.0.0 192.168.1.254
Add default route
route add 0.0.0.0 mask 0.0.0.0 192.168.1.1
Make permanent
route -p add 10.0.0.0 mask 255.0.0.0 192.168.1.254 ```
Cisco IOS:
ip route 10.0.0.0 255.0.0.0 192.168.1.254
ip route 0.0.0.0 0.0.0.0 192.168.1.1
Advantages:
Simple configuration
Predictable behavior
No protocol overhead
Full control
Secure (no routing updates)
Disadvantages:
Manual configuration required
No automatic failover
Doesn't scale well
No adaptation to changes
Administrative overhead
Use cases:
Small networks
Stub networks
Default routes
Backup routes
Security-sensitive environments
Dynamic Routing
Definition: Routes learned automatically via routing protocols
How it works:
1. Routers exchange routing information
2. Build routing tables automatically
3. Adapt to topology changes
4. Select best paths
5. Provide redundancy
Advantages:
Automatic adaptation
Scalability
Fault tolerance
Load balancing
Reduced administration
Disadvantages:
Protocol overhead
Complexity
Convergence time
Bandwidth usage
CPU/memory requirements
Routing Protocols
Interior Gateway Protocols (IGP)
Used within autonomous systems
RIP (Routing Information Protocol)
Characteristics:
Type: Distance vector
Metric: Hop count
Maximum hops: 15
Update interval: 30 seconds
Convergence: Slow
Versions:
RIPv1: Classful, broadcast
RIPv2: Classless, multicast (224.0.0.9)
RIPng: IPv6 support
Configuration (Cisco):
router rip
version 2
network 192.168.1.0
network 10.0.0.0
Pros:
Simple configuration
Low resource usage
Widely supported
Cons:
Slow convergence
Limited scalability (15 hop max)
Inefficient (periodic updates)
Count-to-infinity problem
Use cases:
Small networks
Simple topologies
Legacy environments
OSPF (Open Shortest Path First)
Characteristics:
Type: Link-state
Metric: Cost (based on bandwidth)
Algorithm: Dijkstra's SPF
Updates: Event-driven
Convergence: Fast
Features:
Hierarchical design (areas)
VLSM support
Authentication
Load balancing
Multicast updates (224.0.0.5, 224.0.0.6)
Configuration (Cisco):
router ospf 1
network 192.168.1.0 0.0.0.255 area 0
network 10.0.0.0 0.255.255.255 area 1
Areas:
Area 0: Backbone area (required)
Other areas: Connect to backbone
ABR: Area Border Router
ASBR: Autonomous System Boundary Router
Pros:
Fast convergence
Scalable
Efficient updates
No hop count limit
Hierarchical design
Cons:
Complex configuration
Higher resource usage
Requires planning
Use cases:
Enterprise networks
Large networks
Hierarchical topologies
EIGRP (Enhanced Interior Gateway Routing Protocol)
Characteristics:
Type: Advanced distance vector (hybrid)
Metric: Composite (bandwidth, delay, load, reliability)
Algorithm: DUAL (Diffusing Update Algorithm)
Updates: Partial, triggered
Convergence: Very fast
Vendor: Cisco proprietary
Features:
Fast convergence
Efficient updates
Load balancing (unequal cost)
VLSM support
Authentication
Configuration (Cisco):
router eigrp 100
network 192.168.1.0 0.0.0.255
network 10.0.0.0 0.255.255.255
Pros:
Very fast convergence
Efficient bandwidth usage
Flexible metrics
Easy configuration
Cons:
Cisco proprietary (mostly)
Complex metric calculation
Use cases:
Cisco-only networks
Enterprise environments
Fast convergence required
Exterior Gateway Protocols (EGP)
Used between autonomous systems
BGP (Border Gateway Protocol)
Characteristics:
Type: Path vector
Metric: AS path, policies
Scale: Internet-scale
Updates: Incremental
Convergence: Slow but stable
Features:
Policy-based routing
Scalability (millions of routes)
Loop prevention (AS path)
Route aggregation
Multi-homing support
Configuration (Cisco):
router bgp 65001
neighbor 203.0.113.1 remote-as 65002
network 192.0.2.0 mask 255.255.255.0
BGP types:
eBGP: Between different AS
iBGP: Within same AS
Attributes:
AS_PATH: Path through AS numbers
NEXT_HOP: Next hop IP
LOCAL_PREF: Preference within AS
MED: Multi-Exit Discriminator
COMMUNITY: Route tagging
Pros:
Internet-scale
Policy control
Stability
Redundancy
Cons:
Complex configuration
Slow convergence
Resource intensive
Requires expertise
Use cases:
Internet backbone
ISP networks
Multi-homed networks
Large enterprises
Routing Metrics
Common Metrics
Hop count (RIP):
Number of routers to destination
Simple but crude
Ignores bandwidth, latency
Maximum: 15 hops
Cost (OSPF): ``` Based on bandwidth Cost = Reference bandwidth / Interface bandwidth Default reference: 100 Mbps
Examples: 10 Mbps: Cost 10 100 Mbps: Cost 1 1 Gbps: Cost 1 (need to adjust reference) ```
Composite (EIGRP): ``` Bandwidth: Primary factor Delay: Secondary factor Load: Optional Reliability: Optional MTU: Informational
Formula: Complex weighted calculation ```
AS Path (BGP):
Number of AS traversed
Shorter path preferred
Policy can override
Administrative Distance
Trustworthiness of routing source
Common values:
Directly connected: 0
Static route: 1
EIGRP: 90
OSPF: 110
RIP: 120
External EIGRP: 170
iBGP: 200
Unknown: 255 (not used)
Usage:
Lower AD = More trusted
Used when multiple protocols provide same route
Can be manually adjusted
Example: ``` Route to 10.0.0.0/8 learned from: - OSPF (AD 110) - RIP (AD 120)
Router uses OSPF route (lower AD) ```
Advanced Routing Concepts
Route Aggregation (Summarization)
Purpose: Reduce routing table size
Example: ``` Individual routes: 192.168.0.0/24 192.168.1.0/24 192.168.2.0/24 192.168.3.0/24
Aggregated: 192.168.0.0/22 (covers all four) ```
Benefits:
Smaller routing tables
Faster lookups
Reduced update traffic
Better scalability
Load Balancing
Equal-cost load balancing:
Multiple paths with same metric
Traffic distributed across paths
Per-packet or per-flow
Increases bandwidth
Example: ``` Two paths to 10.0.0.0/8: Path A: Cost 10 Path B: Cost 10
Traffic split between both paths ```
Unequal-cost load balancing (EIGRP):
Distribute traffic proportionally
Based on metric ratios
Variance command
More complex
Policy-Based Routing (PBR)
Route based on criteria other than destination:
Source address
Application/port
Packet size
Time of day
Use cases:
Traffic engineering
QoS implementation
Multi-homing
Security policies
Example:
Web traffic (port 80) → ISP A
VoIP traffic → ISP B (lower latency)
Backup traffic → ISP C (cheaper)
Redistribution
Share routes between routing protocols
Example:
OSPF domain ←→ Redistribution ←→ EIGRP domain
Challenges:
Metric conversion
Loop prevention
Administrative distance
Filtering required
Routing in Practice
Home Network
Typical setup: ``` Router: 192.168.1.1 Routing table: - 192.168.1.0/24 → Local (directly connected) - 0.0.0.0/0 → ISP gateway (default route)
All internet traffic → ISP Local traffic → Local network ```
Enterprise Network
Multi-site with OSPF: ``` Headquarters: Area 0 (backbone) Branch offices: Area 1, 2, 3 Data center: Area 0 Internet: Default route via firewall
Internal routing: OSPF External routing: BGP (if multi-homed) ```
ISP Network
BGP for internet routing:
eBGP: Peering with other ISPs
iBGP: Internal route distribution
IGP: OSPF or IS-IS for internal
Default-free zone: Full internet routing table
Troubleshooting Routing
Common Issues
No route to destination:
Check: Routing table
Command: ip route show | grep destination
Solution: Add static route or enable routing protocol
Routing loop:
Symptom: Packets circulate endlessly
Check: TTL expiring, traceroute shows loop
Solution: Fix routing configuration, check metrics
Asymmetric routing:
Issue: Forward and return paths different
Check: Traceroute both directions
Impact: Firewall issues, performance
Suboptimal routing:
Issue: Not using best path
Check: Routing table metrics
Solution: Adjust metrics, check policies
Diagnostic Tools
traceroute/tracert: ```bash traceroute google.com
Shows path to destination
Identifies routing issues
```
ping: ```bash ping -c 4 8.8.8.8
Tests connectivity
Verifies routing works
```
mtr (My Traceroute): ```bash mtr google.com
Combines ping and traceroute
Real-time statistics
```
Looking glass:
Web-based route viewing
ISP/backbone routers
Public BGP information
IPv6 Routing
Differences from IPv4
Address size:
IPv6: 128 bits
Longer prefixes
More specific routes
Protocols:
RIPng: RIP for IPv6
OSPFv3: OSPF for IPv6
EIGRP for IPv6
MP-BGP: Multiprotocol BGP
Link-local addresses:
Required on all interfaces
Used for routing protocol communication
fe80::/10 range
Example IPv6 routing table:
::/0 → 2001:db8::1 (default)
2001:db8:1::/64 → Local
fe80::/10 → Local (link-local)
Best Practices
Design
1. Hierarchical addressing:
Summarize at boundaries
Reduce routing table size
Improve scalability
2. Redundancy:
Multiple paths
Automatic failover
Load balancing
3. Appropriate protocol selection:
Small network: Static or RIP
Medium network: OSPF
Large network: OSPF or EIGRP
Internet-facing: BGP
Configuration
1. Document everything:
Network diagram
IP addressing plan
Routing protocol design
Policy decisions
2. Use authentication:
Prevent rogue routers
Secure routing updates
MD5 or stronger
3. Filter routes:
Prevent route leaks
Control advertisements
Security
Monitoring
1. Monitor routing tables:
Watch for unexpected routes
Check table size
Verify paths
2. Track metrics:
Convergence time
Route flaps
Update frequency
3. Alert on changes:
Route additions/deletions
Metric changes
Protocol state changes
Conclusion
IP routing is the fundamental mechanism that enables communication across networks and powers the internet. Understanding routing tables, routing protocols, and routing decisions is essential for network design, troubleshooting, and optimization.
Related Articles
Routing Fundamentals
- Default Gateway - Your first hop router
- Subnet Mask - Determining routing decisions
- IPv4 CIDR Notation - Route aggregation
- IPv4 Subnetting - Network segmentation
Routing Protocols
- BGP - Border Gateway Protocol
- ICMP - Routing error messages
- ARP - Local network resolution
- NAT - Address translation routing
Network Design
- IPv6 vs IPv4 - Routing differences
- Dual Stack Networking - Routing both protocols
- Load Balancing - Traffic distribution
- Anycast - Routing to nearest
Troubleshooting
- Ping and Traceroute - Route tracing
- Network Troubleshooting - Routing issues
- Connection Problems - Connectivity diagnosis
Explore More
- Networking Basics - Essential concepts
- Protocols - Internet protocols hub
Key takeaways: - Routing forwards packets between networks - Routing tables contain destination, next hop, metric - Longest prefix match determines route selection - Static routing: Manual, simple, predictable - Dynamic routing: Automatic, scalable, adaptive - IGPs: RIP, OSPF, EIGRP (within AS) - EGP: BGP (between AS) - Metrics determine best path - Administrative distance resolves conflicts - Troubleshoot layer by layer - IPv6 routing similar but with protocol variations
Understanding routing enables you to design efficient networks, troubleshoot connectivity issues, and comprehend how data flows across the global internet.