Part I: Network Theory Chapter 7

Routing and Network Infrastructure

Routing protocols, BGP security (RPKI), NAT, SD-WAN, and how data finds its way across the internet

Chapter 7: Routing and Network Infrastructure

The Two-Hour Internet Hijack of a Cryptocurrency Exchange

On April 24, 2018, attackers executed a sophisticated BGP hijack targeting MyEtherWallet, a popular cryptocurrency wallet service. For approximately two hours, traffic destined for Amazon’s Route 53 DNS servers was rerouted through an attacker-controlled network in Russia.

Users attempting to access MyEtherWallet were served a phishing site with a stolen SSL certificate. The site looked identical to the real thing. Victims who entered their credentials had their cryptocurrency wallets drainedβ€”approximately $150,000 was stolen.

How did attackers redirect traffic meant for one of the world’s largest cloud providers? They exploited BGP, the protocol that determines how traffic flows across the entire internet. BGP is built on trustβ€”routers believe what other routers tell them about which networks they can reach. There’s no built-in verification that an announcement is legitimate.

This incident wasn’t unique. BGP hijacks happen regularly, sometimes accidentally (a misconfiguration in Pakistan once took down YouTube globally), sometimes maliciously. Understanding routingβ€”how it works and how it can failβ€”is essential for anyone working in network security.


Finding the Path

When you send a packet to a server halfway around the world, how does it get there? This might seem like a simple question, but the answer involves one of the most elegant and critical systems in all of computer networking.

Your computer doesn’t know the complete pathβ€”it only knows to send packets to its default gateway (router). From there, each router along the way makes independent decisions about where to forward the packet next, based on routing tables that describe the network topology.

Routing is the process of selecting paths through a network. It’s what makes the internetβ€”a network of networksβ€”function as a coherent whole.

Think of it like asking for driving directions before GPS existed. You might know how to get to the highway, but you don’t know every turn to reach your destination. Instead, you follow signs, ask for directions at key points, and trust that each segment of guidance will get you closer. The internet works similarlyβ€”each router only needs to know the next step, not the entire journey.

In this chapter, we’ll build up from the basics of how individual routers make forwarding decisions, to the protocols that let routers share information with each other, to the global BGP system that ties it all together. We’ll also explore NAT, which enables the modern internet despite IPv4 address exhaustion, and SD-WAN, which represents the latest evolution in enterprise networking.


Routing Fundamentals

Let’s start with the basics: how does a single router decide where to send a packet? Understanding this foundation is essential before we can explore how routers learn about networks they’ve never seen.

How Routing Works

Routers examine the destination IP address of each packet and consult their routing table to determine the next hopβ€”the next router in the path toward the destination. This process repeats at each router until the packet reaches its destination network.

Routing Example

Routing Example:
═══════════════════════════════════════════════════════════════════

Source: 192.168.1.100 β†’ Destination: 8.8.8.8 (Google DNS)

   [Your PC]                                            [Google]
   192.168.1.100                                        8.8.8.8
       β”‚                                                   β–²
       β”‚ 1. "8.8.8.8 not local,                            β”‚
       β”‚    send to default gateway"                       β”‚
       β–Ό                                                   β”‚
   [Home Router]                                           β”‚
   192.168.1.1                                             β”‚
       β”‚                                                   β”‚
       β”‚ 2. "8.8.8.8 β†’ send to ISP"                        β”‚
       β–Ό                                                   β”‚
   [ISP Router]                                            β”‚
       β”‚                                                   β”‚
       β”‚ 3. "8.8.8.8 β†’ route to upstream"                  β”‚
       β–Ό                                                   β”‚
   [Tier 2 ISP] ──► [Tier 1 ISP] ──► [Google Edge] β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       
Each router only knows the NEXT hop, not the full path!

Routing Table Structure

A routing table maps destination networks to next-hop addresses and outgoing interfaces:

$ ip route     # Linux
$ netstat -rn  # macOS

Example Routing Table:
═══════════════════════════════════════════════════════════════════

