一.搭建拓扑图
这里我们用颜色划分出两个区域area0和area1
二.实验前的准备以及OSPF的基本配置
1.配置网关
AR1
<Huawei>
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys shutiao1
[shutiao1]int g0/0/0
[shutiao1-GigabitEthernet0/0/0]ip ad
[shutiao1-GigabitEthernet0/0/0]ip address 192.168.3.1 24
[shutiao1-GigabitEthernet0/0/0]
Dec 26 2024 11:04:42-08:00 shutiao1 %%01IFNET/4/LINK_STATE(l)[0]:The line protoc
ol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
[shutiao1-GigabitEthernet0/0/0]int g0/0/1
[shutiao1-GigabitEthernet0/0/1]ip ad
[shutiao1-GigabitEthernet0/0/1]ip address 192.168.1.1 24
Dec 26 2024 11:04:52-08:00 shutiao1 %%01IFNET/4/LINK_STATE(l)[1]:The line protoc
ol IP on the interface GigabitEthernet0/0/1 has entered the UP state.
[shutiao1-GigabitEthernet0/0/1]int g0/0/2
[shutiao1-GigabitEthernet0/0/2]ip ad
[shutiao1-GigabitEthernet0/0/2]ip address 192.168.2.1 24
[shutiao1-GigabitEthernet0/0/2]
Dec 26 2024 11:05:05-08:00 shutiao1 %%01IFNET/4/LINK_STATE(l)[2]:The line protoc
ol IP on the interface GigabitEthernet0/0/2 has entered the UP state.
[shutiao1-GigabitEthernet0/0/2]q
AR32
<Huawei>
<Huawei>
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys shutiao2
[shutiao2]int g0/0/0
[shutiao2-GigabitEthernet0/0/0]ip ad
[shutiao2-GigabitEthernet0/0/0]ip address 192.168.3.2 24
Dec 26 2024 11:05:26-08:00 shutiao2 %%01IFNET/4/LINK_STATE(l)[0]:The line protoc
ol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
[shutiao2-GigabitEthernet0/0/0]int g0/0/1
[shutiao2-GigabitEthernet0/0/1]ip ad
[shutiao2-GigabitEthernet0/0/1]ip address 192.168.4.1 24
Dec 26 2024 11:05:39-08:00 shutiao2 %%01IFNET/4/LINK_STATE(l)[1]:The line protoc
ol IP on the interface GigabitEthernet0/0/1 has entered the UP state.
[shutiao2-GigabitEthernet0/0/1]q
AR3
<Huawei>
<Huawei>sys
Enter system view, return user view with Ctrl+Z.
[Huawei]sys shutiao3
[shutiao3]int g0/0/0
[shutiao3-GigabitEthernet0/0/0]ip ad
[shutiao3-GigabitEthernet0/0/0]ip address 192.168.4.2 24
Dec 26 2024 11:05:58-08:00 shutiao3 %%01IFNET/4/LINK_STATE(l)[0]:The line protoc
ol IP on the interface GigabitEthernet0/0/0 has entered the UP state.
[shutiao3-GigabitEthernet0/0/0]int g0/0/1
[shutiao3-GigabitEthernet0/0/1]ip ad
[shutiao3-GigabitEthernet0/0/1]ip address 192.168.5.1 24
Dec 26 2024 11:06:10-08:00 shutiao3 %%01IFNET/4/LINK_STATE(l)[1]:The line protoc
ol IP on the interface GigabitEthernet0/0/1 has entered the UP state.
[shutiao3-GigabitEthernet0/0/1]int g0/0/2
[shutiao3-GigabitEthernet0/0/2]ip ad
[shutiao3-GigabitEthernet0/0/2]ip address 192.168.6.1 24
Dec 26 2024 11:06:36-08:00 shutiao3 %%01IFNET/4/LINK_STATE(l)[2]:The line protoc
ol IP on the interface GigabitEthernet0/0/2 has entered the UP state.
[shutiao3-GigabitEthernet0/0/2]Q
2.DHCP的配置
这里我们顺便复习一下DHCP的基本配置
AR1
[shutiao1]dhcp en
[shutiao1]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[shutiao1]ip pool shutiao1
Info: It's successful to create an IP address pool.
[shutiao1-ip-pool-shutiao1]net
[shutiao1-ip-pool-shutiao1]netbios-type
[shutiao1-ip-pool-shutiao1]network 192.168.1.0 ma
[shutiao1-ip-pool-shutiao1]network 192.168.1.0 mask 24
[shutiao1-ip-pool-shutiao1]ga
[shutiao1-ip-pool-shutiao1]gateway-list 192.168.1.1
[shutiao1-ip-pool-shutiao1]int g0/0/1
[shutiao1-GigabitEthernet0/0/1]dh
[shutiao1-GigabitEthernet0/0/1]dhcp s
[shutiao1-GigabitEthernet0/0/1]dhcp select g
[shutiao1-GigabitEthernet0/0/1]dhcp select global
[shutiao1-GigabitEthernet0/0/1]q
[shutiao1]ip pool shutiao2
Info: It's successful to create an IP address pool.
[shutiao1-ip-pool-shutiao2]netw
[shutiao1-ip-pool-shutiao2]network 192.168.2.0 mas
[shutiao1-ip-pool-shutiao2]network 192.168.2.0 mask 24
[shutiao1-ip-pool-shutiao2]ga
[shutiao1-ip-pool-shutiao2]gateway-list 192.168.2.1
[shutiao1-ip-pool-shutiao2]int g0/0/2
[shutiao1-GigabitEthernet0/0/2]dh
[shutiao1-GigabitEthernet0/0/2]dhcp s
[shutiao1-GigabitEthernet0/0/2]dhcp select g
[shutiao1-GigabitEthernet0/0/2]dhcp select global
[shutiao1-GigabitEthernet0/0/2]q
AR3
[shutiao3]dh
[shutiao3]dhcp en
[shutiao3]dhcp enable
Info: The operation may take a few seconds. Please wait for a moment.done.
[shutiao3]ip poo
[shutiao3]ip pool shutiao1
Info: It's successful to create an IP address pool.
[shutiao3-ip-pool-shutiao1]net
[shutiao3-ip-pool-shutiao1]netbios-type
[shutiao3-ip-pool-shutiao1]network 192.168.5.0 ma
[shutiao3-ip-pool-shutiao1]network 192.168.5.0 mask 24
[shutiao3-ip-pool-shutiao1]ga
[shutiao3-ip-pool-shutiao1]gateway-list 192.168.5.1
[shutiao3-ip-pool-shutiao1]int g0/0/1
[shutiao3-GigabitEthernet0/0/1]dh
[shutiao3-GigabitEthernet0/0/1]dhcp s
[shutiao3-GigabitEthernet0/0/1]dhcp selectg
[shutiao3-GigabitEthernet0/0/1]dhcp select g
[shutiao3-GigabitEthernet0/0/1]dhcp select global
[shutiao3-GigabitEthernet0/0/1]q
[shutiao3]ip poo
[shutiao3]ip pool shutiao2
Info: It's successful to create an IP address pool.
[shutiao3-ip-pool-shutiao2]netw
[shutiao3-ip-pool-shutiao2]network 192.168.6.0 ma
[shutiao3-ip-pool-shutiao2]network 192.168.6.0 mask 24
[shutiao3-ip-pool-shutiao2]ga
[shutiao3-ip-pool-shutiao2]gateway-list 192.168.6.1
[shutiao3-ip-pool-shutiao2]int g0/0/2
[shutiao3-GigabitEthernet0/0/2]dh
[shutiao3-GigabitEthernet0/0/2]dhcp s
[shutiao3-GigabitEthernet0/0/2]dhcp select g
[shutiao3-GigabitEthernet0/0/2]dhcp select global
[shutiao3-GigabitEthernet0/0/2]q
这里我们查看一下PC段的分配情况
清楚的看到DHCP成功配置(如果忘记的话,可以去看之前的关于DHCP的基本配置详细讲解)
3.OSPF的基本配置
第一步:启动OSPF协议,分配进程号和RID
第二步:进入相对应的区域
第三步:精准宣告(反掩码均为0.0.0.0)------宣告某一个接口所在的网段
AR1
[shutiao1]os
[shutiao1]ospf 1 ro
[shutiao1]ospf 1 router-id 1.1.1.1
[shutiao1-ospf-1]are
[shutiao1-ospf-1]area 0
[shutiao1-ospf-1-area-0.0.0.0]netw
[shutiao1-ospf-1-area-0.0.0.0]network 192.168.1.1 0.0.0.0
[shutiao1-ospf-1-area-0.0.0.0]net
[shutiao1-ospf-1-area-0.0.0.0]network 192.168.2.1 0.0.0.0
[shutiao1-ospf-1-area-0.0.0.0]netw
[shutiao1-ospf-1-area-0.0.0.0]network 192.168.3.1 0.0.0.0
AR2
[shutiao2]ospf 1 r
[shutiao2]ospf 1 router-id 2.2.2.2
Info: The configuration succeeded. You need to restart the OSPF process to valid
ate the new router ID.
[shutiao2-ospf-1]are
[shutiao2-ospf-1]area 0
[shutiao2-ospf-1-area-0.0.0.0]ne
[shutiao2-ospf-1-area-0.0.0.0]network 192.168.3.2 0.0.0.0
[shutiao2-ospf-1-area-0.0.0.0]are
[shutiao2-ospf-1-area-0.0.0.0]area 1
[shutiao2-ospf-1-area-0.0.0.1]net
[shutiao2-ospf-1-area-0.0.0.1]network 192.168.4.1 0.0.0.0
特别注意这里进去接口相对应的区域!!!
AR3
[shutiao3]os
[shutiao3]ospf 1 ro
[shutiao3]ospf 1 router-id 3.3.3.3
[shutiao3-ospf-1]ar
[shutiao3-ospf-1]area 1
[shutiao3-ospf-1-area-0.0.0.1]net
[shutiao3-ospf-1-area-0.0.0.1]network 192.168.4.2 0.0.0.0
[shutiao3-ospf-1-area-0.0.0.1]net
[shutiao3-ospf-1-area-0.0.0.1]network
[shutiao3-ospf-1-area-0.0.0.1]network 192.168.5.1 0.0.0.0
[shutiao3-ospf-1-area-0.0.0.1]netw
[shutiao3-ospf-1-area-0.0.0.1]network 192.168.6.1 0.0.0.0
查看一下AR1的路由表
[shutiao1]dis ip rou
[shutiao1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 16 Routes : 16
Destination/Mask Proto Pre Cost Flags NextHop Interface
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 Direct 0 0 D 192.168.1.1 GigabitEthernet
0/0/1
192.168.1.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
192.168.1.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
192.168.2.0/24 Direct 0 0 D 192.168.2.1 GigabitEthernet
0/0/2
192.168.2.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
192.168.2.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/2
192.168.3.0/24 Direct 0 0 D 192.168.3.1 GigabitEthernet
0/0/0
192.168.3.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
192.168.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
192.168.4.0/24 OSPF 10 2 D 192.168.3.2 GigabitEthernet
0/0/0
192.168.5.0/24 OSPF 10 3 D 192.168.3.2 GigabitEthernet
0/0/0
192.168.6.0/24 OSPF 10 3 D 192.168.3.2 GigabitEthernet
0/0/0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
AR2
<shutiao2>dis ip ro
<shutiao2>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost Flags NextHop Interface
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
192.168.1.0/24 OSPF 10 2 D 192.168.3.1 GigabitEthernet
0/0/0
192.168.2.0/24 OSPF 10 2 D 192.168.3.1 GigabitEthernet
0/0/0
192.168.3.0/24 Direct 0 0 D 192.168.3.2 GigabitEthernet
0/0/0
192.168.3.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
192.168.3.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/0
192.168.4.0/24 Direct 0 0 D 192.168.4.1 GigabitEthernet
0/0/1
192.168.4.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
192.168.4.255/32 Direct 0 0 D 127.0.0.1 GigabitEthernet
0/0/1
192.168.5.0/24 OSPF 10 2 D 192.168.4.2 GigabitEthernet
0/0/1
192.168.6.0/24 OSPF 10 2 D 192.168.4.2 GigabitEthernet
0/0/1
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
到这里OSPF的基本配置已经结束
三.检验
[shutiao1]ping 192.168.6.253
PING 192.168.6.253: 56 data bytes, press CTRL_C to break
Request time out
Reply from 192.168.6.253: bytes=56 Sequence=2 ttl=126 time=80 ms
Reply from 192.168.6.253: bytes=56 Sequence=3 ttl=126 time=60 ms
Reply from 192.168.6.253: bytes=56 Sequence=4 ttl=126 time=70 ms
Reply from 192.168.6.253: bytes=56 Sequence=5 ttl=126 time=70 ms
--- 192.168.6.253 ping statistics ---
5 packet(s) transmitted
4 packet(s) received
20.00% packet loss
round-trip min/avg/max = 60/70/80 ms
整个实验就结束啦!
恭喜你,成功掌握OSPF的基本配置!!!
学无止境