Routing

What is a Router?

A router is a device that forwards packets between different networks. It works at Layer 3 (Network Layer) of the OSI model and makes decisions based on the destination IP address of each packet. In simple terms, a router connects separate networks, such as LANs, WANs, or the Internet, and finds the best way for data to travel. Router core functions is:

  • Packet forwarding: Routes traffic from one network to another.

  • Routing table management: Keeps track of network paths and their metrics.

  • NAT/PAT: Maps private IPs to public IPs in situations with limited IPv4 addresses.

  • Security: Applies ACLs, firewall rules, or filters out malicious traffic.

  • Dynamic adjustment: Changes routing in real time if the network topology changes.

Diagram

This shows the main role of a router: connecting different networks.

+--------------------+          +----------+          +----------+          +-----------------+
| LAN                |----------| Router A |----------| Internet |----------| Router B        |
| 192.168.1.0/24     |          |          |          |          |          | LAN 10.0.0.0/24 |
+--------------------+          +----------+          +----------+          +-----------------+

Static vs Dynamic Routing

The main difference is how the router learns and keeps track of the paths in its routing table.

Static Routing

Static routes are set up manually by a network administrator. A static route defines the destination network, subnet mask, and the next-hop IP address or outgoing interface.

Advantages:

  • Predictable, no protocol overhead

  • Simple to troubleshoot in small networks

  • Secure (cannot be modified by other routers)

Disadvantages:

  • Manual updates required for topology changes

  • Not scalable for large networks

  • Can lead to human errors

Example Static Routing Table:

Destination Network
Subnet Mask
Next Hop
Interface

192.168.2.0

255.255.255.0

192.168.1.2

eth0

10.0.0.0

255.0.0.0

192.168.1.3

eth1

0.0.0.0

0.0.0.0

192.168.1.1

eth0

Dynamic Routing

Dynamic routing uses protocols to automatically share network information. Routers communicate to discover routes, share updates, and adapt to network failures.

Advantages:

  • Scales well in large networks

  • Changes automatically with topology modifications

  • Lowers administrative workload

Disadvantages:

  • Uses CPU, memory, and bandwidth for routing updates

  • Can share misconfigurations if not well designed

  • Requires careful protocol selection for stability

Routing Protocols

Routers use specific protocols to exchange routing information automatically

Protocol
Type
Metric/Feature
Use Case

RIP

Distance-vector

Hop count (max 15)

Small networks

OSPF

Link-state

SPF algorithm, fast convergence

Enterprise networks

BGP

Path-vector

Policies & AS paths

Internet backbone

EIGRP

Hybrid

Bandwidth, delay, reliability

Cisco enterprise networks

RIP (Routing Information Protocol)

  • Type: Distance-vector protocol.

  • Operation: Sends its entire routing table to neighbors every 30 seconds.

  • Metric: Uses hop count (the number of routers to cross).

  • Limitation: Maximum of 15 hops; slow to respond and prone to loops. Best for small, simple networks.

OSPF (Open Shortest Path First)

  • Type: Link-state protocol.

  • Operation: Routers exchange LSAs (Link-State Advertisements) to create a complete map of the network topology in a Link-State Database.

  • Algorithm: Uses Dijkstra's SPF algorithm to find the shortest path to each network.

  • Benefit: Fast response and efficient path selection, making it good for medium and large networks.

BGP (Border Gateway Protocol)

  • Type: Path-vector protocol.

  • Operation: Used to connect different Autonomous Systems (AS) on the Internet. An AS is a network under a single administrative control (e.g., an ISP).

  • Decision Basis: Routing is based on policies, rules, and paths, not just simple metrics.

  • Role: The main protocol that connects the global Internet.

Routing Tables

A router's routing table contains the information needed for forwarding decisions.

  • Destination network: Where the packet should go

  • Subnet mask: Network part of the IP

  • Next hop: Router to send traffic to

  • Interface: Outgoing port

  • Metric: Cost of route (lower values are preferred)

Example Routing Table:

Destination
Subnet Mask
Next Hop
Interface
Metric

192.168.1.0

255.255.255.0

0.0.0.0

eth0

0

192.168.2.0

255.255.255.0

192.168.1.2

eth1

10

10.0.0.0

255.0.0.0

192.168.1.3

eth1

5

0.0.0.0

0.0.0.0

192.168.1.1

eth0

100

The route 0.0.0.0/0 is the default route, covering all traffic to unknown destinations, usually directing it to the Internet.

Packet Path Example:

  1. A sends a packet to PC B. It sees that 10.0.0.5 is not part of its local network (192.168.1.0/24), so it forwards the packet to its default gateway, Router A.

  2. Router A checks its routing table. It finds an entry for the network 10.0.0.0/8 and sees it can reach that via Router B. It forwards the packet to Router B.

  3. Router B gets the packet, looks at its own table, and sees that the specific PC (10.0.0.5) is on a network directly connected to it. It delivers the packet straight to PC B.

OSPF Routing Example

Scenario: 3 routers forming a backbone

  • Router A: 192.168.1.0/24

  • Router B: 192.168.2.0/24

  • Router C: 10.0.0.0/24

OSPF Steps:

  1. Neighbor Discovery: Routers exchange Hello packets to discover OSPF neighbors on their directly connected networks

  2. Link-State Advertisement (LSA): Routers send LSAs to describe their connected networks and the state of their links

  3. Link-State Database (LSDB): Each router gathers all LSAs into a synchronized LSDB, forming a complete map of the OSPF area

  4. SPF Calculation: Each router runs the Dijkstra SPF algorithm on the LSDB to independently calculate the shortest paths to every network

  5. Routing Table Update: The best paths from the SPF tree are added to the router's IP routing table.

Router B Table:

Network
Next Hop
Metric

192.168.1.0

Router A

1

192.168.2.0

Local

0

10.0.0.0

Router C

1

Routing Loops and Convergence

  • Routing Loops: Happen when a packet is endlessly passed between routers in a cycle, never reaching its destination. Prevention methods are important:

    • TTL (Time-to-Live): A counter in the IP header that decreases with each hop; the packet is discarded if TTL reaches zero

    • Split Horizon: A rule that stops a route from being advertised back out the interface it was learned from

    • Route Poisoning: Marking a failed route as "unreachable" and advertising it to prevent other routers from using it

  • Convergence Delay: The time taken for all routers in a network to update their routing tables after a topology change. Fast convergence is vital for network stability. OSPF converges faster than RIP because it uses a more efficient update process.

Traceroute Example

Command: traceroute 10.0.0.5

This shows the path a packet takes and is useful for troubleshooting routing issues.

Hybrid Routing Networks

Real-world networks often mix static and dynamic routing to take advantage of both approaches:

  • Static Routes are used for important, stable paths (e.g., to a central server farm or a specific security subnet), where predictability is essential

  • Dynamic Routes (OSPF, EIGRP) serve the core network and inter-office links to provide automatic adjustment and scalability

This hybrid setup minimizes protocol overhead when possible while ensuring reliability and flexibility across the network.

Hybrid Routing Example

In this example, a static route may be used inside the local LAN for a specific server, while BGP is used to exchange routes with the Internet and OSPF is used within the larger corporate network.

Last updated