Destination        Gateway         Interface   Metric  Flags
───────────        ───────         ─────────   ──────  ─────
0.0.0.0/0          192.168.1.1     eth0        100     UG   (Default)
192.168.1.0/24     0.0.0.0         eth0        0       U    (Direct)
10.0.0.0/8         192.168.1.254   eth0        50      UG   (Static)
172.16.0.0/16      192.168.1.253   eth0        50      UG   (Static)

Key:
- Destination: Network prefix being routed to
- Gateway: Next hop (0.0.0.0 = directly connected)
- Interface: Which network interface to use
- Metric: Cost/preference (lower is better)
- Flags: U=Up, G=Gateway (not direct)

Longest Prefix Match

When multiple routes match a destination, routers use longest prefix matchβ€”the most specific route wins.

Longest Prefix Match

Longest Prefix Match:
═══════════════════════════════════════════════════════════════════

Routing Table:
10.0.0.0/8       via 192.168.1.1    (matches 16M addresses)
10.10.0.0/16     via 192.168.1.2    (matches 65K addresses)
10.10.10.0/24    via 192.168.1.3    (matches 256 addresses)

Packet destined for 10.10.10.50:
β”œβ”€β”€ Matches 10.0.0.0/8?  (but only /8)
β”œβ”€β”€ Matches 10.10.0.0/16?  (but only /16)
β”œβ”€β”€ Matches 10.10.10.0/24?  ← WINNER! (most specific, /24)
└── Forward to 192.168.1.3

Why this matters:
- More specific routes override less specific ones
- Default route (0.0.0.0/0) is least specific, used as fallback
- Attackers can hijack traffic by announcing more specific routes!

Now that we understand how a router uses its routing table, an important question arises: how does that routing table get populated in the first place? There are two fundamentally different approaches.


Static vs Dynamic Routing

Networks can be configured in two ways: you can manually tell each router exactly where to send traffic, or you can let routers figure it out automatically by talking to each other. Each approach has trade-offs that make it suitable for different situations.

Static Routing

In static routing, administrators manually configure routes. This is simple and predictable but doesn’t adapt to network changes.

# Add static route (Linux)
ip route add 10.0.0.0/8 via 192.168.1.254

# Add static route (Windows)
route add 10.0.0.0 mask 255.0.0.0 192.168.1.254

# Persistent route (Linux, in /etc/network/interfaces or netplan)
up ip route add 10.0.0.0/8 via 192.168.1.254
AdvantagesDisadvantages
Simple to understandDoesn’t adapt to failures
No protocol overheadDoesn’t scale well
Predictable behaviorAdministrative burden
Slightly more secureManual updates required

Use cases: Small networks, default routes, specific traffic engineering, security (forcing traffic paths)

Dynamic Routing

Dynamic routing protocols automatically discover network topology and calculate optimal paths. Routers exchange information with neighbors, building a network-wide view.

AdvantagesDisadvantages
Automatically adapts to failuresProtocol overhead (CPU, bandwidth)
Scales to large networksConvergence time during changes
Reduces administrative overheadPotential security issues

Most networks larger than a home or small office use dynamic routing. But dynamic routing isn’t one-size-fits-allβ€”different protocols exist for different purposes. The most fundamental distinction is between protocols used within an organization versus protocols used between organizations.


Interior Gateway Protocols (IGPs)

Interior Gateway Protocols route within a single organization (Autonomous System). When your company’s routers need to share information about which networks exist and how to reach them, they use an IGP.

Think of an IGP as the internal navigation system of a large building complexβ€”it helps you move between rooms and floors within the building, but it doesn’t concern itself with how to reach other buildings across the city.

Different IGPs use different strategies to share routing information. Understanding these strategies helps you appreciate why networks behave the way they doβ€”and where vulnerabilities might exist.

RIP (Routing Information Protocol)

RIP is one of the oldest routing protocols, using a distance-vector algorithm based on hop count. While rarely used in new deployments, understanding RIP illuminates how distance-vector protocols think.

Characteristics:

  • Metric = hop count (maximum 15; 16 = unreachable)
  • Shares full routing table with neighbors every 30 seconds
  • Simple but limited scalability
  • Slow convergence (minutes)

