Technical Notes

Networking concepts - Routing

V
Vikalp Veer

Routing Tables

A routing table acts like a digital map for a network device, determining if it knows how to reach a destination and identifying the exact next step (the next gateway or next hop) to get the packet closer to its destination. A standard routing table typically contains these key pieces of information:

  • Network Destination: The IP address or subnet of the target network.
  • Next Hop (Gateway): The IP address of the next router the packet should be sent to.
  • Interface: The physical or virtual network port the device should use to send the packet out.
  • Metric/Cost: A numerical value (like hop count or latency) used to determine the best path when multiple routes exist.

If the device does not have a specific route to a destination, it will either drop the packet or forward it to a default gateway (a "catch-all" route).

Example of a routing table :

Network DestinationSubnet MaskNext Hop (Gateway)InterfaceMetric
0.0.0.00.0.0.0203.0.113.1WAN (Ethernet 1)10
192.168.1.0255.255.255.0On-link (Direct)LAN (Ethernet 2)0
10.0.0.0255.0.0.0192.168.1.254LAN (Ethernet 2)2

How This Table Works

  • Row 1 (Default Route): Matches any destination not listed elsewhere (the internet). It forwards traffic to the Service Provider gateway (203.0.113.1).
  • Row 2 (Directly Connected): Matches the local office network. No next hop is needed because the devices are plugged directly into this router.
  • Row 3 (Remote Subnet): Traffic meant for the 10.0.0.0 network is sent to another internal router located at 192.168.1.254.

How Routing Tables Are Populated

Routing tables are populated using three main methods: directly connected networks, static routing, and dynamic routing.

  1. Static Routing (Manual) Static routing happens when a network administrator manually types a permanent route into the router's configuration.

    • How it works: You tell the router explicitly: "To reach network X, always send traffic to gateway Y via interface Z." Best used for: Small, simple networks with only one or two routers, or stub networks (networks with only one way out).

    • Pros: Highly secure, uses zero CPU or network bandwidth, and gives the administrator complete control.

    • Cons: Does not automatically adapt. If a link breaks, traffic fails until an administrator manually changes the route. It becomes unmanageable in large network

  2. Dynamic Routing (Automatic) Dynamic routing relies on routing protocols. Routers run specialized software to talk to neighboring routers, automatically discovering networks and sharing updates.

    • How it works: Routers constantly trade information about the status of the network. If a path changes or breaks, the routers recalculate the topology and update their own routing tables in seconds.

    • Common Protocols:

      • OSPF (Open Shortest Path First): Often used inside large corporate networks to find the fastest path based on link bandwidth.
      • BGP (Border Gateway Protocol): The protocol that connects the entire global internet together.
    • Best used for: Large, complex networks that change frequently or require backup paths.

    • Pros: Highly scalable and automatically adapts to network failures or traffic congestion.

    • Cons: Consumes router CPU and network bandwidth to send updates. It is also more complex to configure and troubleshoot


Routing Policy

Routing policy dictates how a router selects the best path for network traffic and which routes it shares with other routers. It acts as a filter and manipulator of routing information, overriding default path selections (like lowest hop count or shortest AS path) to enforce administrative, security, or traffic-engineering goals.

How Routing Policies Work

