搭建OSPF多区域配置

实验环境

GNS 3中搭建实验环境

GNS 3下载地址 路由设备镜像文件

搭建实验拓扑图

GNS 3软件中添加4个路由设别,与两台PC机,在交换机R1R3中添加业务单板,用于连接两台PC机,然后用连接线分别将4路由设别与两台PC机连接起来,并在拓扑图中开启接口信息,标注划分的IP地址信息,最后在用工具在拓扑图中标注划分的不同区域(area0area1)如图所示:
动态路由——OSPF多区域配置 实验篇 (三)_第1张图片
动态路由——OSPF多区域配置 实验篇 (三)_第2张图片

划分的网段:

  • 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

Router ID划分

  • R11.1.1.1
  • R22.2.2.2
  • R33.3.3.3
  • R44.4.4.4

搭建多区域配置

1、开启全部设别,并打开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.20.1 255.255.255.0   //添加IP地址
R1(config-if)#no shut         //开启接口
R1(config-if)#
*Mar  1 00:01:56.163: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:01:57.163: %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.50.2 255.255.255.0    //添加IP地址
R1(config-if)#no shut         //开启接口
R1(config-if)#
*Mar  1 00:02:31.639: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar  1 00:02:32.639: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R1(config-if)#int f1/0          //进入f1/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:03:16.431: %LINK-3-UPDOWN: Interface FastEthernet1/0, changed state to up
*Mar  1 00:03:17.431: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up
R1(config-if)#do show ip int b           //查看IP地址是否配置成功
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.20.1    YES manual up                    up      
FastEthernet0/1            192.168.50.2    YES manual up                    up      
FastEthernet1/0            192.168.10.1    YES manual up                    up  

2、打开R2路由设备,进入配置接口网段信息。

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.20.2 255.255.255.0          //添加IP地址
R2(config-if)#no shut         //开启接口
R2(config-if)#
*Mar  1 00:07:46.395: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:07:47.395: %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.30.1 255.255.255.0      //添加IP地址
R2(config-if)#no shut         //开启接口
R2(config-if)#
*Mar  1 00:08:20.979: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar  1 00:08:21.979: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R2(config-if)#do show ip int b        //查看IP地址是否配置成功
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.20.2    YES manual up                    up      
FastEthernet0/1            192.168.30.1    YES manual up                    up  

3、打开R3由设备,进入配置接口网段信息。

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:12:29.019: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:12:30.019: %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:13:05.091: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar  1 00:13:06.091: %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 192.168.60.1 255.255.255.0      //添加IP地址
R3(config-if)#no shutt         //开启接口
R3(config-if)#
*Mar  1 00:13:50.719: %LINK-3-UPDOWN: Interface FastEthernet1/0, changed state to up
*Mar  1 00:13:51.719: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up
R3(config-if)#do show ip int b        //查看IP地址是否配置成功
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            192.168.60.1    YES manual up                    up 

4、打开R4由设备,进入配置接口网段信息。

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 00:17:23.547: %LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
*Mar  1 00:17:24.547: %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 00:18:02.799: %LINK-3-UPDOWN: Interface FastEthernet0/1, changed state to up
*Mar  1 00:18:03.799: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R4(config-if)#do show ip int b        //查看IP地址是否配置成功
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.40.2    YES manual up                    up      
FastEthernet0/1            192.168.50.1    YES manual up                    up

5、回到R1路由设备中,配置回环网卡,添加Router IDR2R3R4路由设备中同样操作。

R1(config)#int loopback 0            //进入回环网卡接口     
R1(config-if)#
*Mar  1 00:23:09.519: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R1(config-if)#ip add 1.1.1.1 255.255.255.255       //配置Router ID
R1(config-if)#no shut
R1(config-if)#do show ip int b           //查看回环网卡地址是否配置成功
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.20.1    YES manual up                    up      
FastEthernet0/1            192.168.50.2    YES manual up                    up      
FastEthernet1/0            192.168.10.1    YES manual up                    up      
Loopback0                  1.1.1.1         YES manual up                    up  
R2(config)#int loopback 0
R2(config-if)#
*Mar  1 00:25:49.879: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R2(config-if)#ip add 2.2.2.2 255.255.255.255
R2(config-if)#no shut
R2(config-if)#do show ip int b
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.20.2    YES manual up                    up      
FastEthernet0/1            192.168.30.1    YES manual up                    up      
Loopback0                  2.2.2.2         YES manual up                    up  
R3(config)#int loopback 0
R3(config-if)#
*Mar  1 00:29:09.423: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R3(config-if)#ip add 3.3.3.3 255.255.255.255
R3(config-if)#no shut
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            192.168.60.1    YES manual up                    up      
Loopback0                  3.3.3.3         YES manual up                    up  
R4(config)#int loopback 0
R4(config-if)#i
*Mar  1 00:30:26.755: %LINEPROTO-5-UPDOWN: Line protocol on Interface Loopback0, changed state to up
R4(config-if)#ip add 4.4.4.4 255.255.255.255
R4(config-if)#no shut
R4(config-if)#do show ip int b 
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.40.2    YES manual up                    up      
FastEthernet0/1            192.168.50.1    YES manual up                    up      
Loopback0                  4.4.4.4         YES manual up                    up  

6、在路由设备中启动OSPF协议,并区域中宣告Router ID信息与网段信息。