RIP Hop Count Example

RIP Hop Count Example:
═══════════════════════════════════════════════════════════════════

         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
Network ── Router Aβ”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ Router Bβ”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ Router Cβ”œβ”€ Network
   X     β”‚ Hops: 1 β”‚        β”‚ Hops: 2 β”‚        β”‚ Hops: 3 β”‚    Y
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

From Network X to Network Y: 3 hops
RIP chooses path with fewest hops (ignores bandwidth!)

Problem: 
Path A-B-C might be 10 Mbps each
Path A-D-E-F-C might be 1 Gbps each
RIP chooses slower path because fewer hops!

Versions:

  • RIPv1: Classful (no subnet mask in updates), broadcast
  • RIPv2: Classless (includes subnet mask), supports authentication, multicast

OSPF (Open Shortest Path First)

OSPF is a modern link-state protocol widely used in enterprise networks. It builds a complete map of the network topology.

OSPF Operation

OSPF Operation:
═══════════════════════════════════════════════════════════════════

1. NEIGHBOR DISCOVERY
   Routers send Hello packets on each interface
   Establish adjacencies with neighbors

2. DATABASE SYNCHRONIZATION
   Exchange Link-State Advertisements (LSAs)
   Each router builds complete topology database

3. SPF CALCULATION
   Dijkstra's algorithm calculates shortest paths
   Build routing table from SPF tree

4. ONGOING
   Monitor links for changes
   Flood LSA updates when topology changes
   Re-run SPF if needed

OSPF Topology Database (same on all routers):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Router A: Connected to B (cost 10), C (cost 5)                  β”‚
β”‚ Router B: Connected to A (cost 10), D (cost 20)                 β”‚
β”‚ Router C: Connected to A (cost 5), D (cost 15)                  β”‚
β”‚ Router D: Connected to B (cost 20), C (cost 15)                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SPF calculation finds shortest path from each router to all others

Key concepts:

  • Areas: OSPF divides networks into areas to limit LSA flooding
  • Area 0 (Backbone): All other areas must connect to Area 0
  • Router Types: Internal, ABR (Area Border Router), ASBR (AS Boundary Router)
  • Cost Metric: Based on bandwidth (configurable): 100 Mbps = cost 1, 10 Mbps = cost 10

OSPF security features:

  • MD5 authentication of OSPF messages (deprecated)
  • SHA-based authentication (OSPF cryptographic authentication)
  • However, within a compromised network, OSPF can still be manipulated

EIGRP (Enhanced Interior Gateway Routing Protocol)

Cisco-proprietary (though now partially open), EIGRP combines distance-vector and link-state features.

Characteristics:

  • Uses Diffusing Update Algorithm (DUAL)
  • Fast convergence (sub-second)
  • Supports unequal-cost load balancing
  • Lower overhead than OSPF for some topologies

IGP Comparison

FeatureRIPOSPFEIGRP
AlgorithmDistance-vectorLink-stateHybrid
MetricHop count (max 15)Cost (bandwidth)Composite
ConvergenceSlow (minutes)Fast (seconds)Very fast
ScalabilitySmall networksLarge networksLarge networks
UpdatesPeriodic (30s)Event-triggeredEvent-triggered
CPU/MemoryLowHigherMedium
VendorOpen standardOpen standardCisco (mostly)

IGPs handle routing within an organization, but the internet is made up of thousands of independent organizations, each running their own networks. How do these separate networks learn how to reach each other? That’s where BGP comes inβ€”the protocol that glues the entire internet together.


Exterior Gateway Protocol: BGP

If IGPs are the navigation systems inside individual buildings, BGP is the road map of an entire country. It’s how major networksβ€”ISPs, cloud providers, large enterprisesβ€”tell each other what parts of the internet they can reach. And as we saw in the opening story, it’s also one of the most critical security weak points on the internet.

The Internet’s Routing Protocol

BGP (Border Gateway Protocol) is how the internet works. It routes between Autonomous Systems (AS)β€”independent networks operated by different organizations (ISPs, large enterprises, content providers).

