Routing Fundamentals & Static Routing
Routing Basics
- Concept: Routing is the process routers use to determine the path that IP packets should take over a network to reach their destination.
- Routing Table: A set of instructions stored on the router. Each route tells the router: “To send a packet to destination X, forward it to next-hop Y” (or directly to the destination if connected).
- Routing Methods:
- Dynamic Routing: Routers use protocols (e.g., OSPF) to automatically share routing information and build tables.
- Static Routing: A network administrator manually configures routes.
Connected and Local Routes
When an IP address is configured on a router interface and enabled with no shutdown, two routes are automatically added to the routing table per interface.
- Connected Route (Code:
C): A route to the entire network the interface is connected to.- Example: Interface IP
192.168.1.1/24generates a connected route to192.168.1.0/24.
- Example: Interface IP
- Local Route (Code:
L): A route to the exact IP address configured on the interface, using a/32subnet mask.- Example: Interface IP
192.168.1.1/24generates a local route to192.168.1.1/32. - Purpose: Tells the router, “If a packet is destined for this exact IP, receive it for yourself; do not forward it.”
- Example: Interface IP
Router(config)# interface gigabitethernet0/2
Router(config-if)# ip address 192.168.1.1 255.255.255.0
Router(config-if)# no shutdown
Router(config-if)# exit
Router# show ip interface brief
Router# show ip route
Things to note: In the show ip route output, you may see lines like 192.168.1.0/24 is variably subnetted, 2 subnets, 2 masks. These are not routes; they are informational headers indicating that the routing table contains multiple subnets and masks within that major network.
Route Selection Rules
When a router receives a packet, it evaluates the routing table to make a forwarding decision based on two strict rules:
- Match: The packet’s destination IP address must fall within the network range specified by the route.
- Longest Prefix Match (Most Specific Match): If multiple routes match the destination, the router selects the route with the longest subnet mask (highest prefix length).
- Example: A packet destined for
192.168.1.1matches both192.168.1.0/24and192.168.1.1/32. The/32route is more specific (longest prefix), so the router selects it and processes the packet locally.
- Example: A packet destined for
Things to note: If no route matches the destination IP, the router will drop the packet. Unlike switches, routers never flood unknown unicast packets.
Router vs. Switch Forwarding Behavior
| Feature | Switches (Layer 2) | Routers (Layer 3) |
|---|---|---|
| Forwarding Table | MAC Address Table | Routing Table |
| Match Type | Exact MAC address match | Longest Prefix Match (IP) |
| Unknown Destination | Floods the frame out all ports (except ingress) | Drops the packet |
Static Routing Configuration
Static routes are manually configured to reach remote networks not directly connected to the router.
Command Syntax
Router(config)# ip route <destination_network> <subnet_mask> <next_hop_ip | exit_interface | both>
- Next-Hop IP: The IP address of the adjacent router’s interface (Recommended).
- Exit Interface: The local interface the packet should be sent out of.
- Both: Specifies both the exit interface and next-hop IP.
Configuration Example (Path: PC1 -> R1 -> R3 -> R4 -> PC4)
! On R1: Route to PC4's network (192.168.4.0/24) via R3
R1(config)# ip route 192.168.4.0 255.255.255.0 192.168.13.3
! On R3: Route to PC1's network (192.168.1.0/24) via R1
R3(config)# ip route 192.168.1.0 255.255.255.0 192.168.13.1
! On R3: Route to PC4's network (192.168.4.0/24) via R4
R3(config)# ip route 192.168.4.0 255.255.255.0 192.168.34.4
! On R4: Route to PC1's network (192.168.1.0/24) via R3
R4(config)# ip route 192.168.1.0 255.255.255.0 192.168.34.3
Next-Hop vs. Exit Interface Behavior
| Configuration Method | Routing Table Display | Underlying Mechanism |
|---|---|---|
| Next-Hop IP only | Shows next-hop IP address | Standard recursive lookup. |
| Exit Interface only | Shows as is directly connected |
Relies on Proxy ARP to resolve the next-hop MAC address. (Note: Proxy ARP is beyond CCNA scope, but the display behavior is testable). |
| Both | Shows both interface and next-hop | Combines benefits; avoids recursive lookup delays and Proxy ARP reliance. |
Things to note: You cannot use prefix length notation (e.g., /24) in the ip route command. You must use the dotted-decimal subnet mask (e.g., 255.255.255.0).
Default Routing
- Concept: A default route is the “least specific” route possible (
0.0.0.0 0.0.0.0). It matches any destination IP address. - Purpose: Acts as a catch-all for traffic destined to networks not explicitly listed in the routing table (commonly used to point toward the Internet).
- Terminology: Also known as the Gateway of Last Resort.
! Configure default route pointing to an ISP router
Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2
Things to note: In the show ip route output, a default route is marked with an asterisk (S*), indicating it is a candidate default. The output will also state: Gateway of last resort is 203.0.113.2 to network 0.0.0.0.
Layer 2 vs. Layer 3 Packet Forwarding
When a packet travels across multiple routers, Layer 3 and Layer 2 headers behave differently:
- Layer 3 (IP Header): Source and Destination IP addresses never change from the original sender to the final receiver.
- Layer 2 (Ethernet Header): Source and Destination MAC addresses change at every hop.
- Sender encapsulates packet with Default Gateway’s MAC as destination.
- Router de-encapsulates L2, checks L3 routing table, and re-encapsulates with the next-hop router’s MAC as the new destination.
- This repeats until the final router encapsulates the packet with the end host’s MAC address.
sequenceDiagram
participant PC1
participant R1
participant R3
participant R4
participant PC4
PC1->>R1: L2 Dest: R1 MAC | L3 Dest: PC4 IP
R1->>R3: L2 Dest: R3 MAC | L3 Dest: PC4 IP
R3->>R4: L2 Dest: R4 MAC | L3 Dest: PC4 IP
R4->>PC4: L2 Dest: PC4 MAC | L3 Dest: PC4 IP
Command Summary
! View interface IP assignments and status
Router# show ip interface brief
! View the routing table (includes Codes legend, C=Connected, L=Local, S=Static)
Router# show ip route
! Configure a static route using Next-Hop IP (Recommended)
Router(config)# ip route <destination_network> <subnet_mask> <next_hop_IP>
! Configure a static route using Exit Interface only
Router(config)# ip route <destination_network> <subnet_mask> <exit_interface>
! Configure a static route using BOTH Exit Interface and Next-Hop IP
Router(config)# ip route <destination_network> <subnet_mask> <exit_interface> <next_hop_IP>
! Configure a default route (Gateway of Last Resort)
Router(config)# ip route 0.0.0.0 0.0.0.0 <next_hop_IP>
Common Misconceptions to Avoid:
- Routers flood unknown traffic: False. Routers drop packets if no matching route exists. Only switches flood unknown unicast frames.
/32means a network route: False. A/32route is a host route (Local route), specifying exactly one IP address.- Static routes can use
/24syntax: False. Theip routecommand strictly requires dotted-decimal subnet masks (e.g.,255.255.255.0), not CIDR slash notation. - Two-way reachability: Configuring a route on R1 to reach R4 does not guarantee R4 can reply. You must configure return routes on all intermediate routers (R4 -> R3 -> R1) for communication (like ICMP ping) to succeed.