动态路由——OSPF高级配置 实验篇
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态路由——OSPF高级配置 实验篇相关的知识,希望对你有一定的参考价值。
搭建OSPF高级配置实验搭建拓扑图
在GNS 3
中拓扑区域添加6台路由设别,其中一台R6路由设备作为网络运营商提供的网络设备路由,在R3
路由设备中添加两块单口业务单板,分别用于连接外部网络路由与PC机;添加四台PC机与路由设备连接,其中PC3
作为网络运营商的服务器设备,与R3路由设备相连。其中划分三个区域area 0
、area 2
、RIP
;分别路由设备与PC
接口处标注网段信息,如图所示:
网段划分:
192.168.10.0/24
192.168.20.0/24
192.168.30.0/24
192.168.40.0/24
192.168.50.0/24
192.168.60.0/24
192.168.70.0/24
12.0.0.0/24
13.0.0.0/24
Router ID 划分:
R2
:2.2.2.2
R3
:3.3.3.3
R4
:4.4.4.4
搭建实验
1、首先在R1
路由设备中添加网段地址,并设置将R1
路由设备配置为默认路由。
R1#conf t //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#int f0/0 //进入f0/0接口
R1(config-if)#ip add 192.168.10.1 255.255.255.0 //添加IP地址
R1(config-if)#no shut //开启接口
R1(config-if)#
*Mar 1 00:01:10.451: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:01:11.451: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#int f0/1 //进入f0/1接口
R1(config-if)#ip add 192.168.20.1 255.255.255.0 //添加IP地址
R1(config-if)#no shut //开启接口
R1(config-if)#
*Mar 1 00:01:44.735: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 00:01:45.735: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R1(config-if)#exit //退出接口模式
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.20.2 //配置默认路由
R1(config)#do show ip route //查看路由表
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is 192.168.20.2 to network 0.0.0.0
C 192.168.10.0/24 is directly connected, FastEthernet0/0
C 192.168.20.0/24 is directly connected, FastEthernet0/1
S* 0.0.0.0/0 [1/0] via 192.168.20.2 //配置成功
2、进入R2
路由设备,配置接口地址,启动OSPF协议,设置宣告Router ID
、网段信息;设置静态路由用于连接默认路由网段,最后在OSPF
协议中注入直连网段信息与静态相连的默认路由网段信息。
R2#conf t //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#int f0/0 //进入f0/0接口
R2(config-if)#ip add 192.168.30.1 255.255.255.0 //添加IP地址
R2(config-if)#no shut //开启接口
R2(config-if)#
*Mar 1 00:11:10.515: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:11:11.515: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2(config-if)#int f0/1 //进入f0/1接口
R2(config-if)#ip add 192.168.20.2 255.255.255.0 //添加IP地址
R2(config-if)#no shut //开启接口
R2(config-if)#
*Mar 1 00:11:49.983: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 00:11:50.983: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R2(config-if)#exit
R2(config)#router ospf 1 //开启ospf协议,进程号为1
R2(config-router)#router-id 2.2.2.2 //设置并宣告Router ID
R2(config-router)#network 192.168.30.0 0.0.0.255 area 1 //在area 1区域中宣告网段信息
R2(config-router)#exit //退出ospf协议
R2(config)#ip route 192.168.10.0 255.255.255.0 192.168.20.1 //配置静态路由信息
R2(config)#router ospf 1 //进入ospf协议
R2(config-router)#redistribute connected subnets //注入直连网段信息
R2(config-router)#redistribute static subnets //注入默认路由网段信息
R2(config-router)#ex //退出协议
R2(config)#do show ip route //查看路由表信息
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C 192.168.30.0/24 is directly connected, FastEthernet0/0
S 192.168.10.0/24 [1/0] via 192.168.20.1 //成功添加网段信息
C 192.168.20.0/24 is directly connected, FastEthernet0/1
3、在R3路由设备中配置接口IP
地址;配置默认路由连接外部网段;开启OSPF
协议,设置Router ID
,并在区域中宣告网段,注入设置的外部默认路由网段信息。
R3#conf t //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#int f0/0 //进入f0/0接口
R3(config-if)#ip add 192.168.30.2 255.255.255.0 //添加IP地址
R3(config-if)#no shut //开启接口
R3(config-if)#
*Mar 1 00:42:41.963: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 00:42:42.963: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R3(config-if)#int f0/1 //进入f0/1接口
R3(config-if)#ip add 192.168.40.1 255.255.255.0 //添加IP地址
R3(config-if)#no shut //开启接口
R3(config-if)#
*Mar 1 00:43:23.963: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 00:43:24.963: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R3(config-if)#int f1/0 //进入f1/0接口
R3(config-if)#ip add 12.0.0.1 255.255.255.0 //添加IP地址
R3(config-if)#no shut //开启接口
R3(config-if)#
*Mar 1 00:44:01.631: %LINK-3-UPDOWN: Interface FastEthernet1/0, changed state to up
*Mar 1 00:44:02.631: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up
R3(config-if)#int f2/0 //进入f2/0接口
R3(config-if)#ip add 192.168.70.1 255.255.255.0 //添加IP地址
R3(config-if)#no shut //开启接口
R3(config-if)#
*Mar 1 00:44:41.015: %LINK-3-UPDOWN: Interface FastEthernet2/0, changed state to up
*Mar 1 00:44:42.015: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet2/0, changed state to up
R3(config-if)#do show ip int b //查看接口信息
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.30.2 YES manual up up
FastEthernet0/1 192.168.40.1 YES manual up up
FastEthernet1/0 12.0.0.1 YES manual up up
FastEthernet2/0 192.168.70.1 YES manual up up //成功添加网段
R3(config)#ip route 0.0.0.0 0.0.0.0 12.0.0.2 //配置默认路由,连接外部网段
R3(config)#router ospf 1 //开启ospf协议,进程号为1
R3(config-router)#router-id 3.3.3.3 //设置宣告Router ID
R3(config-router)#network 192.168.30.0 0.0.0.255 area 1 //在area 1区域中宣告网段信息,注意子网掩码写反码
R3(config-router)#
*Mar 1 00:47:50.531: %OSPF-5-ADJCHG: Process 1, Nbr 2.2.2.2 on FastEthernet0/0 from LOADING to FULL, Loading Done
R3(config-router)#network 192.168.40.0 0.0.0.255 area 0 //在area 0区域中宣告网段信息,注意子网掩码写反码
R3(config-router)#network 192.168.70.0 0.0.0.255 area 0
R3(config-router)#default-information originate //将外部路由网段注入ospf协议中
R3(config-router)#ex //退出
R3(config)#do show ip route //查看路由表
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is 12.0.0.2 to network 0.0.0.0
C 192.168.30.0/24 is directly connected, FastEthernet0/0
O E2 192.168.10.0/24 [110/20] via 192.168.30.1, 00:01:21, FastEthernet0/0
C 192.168.40.0/24 is directly connected, FastEthernet0/1
O E2 192.168.20.0/24 [110/20] via 192.168.30.1, 00:01:21, FastEthernet0/0
12.0.0.0/24 is subnetted, 1 subnets
C 12.0.0.0 is directly connected, FastEthernet1/0
C 192.168.70.0/24 is directly connected, FastEthernet2/0
S* 0.0.0.0/0 [1/0] via 12.0.0.2 //成功添加网段
4、在R4
路由设备添加接口IP
地址,启用RIP协议,启用版本2,关闭路由自动汇总功能,宣告网段信息,最后注入OSPF
协议,设置跳数为5
;启用OSPF
协议,设置Router ID
,并在区域中宣告网段,注入RIP
协议。
R4#conf t //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R4(config)#int f0/0 //进入f0/0接口
R4(config-if)#ip add 192.168.40.2 255.255.255.0 //添加IP地址
R4(config-if)#no shut //开启接口
R4(config-if)#
*Mar 1 01:03:22.375: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 01:03:23.375: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R4(config-if)#int f0/1 //进入f0/1接口
R4(config-if)#ip add 192.168.50.1 255.255.255.0 //添加IP地址
R4(config-if)#no shut //开启接口
R4(config-if)#
*Mar 1 01:03:57.519: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 01:03:58.519: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R4(config-if)#ex //退出接口模式
R4(config)#router rip //启用RIP协议
R4(config-router)#version 2 //启用版本2
R4(config-router)#no auto-summary //关闭路由自动汇总功能
R4(config-router)#network 192.168.50.0 //宣告网段
R4(config-router)#redistribute ospf 1 metric 5 //注入ospf协议,设置条数为5
R4(config-router)#ex //退出
R4(config)#router ospf 1 //开启ospf协议,进程号为1
R4(config-router)#router-id 4.4.4.4 //设置宣告Router ID
R4(config-router)#network 192.168.40.0 0.0.0.255 area 0 //在area 0区域中宣告网段信息,注意子网掩码写反码
R4(config-router)#
*Mar 1 01:10:09.027: %OSPF-5-ADJCHG: Process 1, Nbr 3.3.3.3 on FastEthernet0/0 from LOADING to FULL, Loading Done
R4(config-router)#redistribute rip subnets //注入RIP协议
R4(config-router)#ex //退出
R4(config)#do show ip route //查看路由表
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is 192.168.40.1 to network 0.0.0.0
O IA 192.168.30.0/24 [110/20] via 192.168.40.1, 00:01:30, FastEthernet0/0
O E2 192.168.10.0/24 [110/20] via 192.168.40.1, 00:01:30, FastEthernet0/0
C 192.168.40.0/24 is directly connected, FastEthernet0/0
O E2 192.168.20.0/24 [110/20] via 192.168.40.1, 00:01:30, FastEthernet0/0
C 192.168.50.0/24 is directly connected, FastEthernet0/1
O 192.168.70.0/24 [110/11] via 192.168.40.1, 00:01:30, FastEthernet0/0
O*E2 0.0.0.0/0 [110/1] via 192.168.40.1, 00:01:30, FastEthernet0/0 //成功学习网段信息
5、在R5
路由设备中添加接口IP地址,启用RIP
协议,并关闭自动汇总功能,宣告两个网段。
R5#conf t //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R5(config)#int f0/0 //进入f0/0接口
R5(config-if)#ip add 192.168.50.2 255.255.255.0 //添加IP地址
R5(config-if)#no shut //开启接口
R5(config-if)#
*Mar 1 01:27:42.539: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 01:27:43.539: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R5(config-if)#int f0/1 //进入接口f0/1
R5(config-if)#ip add 192.168.60.1 255.255.255.0 //添加IP地址
R5(config-if)#no shut //开启接口
R5(config-if)#
*Mar 1 01:28:17.635: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 01:28:18.635: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R5(config-if)#router rip //启用RIP协议
R5(config-router)#version 2 //启用版本2
R5(config-router)#no auto-summary //关闭自动汇总功能
R5(config-router)#network 192.168.50.0 //宣告网段信息
R5(config-router)#network 192.168.60.0
R5(config-router)#ex //退出
R5(config)#do show ip route //查看路由表
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is 192.168.50.1 to network 0.0.0.0
R 192.168.30.0/24 [120/5] via 192.168.50.1, 00:00:25, FastEthernet0/0
C 192.168.60.0/24 is directly connected, FastEthernet0/1
R 192.168.10.0/24 [120/5] via 192.168.50.1, 00:00:25, FastEthernet0/0
R 192.168.40.0/24 [120/5] via 192.168.50.1, 00:00:25, FastEthernet0/0
R 192.168.20.0/24 [120/5] via 192.168.50.1, 00:00:25, FastEthernet0/0
C 192.168.50.0/24 is directly connected, FastEthernet0/0
R 192.168.70.0/24 [120/5] via 192.168.50.1, 00:00:25, FastEthernet0/0
R* 0.0.0.0/0 [120/1] via 192.168.50.1, 00:00:26, FastEthernet0/0 //成功学习网段信息
6、在R6
路由设备中添加接口IP地址,然后配置静态路由。
R6#conf t //进入全局配置模式
Enter configuration commands, one per line. End with CNTL/Z.
R6(config)#int f0/0 //进入f0/0接口
R6(config-if)#ip add 12.0.0.2 255.255.255.0 //添加IP地址
R6(config-if)#no shut //开启接口
R6(config-if)#
*Mar 1 01:36:54.323: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar 1 01:36:55.323: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R6(config-if)#int f0/1 //进入接口f0/1
R6(config-if)#ip add 13.0.0.1 255.255.255.0 //添加IP地址
R6(config-if)#no shut //开启接口
R6(config-if)#
*Mar 1 01:37:26.223: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar 1 01:37:27.223: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R6(config-if)#ex //退出模式
R6(config)#ip route 192.168.0.0 255.255.0.0 12.0.0.1 //设置静态路由
R6(config)#do show ip route //查看路由表
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
E1 - OSPF external type 1, E2 - OSPF external type 2
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
12.0.0.0/24 is subnetted, 1 subnets
C 12.0.0.0 is directly connected, FastEthernet0/0
13.0.0.0/24 is subnetted, 1 subnets
C 13.0.0.0 is directly connected, FastEthernet0/1
S 192.168.0.0/16 [1/0] via 12.0.0.1 //网段添加成功
7、分别在PC
机中添加IP
地址,并测试网络互通性。
PC1> ip 192.168.10.2 192.168.10.1 //添加IP地址
Checking for duplicate address...
PC1 : 192.168.10.2 255.255.255.0 gateway 192.168.10.1
PC2> ip 192.168.70.2 192.168.70.1 //添加IP地址
Checking for duplicate address...
PC1 : 192.168.70.2 255.255.255.0 gateway 192.168.70.1
PC3> ip 13.0.0.2 13.0.0.1 //添加IP地址
Checking for duplicate address...
PC1 : 13.0.0.2 255.255.255.0 gateway 13.0.0.1
P4> ip 192.168.60.2 192.168.60.1 //添加IP地址
Checking for duplicate address...
PC1 : 192.168.60.2 255.255.255.0 gateway 192.168.60.1
PC1> ping 192.168.70.2 //测试PC1与PC2的互通性
192.168.70.2 icmp_seq=1 timeout
192.168.70.2 icmp_seq=2 timeout
84 bytes from 192.168.70.2 icmp_seq=3 ttl=61 time=53.853 ms
84 bytes from 192.168.70.2 icmp_seq=4 ttl=61 time=60.168 ms
84 bytes from 192.168.70.2 icmp_seq=5 ttl=61 time=57.781 ms //成功通信
PC1> ping 13.0.0.2 //测试PC1与PC3的互通性
13.0.0.2 icmp_seq=1 timeout
13.0.0.2 icmp_seq=2 timeout
84 bytes from 13.0.0.2 icmp_seq=3 ttl=60 time=76.872 ms
84 bytes from 13.0.0.2 icmp_seq=4 ttl=60 time=83.919 ms
84 bytes from 13.0.0.2 icmp_seq=5 ttl=60 time=77.712 ms //成功通信
PC1> ping 192.168.60.2 //测试PC1与P4的互通性
192.168.60.2 icmp_seq=1 timeout
84 bytes from 192.168.60.2 icmp_seq=2 ttl=59 time=97.596 ms
84 bytes from 192.168.60.2 icmp_seq=3 ttl=59 time=97.688 ms
84 bytes from 192.168.60.2 icmp_seq=4 ttl=59 time=99.732 ms
84 bytes from 192.168.60.2 icmp_seq=5 ttl=59 time=103.440 ms //成功通信
PC2> ping 13.0.0.2 //测试PC2与PC3的互通性
13.0.0.2 icmp_seq=1 timeout
13.0.0.2 icmp_seq=2 timeout
84 bytes from 13.0.0.2 icmp_seq=3 ttl=62 time=38.042 ms
84 bytes from 13.0.0.2 icmp_seq=4 ttl=62 time=37.842 ms
84 bytes from 13.0.0.2 icmp_seq=5 ttl=62 time=40.034 ms //成功通信
PC2> ping 192.168.60.2 //测试PC2与P4的互通性
192.168.60.2 icmp_seq=1 timeout
192.168.60.2 icmp_seq=2 timeout
84 bytes from 192.168.60.2 icmp_seq=3 ttl=61 time=56.783 ms
84 bytes from 192.168.60.2 icmp_seq=4 ttl=61 time=63.372 ms
84 bytes from 192.168.60.2 icmp_seq=5 ttl=61 time=53.795 ms //成功通信
PC3> ping 192.168.60.2 //测试PC3与P4的互通性
84 bytes from 192.168.60.2 icmp_seq=1 ttl=60 time=78.788 ms
84 bytes from 192.168.60.2 icmp_seq=2 ttl=60 time=79.786 ms
84 bytes from 192.168.60.2 icmp_seq=3 ttl=60 time=87.773 ms
84 bytes from 192.168.60.2 icmp_seq=4 ttl=60 time=84.850 ms
84 bytes from 192.168.60.2 icmp_seq=5 ttl=60 time=84.778 ms //成功通信
以上是关于动态路由——OSPF高级配置 实验篇的主要内容,如果未能解决你的问题,请参考以下文章
多种动态路由混合架构实验——OSPF协议+RIP协议+静态路由
OSPF动态路由协议(实验篇)OSPF协议的基本配置与虚链路的配置