BGP is fundamentally different from IGPs:

  • Policy-based: Routes based on business relationships, not just shortest path
  • Path-vector: Announces complete AS paths, enabling loop detection
  • Incremental updates: Only changes are advertised, not full tables

BGP Peering Between Autonomous Systems

BGP Peering Between Autonomous Systems:
═══════════════════════════════════════════════════════════════════

            AS 65001                          AS 65002
         (Your Company)                     (ISP Alpha)
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚                       β”‚         β”‚                       β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚  eBGP   β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
    β”‚   β”‚ BGP Router  │─────┼─────────┼─────│ BGP Router  β”‚   β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚         β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
    β”‚         β”‚             β”‚         β”‚           β”‚           β”‚
    β”‚       iBGP            β”‚         β”‚         iBGP          β”‚
    β”‚         β”‚             β”‚         β”‚           β”‚           β”‚
    β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚         β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
    β”‚   β”‚ Internal    β”‚     β”‚         β”‚     β”‚ Internal    β”‚   β”‚
    β”‚   β”‚ Router      β”‚     β”‚         β”‚     β”‚ Router      β”‚   β”‚
    β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚         β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

eBGP: External BGP (between ASes) - typically one hop
iBGP: Internal BGP (within AS) - distributes external routes internally

BGP Path Selection

BGP uses multiple attributes to select the best path. Order of preference (simplified):

  1. Highest Weight (Cisco-specific, local preference)
  2. Highest LOCAL_PREF (prefer certain exit points)
  3. Locally originated routes
  4. Shortest AS_PATH (fewer ASes traversed)
  5. Lowest origin type (IGP < EGP < Incomplete)
  6. Lowest MED (Multi-Exit Discriminator)
  7. eBGP over iBGP
  8. Lowest IGP metric to next hop
  9. Oldest route (stability)
  10. Lowest router ID

BGP Security: A Critical Weakness

BGP fundamentally trusts what peers announce. This trust model creates serious vulnerabilities:

BGP Hijacking Example

BGP Hijacking Example:
═══════════════════════════════════════════════════════════════════

NORMAL OPERATION:
─────────────────
AS 65001 legitimately owns 203.0.113.0/24
Announces: "I can reach 203.0.113.0/24"
Internet routes traffic to AS 65001 

BGP HIJACK ATTACK:
──────────────────
Attacker (AS 99999) announces: "I can reach 203.0.113.0/24"

Other ASes now have two routes:
β”œβ”€β”€ Via AS 65001 (legitimate)
└── Via AS 99999 (attacker)

If AS 99999 appears to be a shorter/better path...
Traffic gets redirected to attacker!

WORSE - MORE SPECIFIC PREFIX ATTACK:
────────────────────────────────────
Legitimate: 203.0.113.0/24
Attacker announces: 203.0.113.0/25 AND 203.0.113.128/25

More specific prefixes ALWAYS win (longest prefix match)!
ALL traffic now goes to attacker, regardless of path length.

Real-world BGP incidents:

YearIncidentImpact
2008Pakistan Telecom hijacked YouTubeGlobal YouTube outage
2017Russia hijacked Google/Apple/Facebook brieflyTraffic routed through Russia
2018Attacker hijacked AWS Route 53 for crypto theft$150K stolen
2019China Telecom hijacked European trafficTraffic rerouted through China
2020Rostelecom hijacked 200+ prefixesMajor websites affected

BGP Security Solutions

RPKI (Resource Public Key Infrastructure):

RPKI provides cryptographic verification of route origins. Route Origin Authorizations (ROAs) are signed statements that AS X is authorized to originate prefix Y.

RPKI Route Origin Validation

RPKI Route Origin Validation:
═══════════════════════════════════════════════════════════════════

ROA Record (cryptographically signed):
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Prefix: 203.0.113.0/24                                          β”‚
β”‚ Max Length: /24                                                 β”‚
β”‚ Origin AS: 65001                                                β”‚
β”‚ Signature: [Verified by Regional Internet Registry]            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

When router receives BGP announcement:
1. Check: Is there an ROA for this prefix?
2. Check: Does announcing AS match ROA?
3. Check: Is prefix length within max-length?

