dotlinux guide

Exploring Dynamic Routing Protocols on Linux: OSPF and BGP

In modern networking, dynamic routing protocols are the backbone of scalable, resilient networks. Unlike static routing—where administrators manually define paths—dynamic protocols automatically adapt to topology changes (e.g., link failures, new devices), reducing operational overhead and improving reliability. While dedicated routing hardware (e.g., Cisco, Juniper) has long dominated this space, Linux-based systems offer a flexible, cost-effective alternative for running dynamic routing protocols. This blog explores two foundational dynamic routing protocols—OSPF (Open Shortest Path First) and BGP (Border Gateway Protocol)—with a focus on their implementation on Linux. We’ll cover core concepts, step-by-step setup using open-source tools like FRRouting, common use cases, and best practices to help you build robust, scalable networks.

Table of Contents

  1. Fundamentals of Dynamic Routing Protocols
    • Static vs. Dynamic Routing
    • OSPF vs. BGP: Key Differences
  2. OSPF on Linux
    • OSPF Core Concepts
    • Tools: FRRouting (FRR)
    • Step-by-Step OSPF Configuration
    • Verification & Troubleshooting
  3. BGP on Linux
    • BGP Core Concepts
    • iBGP vs. eBGP
    • Step-by-Step BGP Configuration
    • Verification & Troubleshooting
  4. Common Practices
    • When to Use OSPF vs. BGP
    • Route Redistribution
    • Filtering with Prefix Lists & Route Maps
  5. Best Practices
    • Network Design & Documentation
    • Security Hardening
    • Monitoring & Maintenance
  6. Conclusion
  7. References

1. Fundamentals of Dynamic Routing Protocols

Static vs. Dynamic Routing

  • Static Routing: Administrators manually configure routes. Simple for small networks but unscalable for large, dynamic environments (e.g., cloud data centers, ISPs).
  • Dynamic Routing: Protocols automatically exchange routing information and update paths. Ideal for networks with frequent changes (e.g., link failures, new subnets).

OSPF vs. BGP: Key Differences

FeatureOSPFBGP
TypeLink-State ProtocolPath-Vector Protocol
Use CaseInternal networks (intra-AS)Inter-AS (e.g., ISP peering, WAN)
MetricCost (based on bandwidth)Path attributes (AS_PATH, LOCAL_PREF, etc.)
ScalabilityAreas (hierarchical design)AS Numbers (autonomous systems)
Convergence SpeedFast (milliseconds to seconds)Slower (seconds to minutes)

2. OSPF on Linux

OSPF Core Concepts

OSPF (Open Shortest Path First) is a link-state protocol designed for intra-AS (Autonomous System) routing. Key concepts:

  • Areas: Hierarchical subdivisions to reduce LSA (Link-State Advertisement) flooding. Area 0 (backbone) is mandatory; all other areas must connect to it.
  • LSA Types: Packets that advertise link-state information (e.g., Type 1: Router LSA, Type 2: Network LSA).
  • Cost: Metric based on interface bandwidth (cost = 100 Mbps / interface_bandwidth by default).

Tools: FRRouting (FRR)

Linux lacks native OSPF support in the kernel, but open-source stacks like FRRouting (FRR) fill this gap. FRR is a fork of Quagga and supports OSPFv2/v3, BGP, RIP, and more.

Step-by-Step OSPF Configuration

Topology Overview

We’ll deploy OSPF between two Linux routers (R1 and R2) in Area 0, each advertising a loopback address:

  • R1:
    • eth0: 192.168.1.1/24 (link to R2)
    • lo: 10.0.0.1/32 (loopback, to be advertised)
  • R2:
    • eth0: 192.168.1.2/24 (link to R1)
    • lo: 10.0.0.2/32 (loopback, to be advertised)

Step 1: Enable IP Forwarding

Linux must act as a router by enabling IP forwarding:

# Enable IPv4 forwarding (persistent across reboots)
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Step 2: Install FRR

On Ubuntu/Debian:

