Static And Dynamic Routing
Category: Routing and Switching
Type: Network Concepts
Generated on: 2025-07-10 09:00:12
For: Network Engineering, Administration & Technical Interviews
1. Quick Overview
Section titled “1. Quick Overview”What is it?
- Routing: The process of selecting the best path for data packets to travel from a source to a destination network.
- Static Routing: Manually configured routing tables on routers. The network administrator explicitly defines the paths.
- Dynamic Routing: Routers automatically learn and adapt to network changes using routing protocols.
Why is it important?
- Static Routing: Simplicity for small, stable networks. Provides high security due to manual configuration. Can be used as a backup route.
- Dynamic Routing: Scalability for large, complex networks. Automatic adaptation to network failures and changes. Reduces administrative overhead.
2. Key Concepts
Section titled “2. Key Concepts”- Routing Table: A table stored on a router that contains information about known networks and how to reach them.
- Next Hop: The next router in the path toward the destination network.
- Administrative Distance (AD): A metric used to prioritize routing sources. Lower AD is preferred. Static routes have a default AD of 1 (Cisco), making them preferred over dynamic routing protocols by default.
- Metric: A value that represents the cost of a path. Routing protocols use metrics to determine the best path. Examples: Hop Count (RIP), Bandwidth (OSPF), Delay (EIGRP).
- Convergence: The process by which routers in a network agree on the best paths to all destinations.
- Routing Protocol: A protocol used by routers to exchange routing information.
- Autonomous System (AS): A collection of networks under a common administrative domain.
- Interior Gateway Protocol (IGP): A routing protocol used within an AS (e.g., RIP, OSPF, EIGRP).
- Exterior Gateway Protocol (EGP): A routing protocol used between ASes (e.g., BGP).
- Distance Vector Routing: Routing protocols that advertise their entire routing table to neighbors (e.g., RIP).
- Link-State Routing: Routing protocols that advertise the state of their links to all routers in the network (e.g., OSPF).
3. How It Works
Section titled “3. How It Works”Static Routing
- Administrator manually configures the routing table on each router.
- When a router receives a packet, it consults its routing table.
- If a matching entry exists, the router forwards the packet to the specified next hop.
- If no matching entry exists, the router drops the packet (or uses a default route, if configured).
+-------+ +-------+ +-------+| R1 |------| R2 |------| R3 |+-------+ +-------+ +-------+ | | | 192.168.1.0/24 | 192.168.3.0/24 | 192.168.2.0/24
R1's Routing Table (Example):Destination Next Hop Interface192.168.2.0/24 192.168.1.2 Eth0192.168.3.0/24 192.168.1.2 Eth0
R2's Routing Table (Example):Destination Next Hop Interface192.168.1.0/24 192.168.2.1 Eth0192.168.3.0/24 192.168.2.3 Eth1
R3's Routing Table (Example):Destination Next Hop Interface192.168.1.0/24 192.168.3.2 Eth0192.168.2.0/24 192.168.3.2 Eth0Dynamic Routing
- Routers exchange routing information with their neighbors using a routing protocol.
- Each router builds a routing table based on the received information and its own knowledge of the network.
- Routing protocols use algorithms to determine the best path to each destination.
- When network changes occur, routers detect the changes and update their routing tables.
- The updated routing information is propagated to other routers, allowing the network to converge on a new set of best paths.
+-------+ +-------+ +-------+| R1 |------| R2 |------| R3 |+-------+ +-------+ +-------+ | | | 192.168.1.0/24 | 192.168.3.0/24 | 192.168.2.0/24
(Using RIP as an example - Distance Vector)
R1 advertises 192.168.1.0/24 to R2R2 advertises 192.168.1.0/24, 192.168.2.0/24 to R1 and R3R3 advertises 192.168.2.0/24, 192.168.3.0/24 to R24. Protocol Details
Section titled “4. Protocol Details”RIP (Routing Information Protocol)
- Distance Vector Protocol: Advertises its entire routing table every 30 seconds.
- Metric: Hop count. Maximum hop count is 15 (16 is considered unreachable).
- Port: UDP port 520.
- Header Format: (Simplified)
- Command (Request or Response)
- Version
- Address Family Identifier (AFI)
- Route Tag
- IP Address
- Metric (Hop Count)
- Message Flow: Routers periodically send their routing tables to their neighbors. When a router receives an update, it updates its own routing table if the new route is better (lower hop count) or if the existing route has timed out.
- Limitations: Slow convergence, susceptible to routing loops (Count-to-Infinity problem).
OSPF (Open Shortest Path First)
- Link-State Protocol: Advertises the state of its links to all routers in the area.
- Metric: Cost, based on bandwidth (Cisco default: 100 Mbps reference bandwidth).
- Protocol: IP protocol 89.
- Header Format: (Simplified)
- Version
- Message Type (Hello, Database Description, Link State Request, Link State Update, Link State Acknowledgment)
- Router ID
- Area ID
- Checksum
- Authentication
- Message Flow:
- Hello Packets: Establish and maintain neighbor relationships.
- Database Description Packets: Exchange database summaries.
- Link State Request Packets: Request specific link state information.
- Link State Update Packets: Contain link state advertisements (LSAs).
- Link State Acknowledgment Packets: Acknowledge receipt of LSAs.
- Advantages: Fast convergence, less susceptible to routing loops, supports VLSM.
- Areas: Divides a large network into smaller, more manageable areas. Area 0 (backbone area) must be present.
EIGRP (Enhanced Interior Gateway Routing Protocol)
- Advanced Distance Vector Protocol (Hybrid): Uses a Diffusing Update Algorithm (DUAL) for fast convergence.
- Metric: Composite metric based on bandwidth, delay, load, and reliability (K1-K5 values). Bandwidth and Delay are used by default.
- Protocol: Proprietary Cisco protocol.
- Protocol: IP protocol 88.
- Message Flow:
- Hello Packets: Discover neighbors.
- Update Packets: Exchange routing information.
- Query Packets: Search for an alternate path.
- Reply Packets: Respond to a query.
- Acknowledgment Packets: Acknowledge receipt of a packet.
- Features: Fast convergence, supports VLSM, supports unequal-cost load balancing.
BGP (Border Gateway Protocol)
- Path Vector Protocol: Used for routing between autonomous systems (ASes).
- Protocol: TCP port 179.
- Attributes: Path attributes are used to influence routing decisions (e.g., AS_PATH, MED, Local Preference).
- Message Flow:
- Open: Establishes a BGP session.
- Update: Advertises or withdraws routes.
- Keepalive: Maintains the BGP session.
- Notification: Closes the BGP session due to an error.
- EBGP: BGP sessions between different ASes.
- IBGP: BGP sessions within the same AS.
5. Real-World Examples
Section titled “5. Real-World Examples”- Small Home Network: Static routing might be sufficient if you only have one router connected to the internet. A default route pointing to the ISP’s gateway would be configured.
- Small Business: Static routing for simple network segments and a dynamic routing protocol (e.g., RIP) for internal routing.
- Large Enterprise Network: OSPF or EIGRP for internal routing, BGP for connecting to other organizations or the internet.
- ISP Network: BGP is essential for routing between different networks (ASes) on the internet.
- Data Center: OSPF or EIGRP with fast convergence and load balancing capabilities.
Example Scenario (Small Office):
A small office has two routers, R1 and R2. R1 connects to the internet, and R2 connects to the internal network (192.168.1.0/24).
- Static Routing on R2: A static route is configured on R2 to forward all traffic destined for the internet (0.0.0.0/0) to R1.
- Static Routing on R1: A static route is configured on R1 to forward traffic destined for the internal network (192.168.1.0/24) to R2.
6. Common Issues
Section titled “6. Common Issues”Static Routing Problems:
- Manual Configuration: Time-consuming and error-prone.
- Scalability: Difficult to manage in large networks.
- Lack of Fault Tolerance: If a link fails, traffic will not be automatically rerouted.
- Configuration Errors: Incorrect IP addresses or subnet masks can cause routing problems.
Troubleshooting Static Routing:
- Verify Routing Tables: Use the
show ip routecommand on Cisco devices orip routeon Linux to check the routing table. - Ping Tests: Use the
pingcommand to test connectivity between devices. - Traceroute: Use the
traceroutecommand to trace the path of a packet. - Check Interfaces: Verify that interfaces are up and configured correctly.
Dynamic Routing Problems:
- Convergence Issues: Slow convergence can lead to temporary routing loops.
- Configuration Complexity: Dynamic routing protocols can be complex to configure.
- Security Vulnerabilities: Routing protocols can be vulnerable to attacks, such as routing table poisoning.
- Resource Consumption: Dynamic routing protocols consume CPU and memory resources.
Troubleshooting Dynamic Routing:
- Check Neighbor Relationships: Verify that routers have formed neighbor relationships.
- Check Routing Updates: Monitor routing updates to ensure that routers are exchanging information correctly.
- Check Metrics: Verify that the metrics used by the routing protocol are configured correctly.
- Debug Routing Protocols: Use debug commands to troubleshoot routing protocol issues. (e.g.,
debug ip ospf events,debug ip rip). - Packet Capture: Use Wireshark or tcpdump to capture and analyze routing protocol traffic.
7. Configuration Examples
Section titled “7. Configuration Examples”Cisco IOS Configuration Examples:
Static Routing:
! Configure a static route to network 192.168.2.0/24 via 192.168.1.2ip route 192.168.2.0 255.255.255.0 192.168.1.2
! Configure a default route to the internet via 203.0.113.1ip route 0.0.0.0 0.0.0.0 203.0.113.1RIP Configuration:
router rip version 2 network 192.168.1.0 network 10.0.0.0 no auto-summary ! Disable automatic summarizationOSPF Configuration:
router ospf 1 router-id 1.1.1.1 network 192.168.1.0 0.0.0.255 area 0 network 10.0.0.0 0.0.0.255 area 0EIGRP Configuration:
router eigrp 100 network 192.168.1.0 network 10.0.0.0 no auto-summaryLinux Configuration Examples:
Static Routing:
# Add a route to network 192.168.2.0/24 via 192.168.1.2ip route add 192.168.2.0/24 via 192.168.1.2
# Add a default route to the internet via 203.0.113.1ip route add default via 203.0.113.1Viewing Routing Table (Linux):
ip route showPacket Capture (tcpdump example):
# Capture RIP traffic on interface eth0tcpdump -i eth0 port 520
# Capture OSPF traffic on interface eth0tcpdump -i eth0 proto ospf
# Capture EIGRP traffic on interface eth0tcpdump -i eth0 proto eigrp8. Interview Questions
Section titled “8. Interview Questions”Q: What is the difference between static and dynamic routing?
A: Static routing is manually configured, while dynamic routing is automatically learned and adapted. Static routing is suitable for small, stable networks, while dynamic routing is better for large, complex networks.
Q: What are the advantages and disadvantages of static routing?
A:
- Advantages: Simplicity, security, control.
- Disadvantages: Manual configuration, scalability issues, lack of fault tolerance.
Q: What are the advantages and disadvantages of dynamic routing?
A:
- Advantages: Automatic adaptation, scalability, fault tolerance.
- Disadvantages: Complexity, resource consumption, security vulnerabilities.
Q: What is Administrative Distance (AD)?
A: AD is a metric used to prioritize routing sources. Lower AD is preferred. Static routes have a default AD of 1 (Cisco), making them preferred over dynamic routing protocols by default.
Q: Explain the difference between Distance Vector and Link-State routing protocols.
A: Distance vector protocols advertise their entire routing table to neighbors, while link-state protocols advertise the state of their links to all routers in the network. Link-state protocols generally converge faster and are less susceptible to routing loops.
Q: What is the role of areas in OSPF?
A: Areas divide a large network into smaller, more manageable segments. This reduces the amount of routing information that each router needs to process, improving performance and scalability. Area 0 (the backbone area) must be present.
Q: What is BGP and why is it used?
A: BGP (Border Gateway Protocol) is a path vector routing protocol used for routing between autonomous systems (ASes). It’s used by ISPs and large organizations to exchange routing information on the internet.
Q: How does EIGRP differ from other distance vector protocols?
A: EIGRP is an advanced distance vector protocol that uses a Diffusing Update Algorithm (DUAL) for fast convergence and supports unequal-cost load balancing. It’s also a hybrid protocol.
Q: You have two routes to the same destination, one learned via OSPF and one configured statically. Which route will the router use?
A: The router will use the static route because it has a lower administrative distance (AD). Static routes have an AD of 1 (Cisco), while OSPF has an AD of 110.
Q: How can you prevent routing loops in a network using RIP?
A: While RIP is prone to loops, you can mitigate this by: * Limiting the hop count (max 15). * Using split horizon (don’t advertise a route back to the neighbor from which you learned it). * Using route poisoning (advertise a route as unreachable with a hop count of 16 when it becomes invalid).
9. Related Concepts
Section titled “9. Related Concepts”- VLSM (Variable Length Subnet Masking)
- CIDR (Classless Inter-Domain Routing)
- Route Summarization
- Default Route
- Routing Protocol Security
- Network Address Translation (NAT)
- Access Control Lists (ACLs)
- Quality of Service (QoS)
- Software-Defined Networking (SDN)
This cheatsheet provides a comprehensive overview of static and dynamic routing, covering key concepts, practical examples, and troubleshooting tips. It should serve as a valuable resource for students, network administrators, and anyone preparing for networking interviews. Remember to practice configuring and troubleshooting routing protocols in a lab environment to solidify your understanding.