Results:
- VALID: ROA exists and matches β†’ Accept
- INVALID: ROA exists but doesn't match β†’ REJECT!
- NOT FOUND: No ROA exists β†’ Accept (for now, transitional)

Other BGP security measures:

  • Prefix filtering: Validate announcements against IRR databases
  • BGPsec: Full path validation (not widely deployed yet)
  • Monitoring services: Detect suspicious announcements (BGPStream, RIPE RIS)
  • Peer agreements: Contractual requirements for filtering

Security Note: BGP hijacking is covered in Part II, Chapter 3. At scale, it can intercept traffic for millions of users.


Network Address Translation (NAT)

We’ve covered how routing moves packets across the internet, but there’s a problem we’ve glossed over: IP addresses are a limited resource. The internet was designed when no one imagined billions of connected devices. How do we make it work?

The answer is NATβ€”a technique that lets many devices share a single public IP address. If you’re reading this at home, your laptop, phone, smart TV, and IoT devices probably all share one public IP address from your ISP. NAT makes this possible.

Understanding NAT is essential because it’s everywhereβ€”and because it’s often confused with security (it isn’t).

The IPv4 Address Crisis Solution

With only 4.3 billion IPv4 addresses and billions of internet-connected devices, we ran out of public addresses. NAT (Network Address Translation) extends IPv4’s life by allowing many devices to share a single public IP address.

How NAT Works

NAT modifies IP addresses (and sometimes ports) as packets traverse a router.

NAT Translation (PAT/NAPT Most Common)

NAT Translation (PAT/NAPT - Most Common):
═══════════════════════════════════════════════════════════════════

OUTBOUND (Private β†’ Public):
────────────────────────────

Device A: 192.168.1.100:5000 β†’ google.com:443
Device B: 192.168.1.101:5001 β†’ google.com:443

        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚   NAT Router     β”‚
        β”‚   Public: 1.2.3.4β”‚
        β”‚   NAT Table:     β”‚
        β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
        β”‚ β”‚Int    β”‚Ext   β”‚ β”‚
        β”‚ β”‚.100:50β”‚:30001β”‚ β”‚
        β”‚ β”‚.101:50β”‚:30002β”‚ β”‚
        β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

After NAT:
Device A appears as: 1.2.3.4:30001 β†’ google.com:443
Device B appears as: 1.2.3.4:30002 β†’ google.com:443

INBOUND (Public β†’ Private):
───────────────────────────

Response to 1.2.3.4:30001 β†’ Translated to 192.168.1.100:5000
Response to 1.2.3.4:30002 β†’ Translated to 192.168.1.101:5001

Router maintains NAT translation table to match responses!

NAT Types

TypeDescriptionUse Case
Static NAT1:1 mapping (public ↔ private)Servers needing inbound access
Dynamic NATPool of public IPs assigned as neededUncommon now
PAT/NAPTMany private IPs share one public IP using portsMost common (home routers)
Carrier-Grade NATISP does NAT for customersIPv4 exhaustion workaround

Port Forwarding

NAT breaks the end-to-end modelβ€”external hosts can’t initiate connections to internal hosts. Port forwarding creates exceptions:

Port Forwarding Configuration

Port Forwarding Configuration:
═══════════════════════════════════════════════════════════════════

NAT Router (Public IP: 1.2.3.4)
Port Forward Rules:
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ External Port β”‚ Internal IP      β”‚ Internal Port β”‚ Protocol   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 80            β”‚ 192.168.1.10     β”‚ 80            β”‚ TCP        β”‚
β”‚ 443           β”‚ 192.168.1.10     β”‚ 443           β”‚ TCP        β”‚
β”‚ 22            β”‚ 192.168.1.20     β”‚ 22            β”‚ TCP        β”‚
β”‚ 25565         β”‚ 192.168.1.30     β”‚ 25565         β”‚ TCP        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

External request to 1.2.3.4:80 β†’ Forwarded to 192.168.1.10:80
External request to 1.2.3.4:22 β†’ Forwarded to 192.168.1.20:22

NAT Security Implications