Routers exchange network reachability information using routing protocols (like BGP, OSPF, or EIGRP). A routing policy intervenes in this exchange by evaluating incoming and outgoing route updates against a set of rules.

  • Filtering: Permitting or denying specific routes from being learned or advertised.

  • Attribute Manipulation: Changing path attributes (such as BGP's Multi-Exit Discriminator (MED) or Local Preference) to make certain paths more or less desirable.

How Routers Use Them:

When a router processes routing updates, it applies policies in three main ways:

  • Import Policies: Filter or modify routing updates received from neighboring routers before adding them to the routing information base (RIB) or routing table.
  • Export Policies: Filter or modify routing updates sent to neighboring routers from the local routing table.
  • Redistribution Policies: Control the sharing of routes learned from one routing protocol into another (e.g., OSPF to BGP).

How Policies are Configured

Policies are typically configured using route maps, prefix lists, or routing policy languages. They follow a logic of Match (identifying the route) and Action (what to do with it).

For example, to prefer a specific path in BGP, a Cisco IOS configuration might look like this:

  1. Define the criteria (Prefix List): Match a specific subnet.

    ip prefix-list MY_PREFIX permit 192.168.1.0/24
    
  2. Set the policy (Route Map): Match the prefix and modify the Local Preference attribute.

    route-map PREFER_PATH permit 10
      match ip address prefix-list MY_PREFIX
      set local-preference 200
    
  3. Apply the policy: Attach it to a BGP neighbor.

    router bgp 65001
     neighbor 10.0.0.1 route-map PREFER_PATH in
    

Concept of RIB and FIB

  1. The RIB (Routing Information Base)

    The RIB is the master database (Routing Table) where the router stores every single path it learns from all sources. It is managed by the router's central CPU.

    • The Content: It contains all routes learned via OSPF, BGP, static routing, and directly connected interfaces. If OSPF finds three different paths to a destination, all three paths sit inside the RIB.

    • The Job: The RIB compares these paths using Administrative Distance and metrics to choose the single absolute best path to a destination.

    • The Characteristic: It is optimized for calculation, not for speed. Packets are not switched using this table.

  2. The FIB (Forward Information Base)

    The FIB is a highly optimized, stripped-down mirror image of the absolute best paths chosen by the RIB. It is copied directly into specialized, lightning-fast hardware memory (like ASIC chips or TCAM).

    • The Content: It only contains the active, winning routes. It strips away protocol overhead, metrics, and alternate paths. It maps a destination IP directly to the outgoing physical interface and the next-hop MAC address.

    • The Job: When a physical packet enters a router port, the hardware checks the FIB to instantly throw the packet out of the correct exit port.

    • The Characteristic: It is optimized for lookup speed. It allows the router to forward millions of packets per second without involving the main CPU


Virtual Routing and Forwarding (VRF):

A Virtual Routing and Forwarding (VRF) instance is a technology that allows a single physical router to run multiple, completely isolated virtual routing tables at the same time.

Think of a standard routing table like an apartment building where everyone shares the same front door and mailroom. A VRF turns that building into a secure office complex where each business has its own private, isolated entrance and directory.

  1. The Core Components of a VRF When you create a VRF on a router, it splits the router's operating system into independent compartments. Each compartment contains:

    • A Dedicated IP Routing Table (RIB): Only routes assigned to this specific VRF exist here.
    • A Dedicated Forwarding Table (FIB): Used for lightning-fast hardware packet switching.
    • Assigned Interfaces: A physical port or subinterface can only belong to one VRF at a time.
    • Independent Routing Protocols: You can run separate instances of OSPF or BGP inside each VRF.
  2. Why VRFs are Necessary In a standard global routing table, IP addresses must be unique. VRFs eliminate this restriction to solve two major enterprise networking challenges:

    • Overlapping IP Addresses: If a Service Provider manages Network A (using 192.168.1.0/24) and Network B (also using 192.168.1.0/24), a standard router would crash or misroute the traffic. By placing Network A into VRF_Green and Network B into VRF_Blue, the router keeps them completely separate.

    • Strict Security Segregation: Guest Wi-Fi traffic can be placed into a VRF_Guest while corporate data sits in VRF_Corp. Even though they travel through the exact same physical router hardware, they cannot talk to or see each other.

  3. How VRF Routing Tables Compare to Global Tables

    FeatureGlobal Routing TableVRF Routing Table
    QuantityExactly one per routerHundreds or thousands per router
    IP OverlapForbidden (causes IP conflicts)Allowed across different VRFs
    Traffic ScopeVisible to all default interfacesVisible only to member interfaces
    Default BehaviorPublic/Shared transitIsolated private sandbox
  4. Moving Traffic Between VRFs (Route Leaking)

    By default, VRFs are completely dark to one another. However, organizations often need a "shared service" (like an internet gateway or a shared printer) accessible by multiple VRFs. To achieve this, engineers use Route Leaking. This is done using two BGP-based identifiers:

    • Route Distinguisher (RD): A unique number prepended to an IP address (e.g., 100:1) inside the router's memory. It transforms a standard IP (like 10.1.1.1) into a globally unique VPNv4 address (100:1:10.1.1.1), ensuring the router doesn't get confused by overlapping spaces

    • Route Targets (RT): Administrative tags applied to routes. A VRF can export its routes with a specific tag, and a different VRF can import that tag, surgically poking a hole through the isolation wall to share specific paths

Tags

networking