85 phút
OSPF và Dynamic Routing
OSPF và Dynamic Routing
Dynamic Routing Protocols
Phân loại
IGP (Interior Gateway Protocol):
- Distance Vector: RIP, EIGRP
- Link State: OSPF, IS-IS
EGP (Exterior Gateway Protocol):
- BGP (Border Gateway Protocol)
So sánh:
RIP: Hop count, max 15 hops, slow convergence
OSPF: Link state, cost-based, fast convergence
EIGRP: Hybrid, DUAL algorithm, Cisco proprietary
BGP: Path vector, Internet routing, policy-based
OSPF Overview
Đặc điểm
- Open standard (RFC 2328 OSPFv2)
- Link-state routing protocol
- Sử dụng Dijkstra SPF algorithm
- Cost = Reference BW / Interface BW
- Reference BW mặc định: 100 Mbps
- Administrative Distance: 110
- Multicast: 224.0.0.5, 224.0.0.6
- Protocol number: 89
OSPF Cost
Cost = 10^8 / Bandwidth (bps)
Interface costs:
Ethernet (10 Mbps): Cost = 10
FastEthernet (100): Cost = 1
GigabitEthernet (1G): Cost = 1
10G: Cost = 1
Với reference BW 100 Mbps, tất cả >= 100Mbps đều có cost 1
Cấu hình reference BW:
R1(config)# router ospf 1
R1(config-router)# auto-cost reference-bandwidth 10000
# Trên tất cả routers phải giống nhau!
OSPF Areas
Backbone Area: Area 0
Regular Areas: Area 1, 2, 3...
Special:
- Stub: No external routes (LSA 5)
- Totally Stubby: Only default route (Cisco)
- NSSA: Not-So-Stubby Area (Cisco)
Rules:
- Tất cả areas phải kết nối với Area 0
- Nếu không trực tiếp → virtual link
- Area 0 là core của OSPF
OSPF Neighbor States
Down - Chưa có thông tin
Init - Nhận được Hello, chưa 2-way
2-Way - 2-way communication
ExStart - Bắt đầu trao đổi DBD
Exchange - Trao đổi DBD packets
Loading - Trao đổi LSAs
Full - Đồng bộ database ✓
Hello Packet
Interval:
- Broadcast: 10s
- NBMA: 30s
Dead Interval:
- Broadcast: 40s (4×Hello)
- NBMA: 120s
Phải khớp:
- Hello interval
- Dead interval
- Area ID
- Authentication
- Stub flag
- MTU (khi Exchange)
Cấu hình OSPF cơ bản
Single Area
# R1
R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0
R1(config-router)# network 10.0.0.0 0.0.0.3 area 0
R1(config-router)# exit
# R2
R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 10.0.0.0 0.0.0.3 area 0
R2(config-router)# network 10.0.0.4 0.0.0.3 area 0
R2(config-router)# exit
# R3
R3(config)# router ospf 1
R3(config-router)# router-id 3.3.3.3
R3(config-router)# network 10.0.0.4 0.0.0.3 area 0
R3(config-router)# network 192.168.3.0 0.0.0.255 area 0
Interface-level config (khuyến nghị)
R1(config)# interface gi0/1
R1(config-if)# ip ospf 1 area 0
R1(config-if)# ip ospf priority 100
R1(config-if)# ip ospf cost 10
R1(config-if)# ip ospf hello-interval 10
R1(config-if)# ip ospf dead-interval 40
R1(config-if)# ip ospf authentication message-digest
R1(config-if)# ip ospf message-digest-key 1 md5 Cisco123
R1(config-if)# exit
Verify OSPF
R1# show ip ospf neighbor
R1# show ip ospf neighbor detail
R1# show ip ospf database
R1# show ip ospf interface
R1# show ip ospf interface brief
R1# show ip protocols
R1# show ip route ospf
R1# show ip ospf
Debug OSPF
R1# debug ip ospf adj
R1# debug ip ospf events
R1# debug ip ospf hello
R1# debug ip ospf packet
R1# undebug all
DR/BDR Election
Trên broadcast networks
DR - Designated Router
BDR - Backup Designated Router
DROther - Các router khác
Election:
1. Priority cao nhất (0-255, default 1)
2. Nếu bằng → Router ID cao nhất
3. Priority = 0 → không tham gia
DRother chỉ form adjacency Full với DR và BDR
DRother-DRother: 2-Way state
Cấu hình DR
R1(config)# interface gi0/1
R1(config-if)# ip ospf priority 100
R1(config-if)# exit
# Non-preemptive: không tự động đổi DR
# Cần clear để bầu lại
R1# clear ip ospf process
Verify DR/BDR
R1# show ip ospf neighbor
# Output:
Neighbor ID Pri State Dead Time Address
2.2.2.2 1 2WAY/DROTHER 00:00:38 10.0.0.2
3.3.3.3 1 FULL/BDR 00:00:35 10.0.0.6
4.4.4.4 1 FULL/DR 00:00:32 10.0.0.10
Multi-Area OSPF
Cấu hình ABR
# ABR (Area Border Router)
ABR(config)# router ospf 1
ABR(config-router)# router-id 1.1.1.1
ABR(config-router)# network 192.168.1.0 0.0.0.255 area 1
ABR(config-router)# network 10.0.0.0 0.0.0.3 area 0
ABR(config-router)# exit
# Interface-level
ABR(config)# interface gi0/0
ABR(config-if)# ip ospf 1 area 0
ABR(config-if)# exit
ABR(config)# interface gi0/1
ABR(config-if)# ip ospf 1 area 1
ABR(config-if)# exit
Stub Area
# Trên tất cả routers trong stub area
R1(config)# router ospf 1
R1(config-router)# area 1 stub
R1(config-router)# exit
# Trên ABR
ABR(config)# router ospf 1
ABR(config-router)# area 1 stub
ABR(config-router)# exit
# Totally Stubby (Cisco)
ABR(config-router)# area 1 stub no-summary
NSSA (Not-So-Stubby Area)
R1(config)# router ospf 1
R1(config-router)# area 1 nssa
R1(config-router)# exit
# ABR
ABR(config)# router ospf 1
ABR(config-router)# area 1 nssa
Virtual Link
# Khi area không kết nối trực tiếp area 0
R1(config)# router ospf 1
R1(config-router)# area 1 virtual-link 2.2.2.2
R1(config-router)# exit
# Cả 2 đầu đều phải config
R2(config)# router ospf 1
R2(config-router)# area 1 virtual-link 1.1.1.1
OSPF Authentication
Type 1 - Plain text (không khuyến nghị)
R1(config)# interface gi0/1
R1(config-if)# ip ospf authentication
R1(config-if)# ip ospf authentication-key Cisco123
Type 2 - MD5
R1(config)# interface gi0/1
R1(config-if)# ip ospf authentication message-digest
R1(config-if)# ip ospf message-digest-key 1 md5 Cisco123
Type 3 - SHA (mới hơn)
R1(config)# interface gi0/1
R1(config-if)# ip ospf authentication key-chain MYKEY
R1(config-if)# exit
R1(config)# key chain MYKEY
R1(config-keychain)# key 1
R1(config-keychain-key)# key-string Cisco123
R1(config-keychain-key)# cryptographic-algorithm hmac-sha-256
R1(config-keychain-key)# exit
R1(config-keychain)# exit
OSPF Network Types
Broadcast (default cho Ethernet)
- DR/BDR election
- Multicast 224.0.0.5, 224.0.0.6
- Hello 10s, Dead 40s
- Auto neighbor discovery
Point-to-Point
R1(config)# interface serial0/0
R1(config-if)# ip ospf network point-to-point
- Không DR/BDR
- Hello 10s, Dead 40s
- Auto neighbor discovery
Non-Broadcast (NBMA)
- DR/BDR election
- Unicast
- Hello 30s, Dead 120s
- Cần neighbor statement
Point-to-Multipoint
R1(config)# interface serial0/0
R1(config-if)# ip ospf network point-to-multipoint
- Không DR/BDR
- Hello 30s, Dead 120s
- Auto neighbor discovery
EIGRP
Overview
- Cisco proprietary (đã mở 2013)
- Advanced distance vector
- DUAL algorithm
- AD: 90 (internal), 170 (external)
- Multicast: 224.0.0.10
- Protocol number: 88
Cấu hình cơ bản
R1(config)# router eigrp 100
R1(config-router)# no auto-summary
R1(config-router)# network 192.168.1.0 0.0.0.255
R1(config-router)# network 10.0.0.0 0.0.0.3
R1(config-router)# exit
# Với passive interface
R1(config-router)# passive-interface gi0/1
R1(config-router)# exit
# Verify
R1# show ip eigrp neighbors
R1# show ip eigrp topology
R1# show ip route eigrp
R1# show ip protocols
EIGRP Metrics
Composite metric:
- Bandwidth (K1)
- Delay (K3)
- Load (K2)
- Reliability (K4, K5)
Default: BW + Delay
Formula: 256 × (10^7/min_BW + sum_delay/10)
Bài tập thực hành
Hãy cấu hình OSPF multi-area!