BenefitsDrawbacks
Hides internal network structureBreaks some protocols (SIP, FTP)
Implicit firewall (inbound blocked by default)Complicates logging/forensics
Conserves public IP addressesNot actual security (just obscurity)
Can’t directly attack internal hostsMakes peer-to-peer difficult

** COMMON MISTAKE**

NAT is not a firewall and not a security measure. It provides obscurity, not protection. A compromised internal host behind NAT can still be controlled by an attacker via outbound connections. Always use proper firewalls.


SD-WAN: Software-Defined Wide Area Network

So far, we’ve discussed how routing works at a protocol level. But how do organizations actually connect their offices, data centers, and cloud resources? Traditionally, this meant expensive dedicated circuits. But the rise of cheap internet bandwidth and sophisticated software has created a new option: SD-WAN.

SD-WAN represents a major shift in enterprise networking, and understanding it helps you appreciate how modern networks are architectedβ€”and where new security considerations arise.

Traditional WAN Challenges

Traditional enterprise WANs use expensive MPLS circuits for reliable connectivity between sites. As cloud applications grew, traffic patterns changedβ€”users needed internet access, not just data center access.

SD-WAN abstracts WAN connectivity, using multiple transport types (MPLS, broadband, LTE) intelligently.

Traditional WAN vs SDWAN

Traditional WAN vs SD-WAN:
═══════════════════════════════════════════════════════════════════

TRADITIONAL WAN:
────────────────
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    MPLS      β”‚  Data      β”‚
Branch A ─────────────────────│  Center    β”‚
              (Expensive)     β”‚            β”‚
Branch B ─────────────────────│  All       β”‚
              (Single path)   β”‚  Traffic   β”‚
Branch C ─────────────────────│  Backhauledβ”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Cloud apps? Traffic goes: Branch β†’ Data Center β†’ Internet β†’ Cloud
                         (Inefficient "trombone" routing)


SD-WAN:
───────
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              MPLS (critical) β”‚  Data    β”‚
Branch A ─────────────────────│  Center  β”‚
         β•²   Broadband        β”‚          β”‚
          β•²  (bulk traffic)   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β•²
            β•²   Direct to cloud!
             β•²  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β•² β”‚  Cloud   β”‚
               β•²β”‚  Apps    β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

SD-WAN controller decides best path per application!

SD-WAN benefits:

  • Use cheaper internet links alongside MPLS
  • Direct cloud access (no backhaul)
  • Application-aware routing
  • Centralized management
  • Built-in encryption across links

SD-WAN security considerations:

  • Encryption quality varies by vendor
  • Direct internet access bypasses data center security
  • Need cloud-based security (SASE) or branch firewalls
  • Controller becomes single point of compromise

Firewalls and Access Control

Throughout this chapter, we’ve discussed how routers move traffic based on destination addresses. But what about controlling which traffic is allowed to flow in the first place? This is the job of firewallsβ€”the gatekeepers of network security.

While not strictly a routing topic, firewalls are so integral to network infrastructure that we need to cover them here. Every network professional needs to understand how firewall rules work and the critical importance of rule ordering.

Firewall Basics

A firewall controls network traffic based on defined rules. It examines packets and decides to allow, block, or log them.

Firewall Types

TypeOSI LayersCapabilitiesPerformance
Packet Filter3-4IP/port filtering, statelessFast
Stateful3-4Track connection stateFast
Application/Proxy7Deep content inspectionSlower
Next-Gen (NGFW)3-7IPS, AV, app awareness, SSL inspectionVaries

Firewall Rules

Rules are evaluated in order; first match wins:

Firewall Rule Examples

Firewall Rule Examples:
═══════════════════════════════════════════════════════════════════

Rule#  Action   Proto  Source           Dest           Port   Notes
─────  ──────   ─────  ──────           ────           ────   ─────
1      ALLOW    TCP    any              10.0.0.5       22     SSH to jump
2      ALLOW    TCP    any              10.0.0.10      443    HTTPS to web
3      ALLOW    TCP    10.0.0.0/24      any            any    LAN outbound
4      ALLOW    UDP    any              any            53     DNS allowed
5      ALLOW    TCP    any              any            80,443 Web allowed
6      DENY     TCP    any              any            25     Block SMTP
7      DENY     any    any              any            any    Default deny