# Add FRR repository
sudo apt update && sudo apt install -y gnupg2
curl -s https://deb.frrouting.org/frr/keys.asc | sudo apt-key add -
echo "deb https://deb.frrouting.org/frr $(lsb_release -s -c) frr-stable" | sudo tee -a /etc/apt/sources.list.d/frr.list

# Install FRR
sudo apt update && sudo apt install -y frr frr-pythontools

Step 3: Configure FRR for OSPF

FRR uses a central config file (/etc/frr/frr.conf) and a CLI (vtysh).

On R1:

  1. Open the FRR config:
    sudo vtysh
  2. Enter configuration mode and enable OSPF:
    R1> enable
    R1# configure terminal
    R1(config)# router ospf
    R1(config-ospf)# router-id 10.0.0.1  # Unique ID (use loopback IP)
    R1(config-ospf)# network 192.168.1.0/24 area 0  # Advertise link subnet
    R1(config-ospf)# network 10.0.0.1/32 area 0      # Advertise loopback
    R1(config-ospf)# exit
    R1(config)# exit
    R1# write memory  # Save config

On R2: Repeat with router-id 10.0.0.2 and adjust networks:

R2(config)# router ospf
R2(config-ospf)# router-id 10.0.0.2
R2(config-ospf)# network 192.168.1.0/24 area 0
R2(config-ospf)# network 10.0.0.2/32 area 0

Verification & Troubleshooting

Verify OSPF Neighbors

Check if R1 and R2 form an adjacency:

R1# show ip ospf neighbor
Neighbor ID     Pri   State           Dead Time   Address         Interface
10.0.0.2        1     FULL/DR         00:00:37    192.168.1.2     eth0

Verify OSPF Routes

Confirm loopback routes are learned:

R1# show ip route ospf
O   10.0.0.2/32 [110/2] via 192.168.1.2, eth0, 00:05:12

Common Issues

  • Area Mismatch: Both routers must use the same area (e.g., Area 0).
  • MTU Mismatch: OSPF requires consistent MTU on links (use ip link set eth0 mtu 1500).
  • Authentication: Enable with area 0 authentication message-digest and ip ospf message-digest-key 1 md5 <password>.

3. BGP on Linux

BGP Core Concepts

BGP (Border Gateway Protocol) is the de facto inter-AS routing protocol. Key concepts:

  • AS (Autonomous System): A network under a single administrative domain (e.g., AS65001 for private use).
  • iBGP vs. eBGP:
    • iBGP: Peers within the same AS (requires full mesh or route reflectors).
    • eBGP: Peers between different ASes (e.g., ISP A and ISP B).
  • Path Attributes: Used to select the best path (e.g., AS_PATH, NEXT_HOP, LOCAL_PREF).

Step-by-Step BGP Configuration

Topology 1: eBGP (Inter-AS)

Two ASes: AS65001 (R1) and AS65002 (R2), connected over 10.0.1.0/24.

R1 (AS65001):

  • eth0: 10.0.1.1/24 (eBGP link)
  • lo: 192.168.0.1/32 (to advertise)

R2 (AS65002):

  • eth0: 10.0.1.2/24 (eBGP link)
  • lo: 192.168.0.2/32 (to advertise)

Configure eBGP on R1

R1# configure terminal
R1(config)# router bgp 65001
R1(config-bgp)# neighbor 10.0.1.2 remote-as 65002  # eBGP peer
R1(config-bgp)# network 192.168.0.1/32              # Advertise loopback
R1(config-bgp)# exit
R1# write memory

Configure eBGP on R2

R2# configure terminal
R2(config)# router bgp 65002
R2(config-bgp)# neighbor 10.0.1.1 remote-as 65001  # eBGP peer
R2(config-bgp)# network 192.168.0.2/32              # Advertise loopback
R2(config-bgp)# exit
R2# write memory

Topology 2: iBGP (Intra-AS)

Two routers in AS65001: R1 and R3 (route reflector client).

