Tutorials Logic, IN info@tutorialslogic.com

Network Routing Static, OSPF, BGP, NAT

What is Routing?

Routing is the process of selecting the best path for data packets to travel from source to destination across one or more networks. Routers use routing tables to make forwarding decisions based on destination IP addresses.

Static vs Dynamic Routing

Feature Static Routing Dynamic Routing
Configuration Manually configured by admin Automatically learned via routing protocols
Adaptability Does not adapt to network changes Adapts automatically to topology changes
Overhead No routing protocol overhead Routing protocol traffic overhead
Scalability Poor (manual updates needed) Excellent
Security More secure (no protocol to exploit) Less secure (routing updates can be spoofed)
Use Case Small networks, stub networks, default routes Large, complex networks

Dynamic Routing Protocols

IGP = Interior Gateway Protocol (within an autonomous system) | EGP = Exterior Gateway Protocol (between autonomous systems)

Protocol Type Algorithm Use Case
RIP IGP, Distance Vector Bellman-Ford Small networks (max 15 hops)
OSPF IGP, Link State Dijkstra (SPF) Large enterprise networks
EIGRP IGP, Hybrid DUAL Cisco networks
BGP EGP, Path Vector Best Path Selection Internet backbone, ISPs
IS-IS IGP, Link State Dijkstra Large ISP networks

Distance Vector vs Link State

Feature Distance Vector Link State
Knowledge Only knows neighbors and distances Complete topology map
Updates Periodic full table updates to neighbors Triggered updates (LSAs) flooded to all
Convergence Slow Fast
Memory/CPU Low High
Loops Prone to routing loops Loop-free (SPF algorithm)
Examples RIP, IGRP OSPF, IS-IS

NAT - Network Address Translation

NAT allows multiple devices on a private network to share a single public IP address. It translates private IP addresses to public IP addresses and vice versa.

  • SNAT (Source NAT): Translates the source IP address. Used when private hosts access the Internet. The router replaces the private source IP with its public IP.
  • DNAT (Destination NAT): Translates the destination IP address. Used for port forwarding - incoming traffic to a public IP is redirected to a private server.
  • PAT (Port Address Translation) / NAT Overload: Maps multiple private IPs to a single public IP using different port numbers. Most common form of NAT in home routers.

Default Gateway

The default gateway is the router that a device uses to send traffic to destinations outside its local network. When a device doesn't have a specific route for a destination, it sends the packet to the default gateway.

Example: If your PC has IP 192.168.1.100/24 and default gateway 192.168.1.1, all traffic to non-192.168.1.x addresses goes to 192.168.1.1 (your router).

Apply Longest-Prefix Match

Apply Longest-Prefix Match
from ipaddress import ip_address, ip_network

routes = [
    (ip_network('0.0.0.0/0'), 'wan'),
    (ip_network('10.0.0.0/8'), 'corp'),
    (ip_network('10.24.0.0/16'), 'engineering'),
]
destination = ip_address('10.24.8.9')
matching = [(network, hop) for network, hop in routes if destination in network]
network, hop = max(matching, key=lambda route: route[0].prefixlen)
print(network, hop)
Output
10.24.0.0/16 engineering

Diagnose a Missing Return Route

Diagnose a Missing Return Route
Forward path: branch 10.30.0.0/16 -> core -> service 172.20.4.10
Observed: request reaches the service, but no reply reaches the branch.
Check: the service gateway has no route for 10.30.0.0/16.
Correction: advertise or add the return route, then verify both directions without relying on NAT as a guess.

A successful outbound trace does not establish that the reverse path is routable.

Before you move on

Network Routing Static, OSPF, BGP, NAT Mastery Check

4 checks
  • Routing is the process of selecting the best path for data packets to travel from source to destination across one or more networks.
  • Routers use routing tables to make forwarding decisions based on destination IP addresses.
  • NAT allows multiple devices on a private network to share a single public IP address.
  • It translates private IP addresses to public IP addresses and vice versa.

Networking Questions Learners Ask

Routers first choose the longest matching prefix because it describes the destination most precisely. Metrics compare candidate routes to the same prefix learned through different paths or protocols.

Routing decisions are made independently in each direction. The destination network may lack a route back to the source, use another gateway, or send replies through a firewall that has no session state.

Static routes work well for small, stable paths and defaults. As links, sites, and redundant paths grow, manual updates become slow and error-prone, and failures do not automatically advertise new paths.

Browse Free Tutorials

Explore 500+ free tutorials across 20+ languages and frameworks.