IMPORTANT: Order matters!
- Rule 3 allows LAN to any port
- Rule 6 blocks SMTP
- If someone from LAN tries SMTP, Rule 3 matches first β†’ ALLOWED!
- Should move Rule 6 BEFORE Rule 3

Stateful firewall understands:
- If outbound connection allowed, related inbound responses allowed
- Tracks TCP state (SYN, ESTABLISHED, etc.)
- Can allow "ESTABLISHED,RELATED" for responses without explicit rule

Common firewall approaches:

  • Default deny: Block everything, explicitly allow what’s needed (more secure)
  • Default allow: Allow everything, explicitly block what’s dangerous (easier but risky)

PRO TIP

When troubleshooting firewall issues, check rules in order. The most common mistake is having a broad β€œallow” rule before a specific β€œdeny” rule you expected to block traffic.


Practical Commands

# View routing table
ip route                    # Linux
netstat -rn                 # macOS, older Linux
route print                 # Windows

# Add/delete routes
ip route add 10.0.0.0/8 via 192.168.1.254        # Linux
ip route del 10.0.0.0/8                           # Linux
route add 10.0.0.0 mask 255.0.0.0 192.168.1.254  # Windows

# Trace route through internet
traceroute -A google.com    # Show AS numbers
mtr google.com              # Combined ping+traceroute

# Check BGP routes (requires looking glass or BGP router)
# Public BGP looking glasses: https://www.bgp4.as/looking-glasses
# Hurricane Electric: https://lg.he.net/

# Check if IP has valid RPKI ROA
# https://rpki-validator.ripe.net/
# Or use bgp.tools, e.g., https://bgp.tools/prefix/8.8.8.0/24

# View NAT translations (Linux)
conntrack -L                # Connection tracking table
iptables -t nat -L -n -v    # NAT rules

# Firewall rules
iptables -L -n -v           # Linux
pfctl -sr                   # macOS/BSD
netsh advfirewall show allprofiles  # Windows

TRY IT YOURSELF

See the AS path to a destination:

traceroute -A google.com

Each line shows the AS number. You can look up AS owners at bgp.tools or peeringdb.com.


Key Takeaways

  1. Routing tables map destinations to next hops; longest prefix match determines which route is used

  2. Static routing is simple but doesn’t adapt; dynamic routing automatically handles failures but adds complexity

  3. IGPs (RIP, OSPF, EIGRP) route within organizations using different algorithms and metrics

  4. BGP routes between autonomous systems and is the critical internet infrastructureβ€”built on trust with significant security implications

  5. RPKI provides cryptographic verification of route origins, helping prevent BGP hijacking

  6. NAT allows address sharing but provides obscurity, not security

  7. SD-WAN modernizes enterprise WANs with software-defined intelligence across multiple transport types

  8. Firewalls enforce access control; rule order matters, and default-deny is more secure


Self-Assessment

  1. Comprehension: Why does longest prefix match make BGP hijacking with more-specific prefixes so effective?

  2. Application: An organization has both MPLS and internet circuits to each branch. How would SD-WAN help them use both effectively?

  3. What if: If RPKI were universally deployed and enforced, what BGP attacks would still be possible?


Review Questions

  1. What is the difference between static and dynamic routing?
  2. How does OSPF differ from RIP in its approach to routing?
  3. What is BGP hijacking, and why is it possible?
  4. How does RPKI help secure BGP, and what are its limitations?
  5. How does NAT allow many devices to share one public IP?
  6. Why is NAT not considered a security measure?

Key RFCs

  • RFC 4271 - A Border Gateway Protocol 4 (BGP-4)
  • RFC 6480 - An Infrastructure to Support RPKI
  • RFC 6811 - BGP Prefix Origin Validation
  • RFC 2328 - OSPF Version 2
  • RFC 2453 - RIP Version 2
  • RFC 3022 - Traditional IP Network Address Translator (NAT)