Routing is the process of choosing a path for packets from source to destination across many interconnected networks. Routers carry out this work at every hop.

Routers and Routing Tables

A router connects two or more networks and forwards packets between them, using the destination IP address. Each router keeps a routing table, whose entries give a destination network (prefix), the next hop (the next router's address) or exit interface, and a metric (cost). When a packet arrives, the router looks up its destination address and forwards it accordingly. Two separate jobs are involved: routing (building the table, the control plane) and forwarding (moving each packet to the right output, the data plane).

Definition: Routing. The process by which routers determine the path that packets take from source to destination, by building routing tables and forwarding each packet to the next hop.

Longest Prefix Match

Several entries may match a destination address. The router chooses the most specific one, the entry with the longest prefix. For example, if the table has 10.0.0.0/8 and 10.1.2.0/24, a packet to 10.1.2.7 uses the /24 entry. The default route 0.0.0.0/0 matches every address and is used when nothing more specific matches; it usually points to the internet service provider.

Static Routing

In static routing, an administrator enters routes manually, such as ip route 192.168.20.0 255.255.255.0 10.0.0.2 on a Cisco router. It is simple, predictable and secure, uses no bandwidth for routing updates and no router CPU for calculation. But it does not adapt to failures or changes: if a link goes down, traffic is lost until someone changes the route. It suits small networks, stub networks with one exit, and default routes.

Dynamic Routing

In dynamic routing, routers run a routing protocol to exchange information and build their tables automatically. They adapt to topology changes and failures, finding new paths, and they scale to large networks. The costs are bandwidth for updates, CPU and memory, more complex configuration, and a period of convergence while all routers come to agree after a change. Protocols are grouped as interior gateway protocols (IGP), used within one autonomous system (AS), such as RIP and OSPF, and exterior gateway protocols (EGP) between autonomous systems, such as BGP. By algorithm, they are distance-vector (RIP), link-state (OSPF) or path-vector (BGP). When a router learns the same network from several sources, it prefers the source with the lowest administrative distance (directly connected 0, static 1, OSPF 110, RIP 120).

Table 3.1: Static and dynamic routing

Feature Static Dynamic
Configuration Manual Automatic, by protocol
Adapts to failures No Yes
Overhead None Updates, CPU, memory
Security High Needs authentication
Best for Small or stub networks Large, changing networks

Example 3.1: Longest prefix match

Problem: A router's table has: 0.0.0.0/0 via ISP, 10.0.0.0/8 via R1, 10.1.0.0/16 via R2 and 10.1.2.0/24 via R3. Where does it send packets to (a) 10.1.2.7, (b) 10.1.9.9, (c) 10.200.0.1, (d) 8.8.8.8?

Solution:

  1. 10.1.2.7 matches /0, /8, /16 and /24; the longest is /24, so R3.
  2. 10.1.9.9 matches /0, /8 and /16; the longest is /16, so R2.
  3. 10.200.0.1 matches /0 and /8, so R1.
  4. 8.8.8.8 matches only the default route, so the ISP.

Result: R3, R2, R1 and the ISP.

import ipaddress
table = [("0.0.0.0/0", "ISP"), ("10.0.0.0/8", "R1"),
         ("10.1.0.0/16", "R2"), ("10.1.2.0/24", "R3")]
def lookup(addr):
    ip = ipaddress.ip_address(addr)
    hits = [(ipaddress.ip_network(n), hop) for n, hop in table
            if ip in ipaddress.ip_network(n)]
    net, hop = max(hits, key=lambda h: h[0].prefixlen)
    return net, hop
for a in ["10.1.2.7", "10.1.9.9", "10.200.0.1", "8.8.8.8"]:
    net, hop = lookup(a)
    print(f"{a:<11} matches {str(net):<12} -> {hop}")

Output

10.1.2.7    matches 10.1.2.0/24  -> R3
10.1.9.9    matches 10.1.0.0/16  -> R2
10.200.0.1  matches 10.0.0.0/8   -> R1
8.8.8.8     matches 0.0.0.0/0    -> ISP

Common mistakes

  • Choosing the first matching route instead of the longest matching prefix.
  • Using static routes in a large network where links change often.
  • Confusing routing (building the table) with forwarding (using it).

Key takeaways

  • Routers forward packets by destination IP using routing tables.
  • The longest prefix match wins; 0.0.0.0/0 is the default route.
  • Static routes are manual and fixed; dynamic routing adapts automatically.
  • IGPs (RIP, OSPF) work inside an AS; BGP works between ASes.

Practice questions

  1. What is the default route?
  2. Give one advantage and one disadvantage of static routing.
  3. What is convergence?

Answers to the practice questions

  1. 0.0.0.0/0, which matches any destination not matched by a more specific entry.
  2. It has no overhead and is secure, but it does not adapt to failures.
  3. The process by which all routers come to agree on routes after a change.

Sources

  • Official BCA syllabus Computer Networks, course code 26BCA404DS02, Unit III