实验拓扑
基础配置
给路由器接口配上ip地址
R1
interface Ethernet0/0
ip address 172.16.12.1 255.255.255.0
no sh
interface Ethernet0/1
ip address 172.16.1.1 255.255.255.0
no sh
R2
interface Ethernet0/0
ip address 172.16.12.2 255.255.255.0
no sh
interface Ethernet0/1
ip address 172.16.2.2 255.255.255.0
no sh
interface Ethernet0/2
ip address 172.16.234.2 255.255.255.0
no sh
R3
interface Ethernet0/0
ip address 172.16.234.3 255.255.255.0
no sh
interface Ethernet0/1
ip address 172.16.3.3 255.255.255.0
no sh
R4
interface Ethernet0/0
ip address 172.16.234.4 255.255.255.0
no sh
interface Ethernet0/1
ip address 172.16.4.4 255.255.255.0
no sh
OSPF 配置
R1
ip route 0.0.0.0 0.0.0.0 172.16.1.0 //配置到外网的静态路由
router ospf 1 //启动ospf进程
router-id 1.1.1.1 //配置ospf的进程ID
auto-cost reference-bandwidth 1000 //修改ospf的度量值,确保所有路由器保持一致
network 172.16.12.1 0.0.0.0 area 0 //配置参与ospf的接口范围
default-information originate //向ospf注入默认路由
interface Ethernet0/0
ip ospf hello-interval 5 //修改ospf发送hello的间隔
ip ospf dead-interval 20 //dead时间一般为hello时间的四倍
R2
router ospf 1
router-id 2.2.2.2
passive-interface Ethernet0/1 //配置被动接口
network 172.16.2.2 0.0.0.0 area 0
network 172.16.12.2 0.0.0.0 area 0
network 172.16.234.2 0.0.0.0 area 0
interface Ethernet0/0
ip ospf dead-interval 20
ip ospf hello-interval 5
interface Ethernet0/2
ip ospf priority 20 //修改优先级(越大越优先),使得R2成为DR,以太网接口ospf优先级默认为1
R3
router ospf 1
router-id 3.3.3.3
auto-cost reference-bandwidth 1000
passive-interface Ethernet0/1
network 172.16.3.3 0.0.0.0 area 0
network 172.16.234.3 0.0.0.0 area 0
interface Ethernet0/0
ip ospf priority 10 //修改优先级。使得R3为BDR
R4
router ospf 1
router-id 4.4.4.4
auto-cost reference-bandwidth 10000
passive-interface Ethernet0/1
network 172.16.4.4 0.0.0.0 area 0
network 172.16.234.4 0.0.0.0 area 0
实验调试
R2# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 10 FULL/BDR 00:00:35 172.16.234.3 Ethernet0/2
4.4.4.4 1 FULL/DROTHER 00:00:36 172.16.234.4 Ethernet0/2
1.1.1.1 1 FULL/BDR 00:00:19 172.16.12.1 Ethernet0/0
R2#show ip ospf interface ethernet 0/0
Ethernet0/0 is up, line protocol is up //接口为up up
Internet Address 172.16.12.2/24, Area 0, Attached via Network Statement
Process ID 1, Router ID 2.2.2.2, Network Type BROADCAST, Cost: 10
Topology-MTID Cost Disabled Shutdown Topology Name
0 10 no no Base
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 2.2.2.2, Interface address 172.16.12.2
Backup Designated router (ID) 1.1.1.1, Interface address 172.16.12.1
Timer intervals configured, Hello 5, Dead 20, Wait 20, Retransmit 5
oob-resync timeout 40
Hello due in 00:00:00
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
Index 2/2, flood queue length 0
Next 0x0(0)/0x0(0)
Last flood scan length is 1, maximum is 2
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 1.1.1.1 (Backup Designated Router)
Suppress hello for 0 neighbor(s)
R2#show ip ospf database //查看ospf数据库
Link ID ADV Router Age Seq# Checksum Link count
1.1.1.1 1.1.1.1 1945 0x80000003 0x002FFF 1
2.2.2.2 2.2.2.2 1925 0x80000004 0x003FFC 3
3.3.3.3 3.3.3.3 1926 0x80000003 0x0058D4 2
4.4.4.4 4.4.4.4 1926 0x80000003 0x009281 2
Link ID ADV Router Age Seq# Checksum
172.16.12.2 2.2.2.2 1944 0x80000001 0x00BB9F
172.16.234.2 2.2.2.2 1925 0x80000001 0x009DC2
Link ID ADV Router Age Seq# Checksum Tag
0.0.0.0 1.1.1.1 1970 0x80000001 0x001D91 1