R1 (Route Reflector):

  • eth1: 10.0.2.1/24 (iBGP link to R3)
  • router bgp 65001
    neighbor 10.0.2.2 remote-as 65001  # iBGP peer (R3)
    neighbor 10.0.2.2 route-reflector-client

R3 (Client):

  • eth1: 10.0.2.2/24
  • router bgp 65001
    neighbor 10.0.2.1 remote-as 65001  # iBGP peer (R1)

Verification & Troubleshooting

Verify BGP Peers

Check eBGP session status:

R1# show ip bgp summary
BGP router identifier 10.0.0.1, local AS number 65001
Neighbor        V         AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.0.1.2        4      65002    123     121        4    0    0 00:10:23        1

Verify BGP Routes

Confirm R1 learns R2’s loopback:

R1# show ip bgp
BGP table version is 4, local router ID is 10.0.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, = multipath,
              i internal, r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.0.2/32   10.0.1.2                 0             0 65002 i

Common Issues

  • AS_PATH Loop: eBGP rejects routes with local AS in AS_PATH.
  • NEXT_HOP Unreachable: iBGP requires an IGP (e.g., OSPF) to resolve NEXT_HOP.
  • Policy Misconfig: Use show ip bgp neighbors 10.0.1.2 advertised-routes to debug filtering.

4. Common Practices

When to Use OSPF vs. BGP

  • OSPF: Use for internal networks (e.g., data centers, campus LANs) where fast convergence and simplicity matter.
  • BGP: Use for inter-AS routing (e.g., connecting to ISPs, multi-cloud WANs) where policy-based routing is critical.

Route Redistribution

Redistribute routes between OSPF and BGP (use cautiously to avoid loops):

# On R1 (AS65001), redistribute OSPF into BGP
R1(config)# router bgp 65001
R1(config-bgp)# redistribute ospf 1 match internal external 1 external 2

Filtering with Prefix Lists & Route Maps

Limit advertised routes to prevent route leaks:

# Prefix list to allow only 192.168.0.0/24 subnets
R1(config)# ip prefix-list ALLOW-LOOPBACKS seq 5 permit 192.168.0.0/24 le 32

# Apply to BGP neighbor
R1(config)# route-map FILTER-ROUTES permit 10
R1(config-route-map)# match ip address prefix-list ALLOW-LOOPBACKS
R1(config)# router bgp 65001
R1(config-bgp)# neighbor 10.0.1.2 route-map FILTER-ROUTES out

5. Best Practices

Network Design & Documentation

  • OSPF Areas: Keep Area 0 small; use stub areas for non-backbone regions to reduce LSA flooding.
  • BGP AS Numbers: Use private ASNs (64512–65535) for internal networks; avoid overlapping with public ASNs.
  • Diagrams: Document topologies, ASNs, and prefixes (tools: draw.io, Lucidchart).

Security Hardening

  • Authentication: Enable BGP MD5 with neighbor 10.0.1.2 password <secret> and OSPF MD5 as shown earlier.
  • Prefix Filtering: Block bogon prefixes (e.g., 0.0.0.0/8) with ip prefix-list BOGONS deny 0.0.0.0/8.
  • Limit Peers: Only peer with trusted ASes; use neighbor <ip> shutdown to disable unused peers.

Monitoring & Maintenance

  • Tools: Use FRR’s built-in SNMP, Prometheus + Grafana (with frr-exporter), or Nagios for alerts.
  • Backups: Automate config backups with cp /etc/frr/frr.conf /backup/frr-$(date +%F).conf.
  • Updates: Regularly update FRR to patch vulnerabilities (e.g., sudo apt upgrade frr).

6. Conclusion

Linux, paired with tools like FRRouting, is a powerful platform for running dynamic routing protocols like OSPF and BGP. OSPF excels in internal networks with fast convergence, while BGP dominates inter-AS routing with flexible policy controls. By following best practices—such as hierarchical design, filtering, and monitoring—you can build scalable, resilient networks that adapt to dynamic changes.

Whether you’re managing a small data center or a global WAN, Linux-based routing offers the flexibility of open-source software with enterprise-grade functionality.

7. References