拓扑图
一、R1 路由器
<Huawei> sys
[Huawei]sys R1
[R1]un in en
[R1]dhcp enable
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip addr 192.168.20.2 24
# 配置DHCP
[R1-GigabitEthernet0/0/0]int g0/0/1
[R1-GigabitEthernet0/0/1]ip addr 192.168.10.1 24
[R1-GigabitEthernet0/0/1]dhcp select int
[R1-GigabitEthernet0/0/1]quit
# 配置OSPF
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
二、R2 路由器
[Huawei]sys R2
[R2]un in en
[R2]int g0/0/1
[R2-GigabitEthernet0/0/1]ip addr 192.168.30.1 24
[R2-GigabitEthernet0/0/1]int g0/0/0
[R2-GigabitEthernet0/0/0]ip addr 192.168.20.1 24
[R2-GigabitEthernet0/0/0]quit
# 配置OSPF
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
三、R3 路由器
[Huawei]sys R3
[R3]un in en
[R3]dhcp enable
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip addr 192.168.30.2 24
[R3-GigabitEthernet0/0/0]int g0/0/1
[R3-GigabitEthernet0/0/1]ip addr 192.168.40.1 24
[R3-GigabitEthernet0/0/1]dhcp select int
[R3-GigabitEthernet0/0/1]quit
# 配置OSPF
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 192.168.40.0 0.0.0.255
四、验证
1、R1 查看邻居表
# 只有 2.2.2.2 一个邻居ID
[R1]dis ospf peer
OSPF Process 1 with Router ID 1.1.1.1
Neighbors
Area 0.0.0.0 interface 192.168.20.2(GigabitEthernet0/0/0)'s neighbors
Router ID: 2.2.2.2 Address: 192.168.20.1
State: Full Mode:Nbr is Master Priority: 1
DR: 192.168.20.1 BDR: 192.168.20.2 MTU: 0
Dead timer due in 37 sec
Retrans timer interval: 5
Neighbor is up for 00:13:35
Authentication Sequence: [ 0 ]
[R1]dis ospf peer brief
OSPF Process 1 with Router ID 1.1.1.1
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 2.2.2.2 Full
----------------------------------------------------------------------------
2、R2 查看邻居表
# 可以看到有 3.3.3.3,1.1.1.1 2个邻居
[R2]dis ospf peer
OSPF Process 1 with Router ID 2.2.2.2
Neighbors
Area 0.0.0.0 interface 192.168.30.1(GigabitEthernet0/0/1)'s neighbors
Router ID: 3.3.3.3 Address: 192.168.30.2
State: Full Mode:Nbr is Master Priority: 1
DR: 192.168.30.2 BDR: 192.168.30.1 MTU: 0
Dead timer due in 32 sec
Retrans timer interval: 5
Neighbor is up for 00:15:27
Authentication Sequence: [ 0 ]
Neighbors
Area 0.0.0.0 interface 192.168.20.1(GigabitEthernet0/0/0)'s neighbors
Router ID: 1.1.1.1 Address: 192.168.20.2
State: Full Mode:Nbr is Slave Priority: 1
DR: 192.168.20.1 BDR: 192.168.20.2 MTU: 0
Dead timer due in 37 sec
Retrans timer interval: 5
Neighbor is up for 00:15:35
Authentication Sequence: [ 0 ]
[R2]dis ospf peer brief
OSPF Process 1 with Router ID 2.2.2.2
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 3.3.3.3 Full
0.0.0.0 GigabitEthernet0/0/0 1.1.1.1 Full
----------------------------------------------------------------------------
[R2]dis ospf peer brief
OSPF Process 1 with Router ID 2.2.2.2
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/1 3.3.3.3 Full
0.0.0.0 GigabitEthernet0/0/0 1.1.1.1 Full
----------------------------------------------------------------------------
3、R3 查看邻居表
# 只有一个 2.2.2.2 邻居
<R3>dis ospf peer
OSPF Process 1 with Router ID 3.3.3.3
Neighbors
Area 0.0.0.0 interface 192.168.30.2(GigabitEthernet0/0/0)'s neighbors
Router ID: 2.2.2.2 Address: 192.168.30.1
State: Full Mode:Nbr is Slave Priority: 1
DR: 192.168.30.2 BDR: 192.168.30.1 MTU: 0
Dead timer due in 33 sec
Retrans timer interval: 5
Neighbor is up for 00:17:49
Authentication Sequence: [ 0 ]
[R3]dis ospf peer brief
OSPF Process 1 with Router ID 3.3.3.3
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 2.2.2.2 Full
----------------------------------------------------------------------------
五、验证互通
# 成功标签:ospf,0.0,GigabitEthernet0,192.168,R1,华为,2.2,OSPF,路由器 From: https://blog.51cto.com/mshxuyi/6022292
PC1>ping 192.168.40.254
Ping 192.168.40.254: 32 data bytes, Press Ctrl_C to break
From 192.168.40.254: bytes=32 seq=1 ttl=125 time=15 ms
From 192.168.40.254: bytes=32 seq=2 ttl=125 time=32 ms
From 192.168.40.254: bytes=32 seq=3 ttl=125 time=31 ms
From 192.168.40.254: bytes=32 seq=4 ttl=125 time=31 ms
From 192.168.40.254: bytes=32 seq=5 ttl=125 time=16 ms
--- 192.168.40.254 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 15/25/32 ms