R1(config)#router ospf 1          //启动OSPF协议,进程号为1
R1(config-router)#router-id 1.1.1.1     //宣告Router ID 
R1(config-router)#network 192.168.20.0 0.0.0.255 area 0  //R1设备在area 0区域中宣告网段信息,注意子网掩码要写反码
R1(config-router)#network 192.168.50.0 0.0.0.255 area 0
R1(config-router)#network 192.168.10.0 0.0.0.255 area 0
R2(config)#router ospf 1              //在R2路由设备中启动OSPF协议,进程号为1
R2(config-router)#router-id 2.2.2.2   //宣告Router ID 
R2(config-router)#network 192.168.20.0 0.0.0.255 area 0 //此网段在area 0区域中宣告网段信息,注意子网掩码要写反码
R2(config-router)#
*Mar  1 00:46:07.555: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on FastEthernet0/0 from LOADING to FULL, Loading Done
R2(config-router)#network 192.168.30.0 0.0.0.255 area 1 //此网段在area 1区域中宣告网段信息,注意子网掩码要写反码
R2(config-router)#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

     2.0.0.0/32 is subnetted, 1 subnets
C       2.2.2.2 is directly connected, Loopback0
C    192.168.30.0/24 is directly connected, FastEthernet0/1
C    192.168.20.0/24 is directly connected, FastEthernet0/0
O    192.168.10.0/24 [110/11] via 192.168.20.1, 00:00:45, FastEthernet0/0
O    192.168.50.0/24 [110/20] via 192.168.20.1, 00:00:33, FastEthernet0/0    //成功学习到R1设备中网段信息
R3(config)#router ospf 1            //在R3路由设备中启动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:53:09.751: %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 1 //此网段在area 1区域中宣告网段信息,注意子网掩码要写反码
R3(config-router)#network 192.168.60.0 0.0.0.255 area 1
R3(config-router)#
*Mar  1 01:04:49.075: %SYS-5-CONFIG_I: Configured from console by console
R3(config-router)#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

     3.0.0.0/32 is subnetted, 1 subnets
C       3.3.3.3 is directly connected, Loopback0
C    192.168.30.0/24 is directly connected, FastEthernet0/0
C    192.168.60.0/24 is directly connected, FastEthernet1/0
O IA 192.168.10.0/24 [110/21] via 192.168.40.2, 00:01:33, FastEthernet0/1
                     [110/21] via 192.168.30.1, 00:01:33, FastEthernet0/0
C    192.168.40.0/24 is directly connected, FastEthernet0/1
O IA 192.168.20.0/24 [110/20] via 192.168.30.1, 00:01:14, FastEthernet0/0
O IA 192.168.50.0/24 [110/30] via 192.168.30.1, 00:01:14, FastEthernet0/0    //成功学习网段信息
R4(config)#router ospf 1             //在R4路由设备中启动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 1  //此网段在area 1区域中宣告网段信息,注意子网掩码要写反码
R4(config-router)#
*Mar  1 01:01:18.223: %OSPF-5-ADJCHG: Process 1, Nbr 3.3.3.3 on FastEthernet0/0 from LOADING to FULL, Loading Done
R4(config-router)#network 192.168.50.0 0.0.0.255 area 0  //此网段在area 0区域中宣告网段信息,注意子网掩码要写反码
R4(config-router)#
*Mar  1 01:01:44.507: %OSPF-5-ADJCHG: Process 1, Nbr 1.1.1.1 on FastEthernet0/1 from LOADING to FULL, Loading Done
R4(config-router)#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

O    192.168.30.0/24 [110/20] via 192.168.40.1, 00:09:36, FastEthernet0/0
O    192.168.60.0/24 [110/11] via 192.168.40.1, 00:06:40, FastEthernet0/0
     4.0.0.0/32 is subnetted, 1 subnets
C       (1)4.4.4.4 is directly connected, Loopback0   //添加(1)是违禁词汇处理
O    192.168.10.0/24 [110/11] via 192.168.50.2, 00:03:12, FastEthernet0/1
C    192.168.40.0/24 is directly connected, FastEthernet0/0
O    192.168.20.0/24 [110/20] via 192.168.50.2, 00:09:21, FastEthernet0/1
C    192.168.50.0/24 is directly connected, FastEthernet0/1                  //成功学习所有网段信息

7、分别给两台PC机添加IP地址,并用ping命令测试两台PC机是否成功通信。

PC1> ip 192.168.10.2 192.168.10.1         //在PC1中添加IP地址
Checking for duplicate address...
PC1 : 192.168.10.2 255.255.255.0 gateway 192.168.10.1   //添加成功
PC2> ip 192.168.60.2 192.168.60.1        //在PC2中添加IP地址
Checking for duplicate address...
PC1 : 192.168.60.2 255.255.255.0 gateway 192.168.60.1  //添加成功
PC1> ping 192.168.60.2                  //使用ping命令与PC2通信
192.168.60.2 icmp_seq=1 timeout
84 bytes from 192.168.60.2 icmp_seq=2 ttl=61 time=54.935 ms
84 bytes from 192.168.60.2 icmp_seq=3 ttl=61 time=63.006 ms
84 bytes from 192.168.60.2 icmp_seq=4 ttl=61 time=47.872 ms
84 bytes from 192.168.60.2 icmp_seq=5 ttl=61 time=45.075 ms       //成功与PC2通信