Định tuyến (Routing)Routing
Thuộc bộ kiến thức Network Engineer Roadmap.
Tổng quan
Routing là quá trình chọn đường đi cho traffic từ một mạng nguồn tới một mạng đích, đi qua một hoặc nhiều thiết bị trung gian. Trong khi switching di chuyển frame bên trong một broadcast domain Layer 2 dựa trên địa chỉ MAC, thì routing di chuyển packet giữa các mạng Layer 3 (các IP subnet) dựa trên địa chỉ IP. Thiết bị làm nhiệm vụ này là router: nó nhận packet trên một interface, quyết định packet nên đi tiếp về đâu, rồi forward ra một interface khác — lặp đi lặp lại, từng hop một, cho tới khi packet đến đích.
Bản chất của internet là một bài toán routing khổng lồ. Không có một tấm bản đồ duy nhất mô tả toàn bộ mạng; thay vào đó, hàng trăm nghìn router mỗi cái nắm một phần thông tin và phối hợp với nhau — thông qua các routing protocol — để dựng lên một tập đường đi nhất quán và không loop. Một packet rời laptop của bạn để tới server ở nửa kia địa cầu có thể đi qua 15–25 router, mỗi router tự đưa ra quyết định forward độc lập trong vài microsecond dựa hoàn toàn vào routing table cục bộ của nó.
Mỗi quyết định routing đều xoay quanh hai câu hỏi:
- Đích nằm ở đâu? Router so sánh địa chỉ IP đích của packet với các entry trong routing table (xem IP addressing và subnetting để hiểu cách địa chỉ và prefix hoạt động).
- Làm sao để tới đó? Entry khớp sẽ cho router biết địa chỉ next-hop và/hoặc interface đi ra.
Ghi chú này trình bày cách routing table hoạt động, sự khác nhau giữa static và dynamic routing, các họ routing protocol chính (distance-vector, link-state, path-vector), các protocol cụ thể bạn sẽ gặp trong thực tế (RIP, OSPF, EIGRP, BGP), và các công nghệ xây dựng trên nền routing (MPLS, VRF, và cloud route table).
Kiến thức nền tảng
Routing table
Mỗi router (và cả mỗi host — laptop của bạn cũng có) duy trì một routing table: một danh sách có thứ tự các mạng đích đã biết và cách tới từng mạng. Khi một packet đến, router tra bảng này để quyết định next-hop. Một entry tối thiểu gồm:
- Destination prefix — một mạng cùng mask của nó, ví dụ
10.1.2.0/24. - Next-hop — địa chỉ IP của router kế cận để forward tới, ví dụ
192.0.2.1. - Interface đi ra — interface cục bộ mà packet rời khỏi, ví dụ
GigabitEthernet0/1. - Metric — thước đo độ “tốt” của route (thấp hơn là tốt hơn).
- Administrative distance — mức độ tin cậy của nguồn sinh ra route (thấp hơn là đáng tin hơn).
Bạn có thể xem trực tiếp:
# Linux
$ ip route show
default via 192.168.1.1 dev eth0 proto dhcp metric 100
10.10.0.0/16 via 192.168.1.254 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.50
! Cisco IOS
Router# show ip route
Codes: C - connected, S - static, R - RIP, O - OSPF, D - EIGRP, B - BGP
* - candidate default
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
O 10.10.0.0/16 [110/20] via 192.168.1.254, 00:15:22, GigabitEthernet0/0
S* 0.0.0.0/0 [1/0] via 192.168.1.1
Trong output Cisco, chữ cái ở cột trái là nguồn của route (C connected, O OSPF, S static). Cặp trong ngoặc [110/20] là [administrative distance / metric].
Longest-prefix match
Một IP đích có thể khớp cùng lúc nhiều entry trong routing table. Ví dụ, packet đi tới 10.1.2.5 có thể khớp tất cả các entry sau:
| Entry | Độ dài prefix | Khớp 10.1.2.5? |
|---|---|---|
0.0.0.0/0 (default) | 0 | có |
10.0.0.0/8 | 8 | có |
10.1.0.0/16 | 16 | có |
10.1.2.0/24 | 24 | có |
Router luôn chọn entry cụ thể nhất — entry có prefix dài nhất (mask lớn nhất). Ở đây nó chọn 10.1.2.0/24. Đây là quy tắc forward nền tảng: longest-prefix match thắng. Nhờ đó router có thể mang một default route 0.0.0.0/0 làm “bắt tất cả”, đồng thời ghi đè nó bằng các route cụ thể hơn cho từng đích riêng.
Directly connected và remote network
- Mạng directly connected là các subnet nằm ngay trên interface của router. Khi bạn gán
192.168.1.1/24cho một interface và bật nó lên, router tự động cài một connected route (C) cho192.168.1.0/24. Không cần protocol nào — router tới được các host đó trực tiếp qua Layer 2. - Mạng remote là mọi thứ còn lại: các subnet chỉ tới được thông qua một router khác. Router học các route này hoặc từ con người (static route) hoặc từ routing protocol (dynamic route), và mỗi remote route trỏ tới một next-hop — router kế cận để chuyển packet tới.
Về bản chất, forward mang tính đệ quy: “để tới mạng X, gửi tới next-hop Y” — và bản thân router phải biết cách tới Y (thường vì Y nằm trên một subnet directly connected).
Administrative distance (AD)
Router có thể học cùng một đích từ nhiều nguồn — ví dụ một static route và OSPF và RIP cùng mô tả 10.10.0.0/16. Router không thể cài các entry mâu thuẫn, nên phải chọn một. Administrative distance xếp hạng mức độ tin cậy của nguồn, độc lập với metric. AD thấp hơn thắng. Chỉ sau khi AD đã chọn được nguồn thì metric của protocol mới dùng để phân định giữa các route cùng nguồn đó.
| Nguồn route | AD mặc định (Cisco) |
|---|---|
| Connected interface | 0 |
| Static route | 1 |
| eBGP (external BGP) | 20 |
| EIGRP (internal) | 90 |
| OSPF | 110 |
| RIP | 120 |
| iBGP (internal BGP) | 200 |
| Không tới được / floating dự phòng | 255 (không bao giờ cài) |
Vì vậy một static route (AD 1) luôn thắng một route học từ OSPF (AD 110) cho cùng prefix, bất kể metric — vì bạn, người vận hành, được coi là biết rõ nhất.
Metric
Metric là giá trị mà một routing protocol dùng để so sánh các đường ứng viên của chính nó tới cùng một đích và chọn ra đường tốt nhất. Thấp hơn là tốt hơn. Mỗi protocol đo “tốt nhất” theo cách khác nhau:
- RIP — hop count (số router phải đi qua).
- OSPF — cost, suy ra từ bandwidth của interface.
- EIGRP — tổng hợp của bandwidth và delay (mặc định).
- BGP — không có một metric số đơn lẻ; nó chạy một thuật toán chọn đường nhiều bước dựa trên các attribute.
Control plane và data plane
- Control plane dựng nên routing table: chạy các routing protocol, trao đổi update với neighbor, và tính toán các đường tốt nhất. Đây là phần “suy nghĩ”.
- Data plane (hay forwarding plane) thực sự di chuyển packet. Router hiện đại biên dịch routing table (RIB — Routing Information Base) thành một forwarding table (FIB) đã tối ưu, thường nằm trong phần cứng (Cisco gọi là CEF — Cisco Express Forwarding), để packet được chuyển ở tốc độ line-rate mà không phải chạy lại toàn bộ logic routing cho từng packet.
Khái niệm chính
Static routing
Static route là route bạn cấu hình bằng tay. Router không tự học, không tự thích nghi, cũng không tự rút nó — route tồn tại cho tới khi bạn xóa.
! Cisco IOS — tới 10.20.0.0/16 qua next-hop 192.0.2.2
Router(config)# ip route 10.20.0.0 255.255.0.0 192.0.2.2
! Default route — "mọi thứ còn lại" đi tới gateway của ISP
Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1
# Tương đương trên Linux
$ sudo ip route add 10.20.0.0/16 via 192.0.2.2
$ sudo ip route add default via 203.0.113.1
Default route (0.0.0.0/0, “quad-zero”) là entry longest-prefix cuối cùng dùng làm phương án dự phòng: nó khớp với mọi đích không được entry cụ thể hơn bao phủ. Các stub network và host thường chỉ mang đúng một default route trỏ về gateway của mình (“default gateway”), thay vì mang cả bảng đầy đủ.
Ưu điểm: không tốn overhead protocol, không tốn CPU/bandwidth cho update, hoàn toàn dự đoán được, an toàn hơn (không có route bị neighbor “tiêm” vào), và kiểm soát đường đi chính xác. Nhược điểm: không scale (mọi route trên mọi router phải nhập tay), không tự failover trừ khi kết hợp với tracking (ví dụ một floating static route có AD cao làm dự phòng), và dễ sai trong topology lớn hoặc hay thay đổi.
Khi nào dùng: mạng nhỏ, stub site có một lối ra duy nhất, default route hướng về ISP, và làm dự phòng. Dưới đây là một floating static route — nó chỉ được cài (AD 130) khi đường chính (học qua OSPF, AD 110) biến mất:
! Đường chính học qua OSPF (AD 110); backup này chỉ cài khi route OSPF mất
Router(config)# ip route 10.20.0.0 255.255.0.0 198.51.100.2 130
Dynamic routing
Dynamic routing dùng một routing protocol để router tự động khám phá các mạng, chia sẻ những gì mình biết cho neighbor, và tính lại đường khi topology thay đổi (một link chết, một router reboot). Thời gian để tất cả router cùng đồng thuận về một góc nhìn nhất quán mới sau một thay đổi gọi là convergence — một chỉ số chất lượng then chốt của mọi protocol.
Ưu điểm: scale được cho mạng lớn, tự thích nghi với sự cố, ít việc thủ công. Nhược điểm: tốn CPU, memory và bandwidth; tăng độ phức tạp; và cần bảo vệ protocol trước các update sai hoặc độc hại.
Distance-vector và link-state
Hai họ IGP kinh điển khác nhau căn bản ở cái gì được chia sẻ và cách tính đường.
| Khía cạnh | Distance-vector | Link-state |
|---|---|---|
| Mỗi router biết gì | Chỉ biết khoảng cách/hướng do neighbor báo (“routing theo tin đồn”) | Toàn bộ bản đồ topology của area |
| Quảng bá cái gì | Toàn bộ routing table của mình, cho neighbor trực tiếp | Các link của chính nó (LSA), flood tới mọi router trong area |
| Thuật toán | Bellman-Ford | Dijkstra (SPF — Shortest Path First) |
| Convergence | Chậm hơn; nguy cơ loop và count-to-infinity | Nhanh hơn; mỗi router tự tính độc lập |
| Tài nguyên | CPU/memory thấp | CPU/memory cao hơn (giữ cả topology) |
| Ví dụ | RIP, EIGRP (nâng cao) | OSPF, IS-IS |
Router distance-vector tin vào bản tóm tắt của neighbor; router link-state tự dựng bức tranh đầy đủ của mình và chạy Dijkstra để tìm đường ngắn nhất, nhờ đó tránh được hầu hết vấn đề loop và converge nhanh hơn.
IGP và EGP
- IGP (Interior Gateway Protocol) — chạy bên trong một autonomous system (AS), tức một mạng dưới một quyền quản trị duy nhất. Tối ưu cho convergence nhanh và đường nội bộ tốt nhất. Ví dụ: OSPF, IS-IS, EIGRP, RIP.
- EGP (Exterior Gateway Protocol) — chạy giữa các autonomous system. Tối ưu cho policy, khả năng scale và tính ổn định hơn là tốc độ thô. EGP duy nhất còn dùng thực tế hiện nay là BGP.
Một autonomous system được định danh bằng một AS number (ASN) — một số duy nhất toàn cầu (16-bit 1–65535, hoặc 32-bit) cấp bởi registry khu vực (ví dụ AS15169 là Google). ISP của bạn có ASN; các doanh nghiệp lớn có multi-home cũng có.
RIP — Routing Information Protocol
RIP là routing protocol động cổ và đơn giản nhất — một IGP distance-vector thuần túy.
- Metric: chỉ có hop count. Mỗi router cộng thêm 1.
- Tối đa: 15 hop; 16 = không tới được (vô cực). Giới hạn cố tình nhỏ này hạn chế mức scale của RIP và giúp chặn bớt vấn đề count-to-infinity.
- Update: broadcast/multicast toàn bộ bảng theo chu kỳ mỗi 30 giây.
- Phiên bản: RIPv1 (classful, không kèm mask trong update — lỗi thời), RIPv2 (classless/VLSM, multicast 224.0.0.9, hỗ trợ authentication), RIPng (cho IPv6).
Router(config)# router rip
Router(config-router)# version 2
Router(config-router)# no auto-summary
Router(config-router)# network 192.168.1.0
Router(config-router)# network 10.0.0.0
Hạn chế: trần 15 hop, convergence chậm, và metric hop count bỏ qua bandwidth (một đường 10 Gbps qua 3 hop lại thua đường 1 Mbps qua 2 hop). RIP chủ yếu chỉ còn tồn tại trong lab, mạng cực nhỏ, và thiết bị legacy. Các cơ chế chống loop mà nó dựa vào: split horizon, route poisoning, poison reverse, và hold-down timer.
OSPF — Open Shortest Path First
OSPF là IGP link-state chuẩn mở phổ biến nhất (RFC 2328 cho OSPFv2/IPv4, RFC 5340 cho OSPFv3/IPv6). Mọi router dựng một Link-State Database (LSDB) giống hệt nhau mô tả topology, rồi chạy thuật toán SPF của Dijkstra để tính cây đường ngắn nhất tới mọi đích.
Cách hoạt động:
- Router khám phá neighbor và hình thành adjacency bằng gói Hello.
- Mỗi router mô tả các link của mình trong các LSA (Link-State Advertisement) và flood chúng tới mọi router trong area.
- Mọi router ghép các LSA lại thành một LSDB giống hệt nhau.
- Mỗi router độc lập chạy SPF để dựng routing table của mình.
Cost (metric): cost của OSPF là reference-bandwidth / interface-bandwidth. Với reference mặc định 100 Mbps, link 100 Mbps = cost 1, link 10 Mbps = cost 10. Trên mạng hiện đại bạn nên tăng reference bandwidth (ví dụ lên 100000 cho 100 Gbps) để các link nhanh được phân biệt.
Area: OSPF scale bằng cách chia một domain lớn thành các area, tất cả nối vào một backbone area 0 trung tâm. Việc flood LSA được giới hạn trong một area; Area Border Router (ABR) tóm tắt route giữa các area. Nhờ đó LSDB nhỏ và SPF chạy nhẹ. Các loại area đặc biệt (stub, totally stubby, NSSA) còn giảm thêm số LSA đưa vào các area rìa.
DR/BDR: Trên một segment multi-access (như Ethernet có nhiều router) OSPF bầu một Designated Router (DR) và Backup DR (BDR) để tránh việc mọi router phải hình thành full-mesh adjacency. Mọi router chỉ hình thành adjacency với DR/BDR, giảm việc flood LSA từ O(n²) xuống O(n). Bầu chọn theo OSPF priority cao nhất, rồi tới Router ID cao nhất.
Convergence: nhanh — thường dưới một giây tới vài giây — vì mỗi router đã giữ sẵn toàn bộ topology và chỉ cần chạy lại SPF khi một LSA thay đổi.
! Cisco IOS — OSPF một area
Router(config)# router ospf 1
Router(config-router)# router-id 1.1.1.1
Router(config-router)# auto-cost reference-bandwidth 100000
Router(config-router)# network 192.168.1.0 0.0.0.255 area 0
Router(config-router)# network 10.1.0.0 0.0.255.255 area 0
Router(config-router)# passive-interface GigabitEthernet0/2
!
! Kiểm tra
Router# show ip ospf neighbor
Router# show ip route ospf
Lưu ý wildcard mask (0.0.0.255, đảo ngược của subnet mask) và việc gán area tường minh. passive-interface dừng gửi Hello của OSPF trên các interface hướng về host (nơi không có router), giúp tăng bảo mật và giảm nhiễu.
EIGRP — Enhanced Interior Gateway Routing Protocol
EIGRP là protocol distance-vector nâng cao của Cisco (đã mở thành RFC 7868 dạng informational). Nó hành xử như distance-vector (học từ neighbor, không giữ topology đầy đủ) nhưng bổ sung tốc độ và tính không-loop kiểu link-state nhờ DUAL (Diffusing Update Algorithm).
- Metric: tổng hợp, mặc định dùng bandwidth và delay (tùy chọn thêm load và reliability). Nhờ đó nó nhận biết được bandwidth, khác với RIP.
- Neighbor: hình thành adjacency bằng gói Hello; gửi update tăng dần (incremental) và có độ tin cậy, chỉ khi có gì đó thay đổi — không phải dump toàn bảng theo chu kỳ.
- Các thuật ngữ DUAL:
- Successor — next-hop tốt nhất hiện tại (metric thấp nhất, không loop); được cài vào routing table.
- Feasible successor — một next-hop dự phòng không-loop được tính sẵn. Nếu successor chết mà có feasible successor, EIGRP chuyển sang nó ngay lập tức (không cần tính lại), cho convergence rất nhanh.
- Feasibility condition — một neighbor chỉ đủ tư cách làm feasible successor nếu reported distance của nó tới đích nhỏ hơn tổng distance của successor hiện tại, điều này đảm bảo không tạo loop.
! Cisco IOS — cấu hình named EIGRP
Router(config)# router eigrp CORP
Router(config-router)# address-family ipv4 unicast autonomous-system 100
Router(config-router-af)# network 192.168.1.0 0.0.0.255
Router(config-router-af)# network 10.1.0.0 0.0.255.255
!
Router# show ip eigrp neighbors
Router# show ip eigrp topology
EIGRP converge rất nhanh khi có feasible successor và cấu hình đơn giản hơn OSPF, nhưng (về mặt lịch sử) gắn với Cisco, nên phổ biến trong doanh nghiệp toàn Cisco và hiếm gặp ở môi trường đa hãng hoặc core của nhà cung cấp dịch vụ.
BGP — Border Gateway Protocol
BGP (phiên bản 4, RFC 4271) là routing protocol của internet — EGP duy nhất còn dùng. Nó là protocol path-vector: thay vì một metric đơn giản, nó quảng bá cả AS-path (danh sách các autonomous system mà một route đi qua), vừa cho phép làm policy vừa chống loop (một router loại bỏ mọi route có AS-path đã chứa ASN của chính nó).
eBGP và iBGP:
| eBGP (external) | iBGP (internal) | |
|---|---|---|
| Peer | Giữa các AS khác nhau | Trong cùng một AS |
| TTL | Thường trực tiếp kề nhau (TTL 1) | Bất kỳ đâu trong AS |
| AS-path | Prepend ASN của mình khi quảng bá | Không đổi AS-path |
| AD mặc định (Cisco) | 20 | 200 |
| Hành vi next-hop | Đặt next-hop là chính nó | Giữ nguyên next-hop (thường cần next-hop-self) |
| Chống loop | AS-path | Quy tắc split-horizon → cần full mesh hoặc route reflector |
Vì iBGP không quảng bá lại route học từ một iBGP peer sang một iBGP peer khác (để chống loop khi không đổi AS-path), một thiết kế iBGP ngây thơ đòi hỏi full mesh các phiên peer. Các AS lớn giải quyết bằng route reflector hoặc confederation.
Các path attribute chính của BGP (dùng để chọn đường tốt nhất, theo thứ tự quyết định của Cisco — cao nhất thắng trừ khi ghi chú khác):
- Weight (chỉ Cisco, cục bộ trên một router) — cao nhất thắng.
- Local Preference — cao nhất thắng; đặt trong AS của bạn để ưu tiên một điểm ra (ví dụ ưu tiên ISP rẻ hơn).
- Ưu tiên route khởi tạo cục bộ.
- Độ dài AS-path — ngắn nhất thắng (đi qua ít AS hơn).
- Kiểu Origin (IGP < EGP < Incomplete).
- MED (Multi-Exit Discriminator) — thấp nhất thắng; một gợi ý cho AS neighbor về điểm vào nào của AS bạn nên ưu tiên.
- eBGP hơn iBGP.
- IGP metric tới next-hop thấp nhất, rồi route cũ nhất, rồi router ID thấp nhất làm tiêu chí phá hòa.
Một mô hình tư duy hữu ích: Local Preference kiểm soát cách traffic rời khỏi AS của bạn (outbound), còn MED và AS-path prepending ảnh hưởng tới cách traffic đi vào AS của bạn (inbound).
! Cisco IOS — eBGP tới một ISP, cộng một iBGP peer
Router(config)# router bgp 65001
Router(config-router)# bgp router-id 10.0.0.1
! neighbor eBGP thuộc AS của ISP
Router(config-router)# neighbor 203.0.113.1 remote-as 64500
! neighbor iBGP trong AS của mình
Router(config-router)# neighbor 10.0.0.2 remote-as 65001
Router(config-router)# neighbor 10.0.0.2 next-hop-self
! quảng bá prefix public của mình vào BGP
Router(config-router)# network 198.51.100.0 mask 255.255.255.0
!
! ưu tiên link ISP cho traffic outbound qua local-pref
Router(config)# route-map PREFER-ISP permit 10
Router(config-route-map)# set local-preference 200
Router(config)# router bgp 65001
Router(config-router)# neighbor 203.0.113.1 route-map PREFER-ISP in
!
Router# show ip bgp summary
Router# show ip bgp
BGP được đánh giá cao vì tính ổn định và khả năng kiểm soát policy, chứ không phải tốc độ: nó không “flap” đường trên mỗi thay đổi nhỏ, và update mang theo các attribute phong phú để người vận hành cài đặt policy routing phức tạp (peering vs transit, traffic engineering, lọc prefix). Quy mô của nó cực lớn — bảng IPv4 toàn cầu vượt quá 900.000 prefix.
MPLS và MPLS VPN
MPLS (Multi-Protocol Label Switching) forward packet dựa trên các label ngắn, độ dài cố định thay vì tra IP đích ở mỗi hop. Tại rìa mạng, router ingress (LER — Label Edge Router) phân loại packet vào một FEC (Forwarding Equivalence Class) và push một label. Các router lõi (LSR — Label Switching Router) sau đó swap label và forward dọc theo một LSP (Label-Switched Path) đã lập sẵn — một phép tra nhanh dựa trên bảng — cho tới khi router egress pop label và forward theo IP bình thường. Label được phân phối bởi LDP hoặc bởi BGP hiểu MPLS / segment routing.
Vì sao nó quan trọng:
- Tốc độ và đơn giản ở lõi — một phép tra label nhỏ thay cho một phép tra longest-prefix IP (bớt quan trọng với phần cứng hiện đại, nhưng mô hình vẫn còn giá trị).
- Traffic engineering (MPLS-TE) — điều hướng luồng theo đường tường minh, không chỉ theo đường ngắn nhất của IGP.
- MPLS L3VPN — ứng dụng chủ lực. Một nhà cung cấp dịch vụ chở nhiều mạng IP riêng của nhiều khách hàng trên cùng một backbone MPLS dùng chung, giữ route của mỗi khách hàng cách ly hoàn toàn. Route khách hàng nằm trong các VRF riêng từng khách (bên dưới) trên router biên nhà cung cấp (PE), được chở qua lõi dưới dạng route VPNv4 qua MP-BGP, và dùng ngăn xếp hai label (một transport label ngoài + một VPN label trong). Khách hàng thậm chí có thể dùng không gian địa chỉ private trùng nhau vì mỗi VRF là một routing context riêng.
VRF — Virtual Routing and Forwarding
VRF cho phép một router vật lý duy nhất giữ nhiều routing table độc lập cùng lúc, như thể nó là nhiều router ảo. Mỗi VRF có routing table riêng, bộ interface riêng, và góc nhìn mạng riêng — traffic trong một VRF không thể tới VRF khác trừ khi bạn cố ý leak route giữa chúng.
Ứng dụng:
- Multi-tenancy — giữ route của Khách hàng A và Khách hàng B tách biệt hoàn toàn trên phần cứng dùng chung (nền tảng của MPLS L3VPN).
- Không gian IP trùng nhau — hai phòng ban cùng dùng
10.0.0.0/8có thể cùng tồn tại trong các VRF khác nhau. - Phân đoạn và bảo mật — cách ly các mạng guest, corporate, IoT, và management ở Layer 3.
! Cisco IOS — định nghĩa một VRF và gán interface
Router(config)# vrf definition CUSTOMER-A
Router(config-vrf)# rd 65001:100
Router(config-vrf)# address-family ipv4
!
Router(config)# interface GigabitEthernet0/1
Router(config-if)# vrf forwarding CUSTOMER-A
Router(config-if)# ip address 10.1.1.1 255.255.255.0
!
Router# show ip route vrf CUSTOMER-A
Route distinguisher (RD) làm cho các prefix khách hàng vốn trùng nhau trở nên duy nhất toàn cầu bên trong MP-BGP.
Cloud routing
Mạng cloud định tuyến bằng route table gắn vào subnet thay vì bằng routing protocol chạy trên thiết bị vật lý. Trong AWS, một VPC route table ánh xạ CIDR đích tới target (internet gateway, NAT gateway, transit gateway, VPC peering, hay virtual private gateway); match cụ thể nhất (longest-prefix) thắng, đúng như trên router vật lý. Route propagation có thể tự động tiêm các route học qua VPN hoặc Direct Connect (qua BGP trên virtual gateway) vào route table. GCP và Azure theo cùng mô hình với tên gọi riêng. Chủ đề này được trình bày sâu trong ./16-cloud-networking.md.
So sánh các routing protocol
| Protocol | Loại | Metric | IGP/EGP | Chuẩn | Convergence | Use case điển hình |
|---|---|---|---|---|---|---|
| Static | — (thủ công) | Chỉ AD | — | — | Tức thì (không thích nghi) | Stub site, default route, dự phòng |
| RIP | Distance-vector | Hop count (tối đa 15) | IGP | RFC 2453 (v2) | Chậm | Legacy / mạng rất nhỏ |
| OSPF | Link-state | Cost (bandwidth) | IGP | RFC 2328 | Nhanh (dưới giây) | Doanh nghiệp & core đa hãng |
| IS-IS | Link-state | Cost | IGP | ISO 10589 | Nhanh | Core nhà cung cấp dịch vụ |
| EIGRP | Distance-vector nâng cao | Bandwidth + delay | IGP | RFC 7868 | Rất nhanh (feasible successor) | Doanh nghiệp toàn Cisco |
| BGP | Path-vector | Path attribute | EGP (và iBGP) | RFC 4271 | Chậm (cố ý) | Internet, inter-AS, policy WAN |
Best Practices
- Ưu tiên route cụ thể và đã được summarize. Summarize (aggregate) prefix tại các ranh giới — biên area OSPF, biên BGP — để thu nhỏ routing table, tăng tốc SPF, và giới hạn phạm vi ảnh hưởng của một link hay flap.
- Luôn có một default route ở biên, nhưng đừng bao giờ để default route lọt tới nơi gây loop hoặc black hole.
- Dùng static route một cách có chủ đích, không mặc định. Chúng hoàn hảo cho stub link và dự phòng (floating static), nhưng không tự failover — hãy ghép với IP SLA / object tracking nếu link có thể chết.
- Đặt reference bandwidth của OSPF nhất quán trên mọi router (
auto-cost reference-bandwidth) để các link 1/10/100 Gbps thực sự được phân biệt; nếu không mọi link nhanh đều gộp về cost 1. - Đặt passive các interface hướng về host (
passive-interface) trong IGP để không gửi Hello nơi không có router — bớt nhiễu, giảm bề mặt tấn công. - Bật authentication cho routing protocol. Bật MD5/SHA cho các phiên OSPF, EIGRP, và BGP để kẻ tấn công không thể tiêm route giả.
- Lọc BGP thật chặt. Áp prefix-list / route-map cho cả chiều inbound và outbound của BGP để không bao giờ nhận hay quảng bá prefix không đáng có (một filter cấu hình sai đã từng gây sự cố internet toàn cầu). Đặt giới hạn maximum-prefix trên các peer.
- Dùng Local Preference cho outbound và AS-path prepending / MED cho inbound trong traffic engineering — nắm rõ đòn bẩy nào điều khiển chiều nào.
- Thiết kế cho convergence. Tinh chỉnh Hello/dead timer hoặc dùng BFD (Bidirectional Forwarding Detection) để phát hiện sự cố dưới giây ở nơi cần failover nhanh.
- Để ý administrative distance khi redistribute giữa các protocol — AD lệch nhau hoặc redistribute không kiểm soát có thể tạo routing loop và đường suboptimal. Dùng route tag và filter khi buộc phải redistribute hai chiều.
- Cách ly bằng VRF thay vì chỉ dựa vào ACL khi các tenant hay môi trường tuyệt đối không được dùng chung routing table.
- Ghi tài liệu và giám sát. Giữ một nguồn sự thật cho static route và policy BGP, đồng thời giám sát số lượng route, trạng thái neighbor, và các sự kiện convergence (SNMP, streaming telemetry, syslog).
Tài liệu tham khảo
- RFC 2328 — OSPF Version 2
- RFC 5340 — OSPF for IPv6 (OSPFv3)
- RFC 4271 — A Border Gateway Protocol 4 (BGP-4)
- RFC 2453 — RIP Version 2
- RFC 7868 — Cisco EIGRP
- RFC 3031 — Multiprotocol Label Switching Architecture
- RFC 4364 — BGP/MPLS IP Virtual Private Networks (L3VPN)
- Cisco — IP Routing Configuration Guides
Part of the Network Engineer Roadmap knowledge base.
Overview
Routing is the process of selecting a path for traffic to travel from a source network to a destination network across one or more intermediate devices. Where switching moves frames within a single Layer 2 broadcast domain using MAC addresses, routing moves packets between Layer 3 networks (IP subnets) using IP addresses. A router is the device that performs this job: it receives a packet on one interface, decides where it should go next, and forwards it out another interface — repeatedly, hop by hop, until the packet reaches its destination.
The internet is, at its heart, a colossal exercise in routing. There is no single map of the whole network; instead, hundreds of thousands of routers each hold a partial view and cooperate — through routing protocols — to build a consistent, loop-free set of paths. A packet leaving your laptop to reach a server on the other side of the planet may cross 15–25 routers, each making an independent forwarding decision in microseconds based purely on its local routing table.
Two questions sit at the core of every routing decision:
- Where is the destination? The router compares the packet’s destination IP against entries in its routing table (see IP addressing and subnetting for how addresses and prefixes work).
- How do I reach it? The matching entry tells the router the next-hop address and/or the outgoing interface.
This note covers how the routing table works, the difference between static and dynamic routing, the major routing protocol families (distance-vector, link-state, path-vector), the specific protocols you will meet in the field (RIP, OSPF, EIGRP, BGP), and the technologies built on top of routing (MPLS, VRF, and cloud route tables).
Fundamentals
The routing table
Every router (and every host — your laptop has one too) maintains a routing table: an ordered list of known destination networks and how to reach each one. When a packet arrives, the router consults this table to decide the next hop. A single entry contains, at minimum:
- Destination prefix — a network and its mask, e.g.
10.1.2.0/24. - Next-hop — the IP address of the adjacent router to forward to, e.g.
192.0.2.1. - Outgoing interface — the local interface the packet leaves through, e.g.
GigabitEthernet0/1. - Metric — a measure of how “good” the route is (lower is better).
- Administrative distance — how trustworthy the source of the route is (lower is better).
You can inspect it directly:
# Linux
$ ip route show
default via 192.168.1.1 dev eth0 proto dhcp metric 100
10.10.0.0/16 via 192.168.1.254 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.50
! Cisco IOS
Router# show ip route
Codes: C - connected, S - static, R - RIP, O - OSPF, D - EIGRP, B - BGP
* - candidate default
C 192.168.1.0/24 is directly connected, GigabitEthernet0/0
O 10.10.0.0/16 [110/20] via 192.168.1.254, 00:15:22, GigabitEthernet0/0
S* 0.0.0.0/0 [1/0] via 192.168.1.1
In the Cisco output the letter in the left column is the route source (C connected, O OSPF, S static). The bracketed pair [110/20] is [administrative distance / metric].
Longest-prefix match
A destination IP can match several routing-table entries at once. For example, a packet to 10.1.2.5 might match all of these:
| Entry | Prefix length | Matches 10.1.2.5? |
|---|---|---|
0.0.0.0/0 (default) | 0 | yes |
10.0.0.0/8 | 8 | yes |
10.1.0.0/16 | 16 | yes |
10.1.2.0/24 | 24 | yes |
The router always chooses the most specific match — the one with the longest prefix (largest mask). Here it picks 10.1.2.0/24. This is the fundamental forwarding rule: longest-prefix match wins. It lets a router carry a broad 0.0.0.0/0 default route as a catch-all while overriding it with more specific routes for particular destinations.
Directly connected vs remote networks
- Directly connected networks are the subnets on the router’s own interfaces. When you assign
192.168.1.1/24to an interface and bring it up, the router automatically installs a connected route (C) for192.168.1.0/24. No protocol needed — the router can reach those hosts directly over Layer 2. - Remote networks are everything else: subnets reachable only through another router. The router learns these either from a human (static routes) or from a routing protocol (dynamic routes), and each remote route points to a next-hop — the neighboring router to hand the packet to.
Forwarding is recursive in spirit: “to reach network X, send to next-hop Y” — and the router must itself know how to reach Y (usually because Y is on a directly connected subnet).
Administrative distance (AD)
A router may learn about the same destination from multiple sources — say, a static route and OSPF and RIP all describe 10.10.0.0/16. It cannot install conflicting entries, so it must pick one. Administrative distance ranks the trustworthiness of the source, independent of the metric. Lower AD wins. Only after AD selects a source does the protocol’s own metric break ties among routes from that same source.
| Route source | Default AD (Cisco) |
|---|---|
| Connected interface | 0 |
| Static route | 1 |
| eBGP (external BGP) | 20 |
| EIGRP (internal) | 90 |
| OSPF | 110 |
| RIP | 120 |
| iBGP (internal BGP) | 200 |
| Unreachable / floating fallback | 255 (never installed) |
So a static route (AD 1) always beats an OSPF-learned route (AD 110) for the same prefix, regardless of metrics — because you, the operator, are assumed to know best.
Metric
The metric is a value a routing protocol uses to compare its own candidate paths to the same destination and pick the best one. Lower is better. Each protocol measures “best” differently:
- RIP — hop count (number of routers to cross).
- OSPF — cost, derived from interface bandwidth.
- EIGRP — a composite of bandwidth and delay (by default).
- BGP — no single numeric metric; it runs a multi-step path-selection algorithm over attributes.
Control plane vs data plane
- The control plane builds the routing table: it runs the routing protocols, exchanges updates with neighbors, and computes best paths. This is the “thinking” part.
- The data plane (or forwarding plane) actually moves packets. Modern routers compile the routing table (RIB — Routing Information Base) into an optimized forwarding table (FIB), often in hardware (Cisco calls this CEF — Cisco Express Forwarding), so packets are switched at line rate without consulting the full routing logic on every packet.
Key Concepts
Static routing
A static route is a route you configure by hand. The router does not learn it, adapt it, or withdraw it — it stays until you remove it.
! Cisco IOS — reach 10.20.0.0/16 via next-hop 192.0.2.2
Router(config)# ip route 10.20.0.0 255.255.0.0 192.0.2.2
! Default route — "everything else" goes to the ISP gateway
Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1
# Linux equivalent
$ sudo ip route add 10.20.0.0/16 via 192.0.2.2
$ sudo ip route add default via 203.0.113.1
The default route (0.0.0.0/0, “quad-zero”) is the ultimate longest-prefix fallback: it matches any destination not covered by a more specific entry. Stub networks and hosts typically carry just one default route pointing at their gateway (“the default gateway”), rather than a full table.
Pros: no protocol overhead, no CPU/bandwidth for updates, fully predictable, more secure (no route injection from neighbors), and precise control over paths. Cons: does not scale (every route on every router by hand), no automatic failover unless combined with tracking (e.g. a floating static route with a high AD as backup), and error-prone in large or changing topologies.
When to use: small networks, stub sites with a single exit, default routes toward an ISP, and as backups. Below is a floating static route — it only installs (AD 5) if the primary path (via OSPF, AD 110… actually lower AD wins, so use AD higher than the primary’s) disappears:
! Primary learned via OSPF (AD 110); this backup installs only if OSPF route is gone
Router(config)# ip route 10.20.0.0 255.255.0.0 198.51.100.2 130
Dynamic routing
Dynamic routing uses a routing protocol so routers automatically discover networks, share what they know with neighbors, and recompute paths when the topology changes (a link fails, a router reboots). The time it takes all routers to agree on a new consistent view after a change is called convergence — a key quality metric for any protocol.
Pros: scales to large networks, adapts automatically to failures, less manual work. Cons: consumes CPU, memory, and bandwidth; adds complexity; and requires securing the protocol against bad or malicious updates.
Distance-vector vs link-state
The two classic families of IGP differ fundamentally in what they share and how they compute paths.
| Aspect | Distance-vector | Link-state |
|---|---|---|
| What each router knows | Only distances/directions reported by neighbors (“routing by rumor”) | The full topology map of its area |
| What is advertised | Its entire routing table, to directly connected neighbors | Its own links (LSAs), flooded to all routers in the area |
| Algorithm | Bellman-Ford | Dijkstra (SPF — Shortest Path First) |
| Convergence | Slower; risk of loops and count-to-infinity | Faster; each router computes independently |
| Resource use | Low CPU/memory | Higher CPU/memory (holds full topology) |
| Examples | RIP, EIGRP (advanced) | OSPF, IS-IS |
Distance-vector routers trust their neighbors’ summaries; link-state routers build their own complete picture and run Dijkstra to find shortest paths, which avoids most loop problems and converges faster.
IGP vs EGP
- IGP (Interior Gateway Protocol) — runs within a single autonomous system (AS), i.e. a network under one administrative control. Optimizes for fast convergence and best internal path. Examples: OSPF, IS-IS, EIGRP, RIP.
- EGP (Exterior Gateway Protocol) — runs between autonomous systems. Optimizes for policy, scalability, and stability over raw speed. The only EGP in real use today is BGP.
An autonomous system is identified by an AS number (ASN) — a globally unique number (16-bit 1–65535, or 32-bit) assigned by a regional registry (e.g. AS15169 is Google). Your ISP has an ASN; large enterprises that multi-home have one too.
RIP — Routing Information Protocol
RIP is the oldest, simplest dynamic routing protocol — a pure distance-vector IGP.
- Metric: hop count only. Each router adds 1.
- Maximum: 15 hops; 16 = unreachable (infinity). This deliberately small cap limits how far RIP can scale and helps bound the count-to-infinity problem.
- Updates: periodic broadcasts/multicasts of the whole table every 30 seconds.
- Versions: RIPv1 (classful, no mask in updates — obsolete), RIPv2 (classless/VLSM, multicast 224.0.0.9, supports authentication), RIPng (for IPv6).
Router(config)# router rip
Router(config-router)# version 2
Router(config-router)# no auto-summary
Router(config-router)# network 192.168.1.0
Router(config-router)# network 10.0.0.0
Limitations: the 15-hop ceiling, slow convergence, and a hop-count metric that ignores bandwidth (a 10 Gbps 3-hop path loses to a 1 Mbps 2-hop path). RIP survives mostly in labs, tiny networks, and legacy gear. Loop-prevention mechanisms it relies on: split horizon, route poisoning, poison reverse, and hold-down timers.
OSPF — Open Shortest Path First
OSPF is the dominant open-standard link-state IGP (RFC 2328 for OSPFv2/IPv4, RFC 5340 for OSPFv3/IPv6). Every router builds an identical Link-State Database (LSDB) describing the topology, then runs Dijkstra’s SPF algorithm to compute the shortest-path tree to every destination.
How it works:
- Routers discover neighbors and form adjacencies using Hello packets.
- Each router describes its links in LSAs (Link-State Advertisements) and floods them to all routers in the area.
- Every router assembles the LSAs into an identical LSDB.
- Each router independently runs SPF to build its routing table.
Cost (metric): OSPF cost is reference-bandwidth / interface-bandwidth. With the default reference of 100 Mbps, a 100 Mbps link = cost 1, a 10 Mbps link = cost 10. On modern networks you should raise the reference bandwidth (e.g. to 100000 for 100 Gbps) so fast links are distinguished.
Areas: OSPF scales by dividing a large domain into areas, all connected to a central backbone area 0. LSA flooding is contained within an area; Area Border Routers (ABRs) summarize between areas. This keeps LSDBs small and SPF runs cheap. Special area types (stub, totally stubby, NSSA) further reduce the LSAs injected into edge areas.
DR/BDR: On a multi-access segment (like Ethernet with many routers) OSPF elects a Designated Router (DR) and Backup DR (BDR) to avoid every router forming a full mesh of adjacencies. All routers form adjacency with the DR/BDR only, which reduces LSA flooding from O(n²) to O(n). Election is by highest OSPF priority, then highest Router ID.
Convergence: fast — typically sub-second to a few seconds — because each router already holds the full topology and only needs to re-run SPF when an LSA changes.
! Cisco IOS — OSPF single area
Router(config)# router ospf 1
Router(config-router)# router-id 1.1.1.1
Router(config-router)# auto-cost reference-bandwidth 100000
Router(config-router)# network 192.168.1.0 0.0.0.255 area 0
Router(config-router)# network 10.1.0.0 0.0.255.255 area 0
Router(config-router)# passive-interface GigabitEthernet0/2
!
! Verify
Router# show ip ospf neighbor
Router# show ip route ospf
Note the wildcard mask (0.0.0.255, the inverse of a subnet mask) and the explicit area assignment. passive-interface stops OSPF Hellos on interfaces facing hosts (no routers there), improving security and reducing noise.
EIGRP — Enhanced Interior Gateway Routing Protocol
EIGRP is Cisco’s advanced distance-vector protocol (opened as informational RFC 7868). It behaves like distance-vector (it learns from neighbors, not a full topology) but adds link-state-like speed and loop-freedom via the DUAL (Diffusing Update Algorithm).
- Metric: composite, using bandwidth and delay by default (load and reliability optionally). This makes it bandwidth-aware, unlike RIP.
- Neighbors: forms adjacencies with Hello packets; sends incremental, reliable updates only when something changes — not periodic full-table dumps.
- DUAL terms:
- Successor — the current best (lowest-metric, loop-free) next-hop; installed in the routing table.
- Feasible successor — a pre-computed loop-free backup next-hop. If the successor fails and a feasible successor exists, EIGRP switches to it instantly (no recomputation), giving very fast convergence.
- Feasibility condition — a neighbor qualifies as a feasible successor only if its reported distance to the destination is less than the current successor’s total distance, which guarantees no loop.
! Cisco IOS — named EIGRP configuration
Router(config)# router eigrp CORP
Router(config-router)# address-family ipv4 unicast autonomous-system 100
Router(config-router-af)# network 192.168.1.0 0.0.0.255
Router(config-router-af)# network 10.1.0.0 0.0.255.255
!
Router# show ip eigrp neighbors
Router# show ip eigrp topology
EIGRP converges very fast when feasible successors are available and is simpler to configure than OSPF, but it is (historically) Cisco-centric, so it is common in all-Cisco enterprises and rare in multi-vendor or service-provider cores.
BGP — Border Gateway Protocol
BGP (version 4, RFC 4271) is the routing protocol of the internet — the only EGP in use. It is a path-vector protocol: instead of a simple metric, it advertises the full AS-path (the list of autonomous systems a route traverses), which both enables policy and prevents loops (a router rejects any route whose AS-path already contains its own ASN).
eBGP vs iBGP:
| eBGP (external) | iBGP (internal) | |
|---|---|---|
| Peers | Between different ASes | Within the same AS |
| TTL | Typically directly connected (TTL 1) | Anywhere in the AS |
| AS-path | Prepends own ASN on advertise | Does not change AS-path |
| Default AD (Cisco) | 20 | 200 |
| Next-hop behavior | Sets next-hop to itself | Next-hop unchanged (often needs next-hop-self) |
| Loop prevention | AS-path | Split-horizon rule → needs full mesh or route reflectors |
Because iBGP does not re-advertise routes learned from one iBGP peer to another (to prevent loops without an AS-path change), a naive iBGP design requires a full mesh of peerings. Large ASes solve this with route reflectors or confederations.
Key BGP path attributes (used to select the best path, in Cisco’s decision order — highest wins unless noted):
- Weight (Cisco-only, local to one router) — highest wins.
- Local Preference — highest wins; set within your AS to prefer an exit point (e.g. prefer the cheaper ISP).
- Locally originated routes preferred.
- AS-path length — shortest wins (fewer ASes to cross).
- Origin type (IGP < EGP < Incomplete).
- MED (Multi-Exit Discriminator) — lowest wins; a hint to a neighbor AS about which entry point into your AS to prefer.
- eBGP over iBGP.
- Lowest IGP metric to the next-hop, then oldest route, then lowest router ID as tiebreakers.
A useful mental model: Local Preference controls how traffic leaves your AS (outbound), while MED and AS-path prepending influence how traffic enters your AS (inbound).
! Cisco IOS — eBGP to an ISP, plus one iBGP peer
Router(config)# router bgp 65001
Router(config-router)# bgp router-id 10.0.0.1
! eBGP neighbor in the ISP's AS
Router(config-router)# neighbor 203.0.113.1 remote-as 64500
! iBGP neighbor inside our own AS
Router(config-router)# neighbor 10.0.0.2 remote-as 65001
Router(config-router)# neighbor 10.0.0.2 next-hop-self
! advertise our public prefix into BGP
Router(config-router)# network 198.51.100.0 mask 255.255.255.0
!
! prefer the ISP link for outbound traffic via local-pref
Router(config)# route-map PREFER-ISP permit 10
Router(config-route-map)# set local-preference 200
Router(config)# router bgp 65001
Router(config-router)# neighbor 203.0.113.1 route-map PREFER-ISP in
!
Router# show ip bgp summary
Router# show ip bgp
BGP is prized for stability and policy control, not speed: it does not flap paths on every minor change, and updates carry rich attributes so operators can implement complex routing policy (peering vs transit, traffic engineering, prefix filtering). Its scale is immense — the global IPv4 table exceeds 900,000 prefixes.
MPLS and MPLS VPNs
MPLS (Multi-Protocol Label Switching) forwards packets based on short, fixed-length labels rather than by looking up the destination IP at every hop. At the network edge, an ingress router (LER — Label Edge Router) classifies a packet into a FEC (Forwarding Equivalence Class) and pushes a label. Core routers (LSRs — Label Switching Routers) then swap labels and forward along a pre-established LSP (Label-Switched Path) — a fast, table-driven lookup — until the egress router pops the label and forwards natively. Labels are distributed by LDP or by MPLS-aware BGP/segment routing.
Why it matters:
- Speed and simplicity in the core — one small label lookup instead of a longest-prefix IP lookup (less relevant with modern hardware, but the model persists).
- Traffic engineering (MPLS-TE) — steer flows along explicit paths, not just the IGP shortest path.
- MPLS L3VPN — the killer application. A service provider carries many customers’ private IP networks over one shared MPLS backbone, keeping each customer’s routes fully isolated. Customer routes live in per-customer VRFs (below) on the provider edge (PE) routers, are carried across the core as VPNv4 routes via MP-BGP, and use a two-label stack (an outer transport label + an inner VPN label). Customers can even use overlapping private address space because each VRF is a separate routing context.
VRF — Virtual Routing and Forwarding
VRF lets a single physical router hold multiple independent routing tables at once, as if it were several virtual routers. Each VRF has its own routing table, its own set of interfaces, and its own view of the network — traffic in one VRF cannot reach another unless you explicitly leak routes between them.
Uses:
- Multi-tenancy — keep Customer A’s and Customer B’s routes completely separate on shared hardware (the foundation of MPLS L3VPN).
- Overlapping IP space — two departments both using
10.0.0.0/8can coexist in different VRFs. - Segmentation and security — isolate guest, corporate, IoT, and management networks at Layer 3.
! Cisco IOS — define a VRF and bind an interface
Router(config)# vrf definition CUSTOMER-A
Router(config-vrf)# rd 65001:100
Router(config-vrf)# address-family ipv4
!
Router(config)# interface GigabitEthernet0/1
Router(config-if)# vrf forwarding CUSTOMER-A
Router(config-if)# ip address 10.1.1.1 255.255.255.0
!
Router# show ip route vrf CUSTOMER-A
The route distinguisher (RD) makes otherwise-overlapping customer prefixes globally unique inside MP-BGP.
Cloud routing
Cloud networks route with route tables attached to subnets rather than routing protocols on physical boxes. In AWS a VPC route table maps destination CIDRs to targets (an internet gateway, NAT gateway, transit gateway, VPC peering connection, or virtual private gateway); the most specific (longest-prefix) match wins, exactly as on a physical router. Route propagation can automatically inject routes learned over a VPN or Direct Connect (via BGP on a virtual gateway) into the route table. GCP and Azure follow the same model with their own naming. This is covered in depth in ./16-cloud-networking.md.
Routing protocol comparison
| Protocol | Type | Metric | IGP/EGP | Standard | Convergence | Typical use case |
|---|---|---|---|---|---|---|
| Static | — (manual) | AD only | — | — | Instant (no adaptation) | Stub sites, default routes, backups |
| RIP | Distance-vector | Hop count (max 15) | IGP | RFC 2453 (v2) | Slow | Legacy / very small nets |
| OSPF | Link-state | Cost (bandwidth) | IGP | RFC 2328 | Fast (sub-second) | Enterprise & multi-vendor cores |
| IS-IS | Link-state | Cost | IGP | ISO 10589 | Fast | Service-provider cores |
| EIGRP | Advanced distance-vector | Bandwidth + delay | IGP | RFC 7868 | Very fast (feasible successor) | All-Cisco enterprises |
| BGP | Path-vector | Path attributes | EGP (and iBGP) | RFC 4271 | Slow (by design) | Internet, inter-AS, WAN policy |
Best Practices
- Prefer specific, summarized routes. Summarize (aggregate) prefixes at boundaries — OSPF area borders, BGP edges — to shrink routing tables, speed SPF, and contain the blast radius of a flapping link.
- Always have a default route at the edge, but never let a default route leak somewhere it causes a loop or a black hole.
- Use static routes deliberately, not by default. They are perfect for stub links and backups (floating statics), but they do not fail over on their own — pair them with IP SLA / object tracking if a link can go down.
- Set OSPF reference bandwidth consistently on every router (
auto-cost reference-bandwidth) so 1/10/100 Gbps links are actually distinguished; otherwise all fast links collapse to cost 1. - Make host-facing interfaces passive (
passive-interface) in IGPs so you do not send Hellos where no routers exist — less noise, smaller attack surface. - Authenticate routing protocols. Enable MD5/SHA authentication on OSPF, EIGRP, and BGP sessions so an attacker cannot inject false routes.
- Filter BGP aggressively. Apply prefix-lists / route-maps to both inbound and outbound BGP so you never accept or announce prefixes you shouldn’t (a misconfigured filter has caused global internet outages). Set maximum-prefix limits on peers.
- Use Local Preference for outbound and AS-path prepending / MED for inbound traffic engineering — know which lever controls which direction.
- Design for convergence. Tune Hello/dead timers or use BFD (Bidirectional Forwarding Detection) for sub-second failure detection where fast failover matters.
- Watch administrative distance when redistributing between protocols — mismatched AD or uncontrolled redistribution can create routing loops and suboptimal paths. Use route tags and filters when mutual redistribution is unavoidable.
- Isolate with VRFs rather than relying on ACLs alone when tenants or environments must never share a routing table.
- Document and monitor. Keep a source of truth for static routes and BGP policy, and monitor route counts, neighbor states, and convergence events (SNMP, streaming telemetry, syslog).
References
- RFC 2328 — OSPF Version 2
- RFC 5340 — OSPF for IPv6 (OSPFv3)
- RFC 4271 — A Border Gateway Protocol 4 (BGP-4)
- RFC 2453 — RIP Version 2
- RFC 7868 — Cisco EIGRP
- RFC 3031 — Multiprotocol Label Switching Architecture
- RFC 4364 — BGP/MPLS IP Virtual Private Networks (L3VPN)
- Cisco — IP Routing Configuration Guides