组建规模较大的园区网常采用核心、汇聚和接入三层架构,这种架构可以较好的分摊流量,减轻核心交换机的压力。这次带学生做路由的实验,就设计了这样一个使用OSPF或RIP协议实现企业三层内网互通的实验。
IP地址规划:
假设企业有9个vlan,vlan1用于管理vlan,vlan2-9是用户使用的vlan。
vlan1:192.168.1.0/24
vlan2:192.168.2.0/24
...
vlan9:192.168.9.0/24
实验拓扑图:
实验步骤:
1、在汇聚层和接入层交换机上创建相应的vlan并实现vlan间通信。
1.1 汇聚层交换机的配置:
Switch#config t
Switch(config)#hostname CollectiveSW1
CollectiveSW1(config)#vlan 2
CollectiveSW1(config-vlan)#exit
CollectiveSW1(config)#vlan 3
CollectiveSW1(config-vlan)#exit
CollectiveSW1(config)#vlan 4
CollectiveSW1(config-vlan)#exit
CollectiveSW1(config)#vlan 5
CollectiveSW1(config-vlan)#exit
CollectiveSW1(config)#int vlan 2
CollectiveSW1(config-if)#ip add 192.168.2.254 255.255.255.0
CollectiveSW1(config-if)#no sh
CollectiveSW1(config-if)#exit
CollectiveSW1(config)#int vlan 3
CollectiveSW1(config-if)#ip add 192.168.3.254 255.255.255.0
CollectiveSW1(config-if)#no sh
CollectiveSW1(config-if)#exit
CollectiveSW1(config)#int vlan 4
CollectiveSW1(config-if)#ip add 192.168.4.254 255.255.255.0
CollectiveSW1(config-if)#no sh
CollectiveSW1(config-if)#exit
CollectiveSW1(config)#int vlan 5
CollectiveSW1(config-if)#ip add 192.168.5.254 255.255.255.0
CollectiveSW1(config-if)#no sh
CollectiveSW1(config-if)#exit
CollectiveSW1(config)#int f0/2
CollectiveSW1(config-if)#switchport trunk encapsulation dot1q
CollectiveSW1(config-if)#switchport mode trunk
CollectiveSW1(config-if)#switchport trunk allowed vlan all
CollectiveSW1(config-if)#exit
CollectiveSW1(config)#int f0/3
CollectiveSW1(config-if)#switchport trunk encapsulation dot1q
CollectiveSW1(config-if)#switchport mode trunk
CollectiveSW1(config-if)#switchport trunk allowed vlan all
CollectiveSW1(config)#ip routing /*启用三层交换机的路由功能*/
1.2 接入层交换机的配置:
Switch#config t
Switch(config)#hostname AccessSW1
AccessSW1(config)#vlan 2
AccessSW1(config-vlan)#exit
AccessSW1(config)#vlan 3
AccessSW1(config-vlan)#exit
AccessSW1(config)#int f0/2
AccessSW1(config-if)#switchport mode access
AccessSW1(config-if)#switchport access vlan 2
AccessSW1(config-if)#exit
AccessSW1(config)#int f0/3
AccessSW1(config-if)#switchport mode access
AccessSW1(config-if)#switchport access vlan 3
AccessSW1(config-if)#exit
AccessSW1(config)#int f0/1
AccessSW1(config-if)#switchport mode trunk
AccessSW1(config-if)#switchport trunk allowed vlan all
AccessSW1(config-if)#exit
AccessSW1(config)#int vlan 1
AccessSW1(config-if)#ip address 192.168.1.253 255.255.255.0 /*管理IP*/
AccessSW1(config-if)#no shutdown
AccessSW1(config-if)#exit
AccessSW1(config)#ip default-gateway 192.168.1.254
其他几个汇聚交换机和接入交换机的配置与上述类似,就不列出配置清单了。至此,在同一个汇聚交换机下所有的vlan都可以互通了,但不同汇聚交换机下的vlan不通。
2、配置动态路由协议实现全网互通
2.1 在核心交换机上配置vlan1 的地址及OSPF路由协议:
Switch#config t
Switch(config)#hostname CoreSW1
CoreSW1(config)#int vlan 1
CoreSW1(config-if)#ip add 192.168.1.254 255.255.255.0
CoreSW1(config-if)#no sh
CoreSW1(config-if)#exit
CoreSW1(config)#ip routing
CoreSW1(config)#router ospf 1
CoreSW1(config-router)#network 192.168.1.0 0.0.0.255 area 0
2.2 在汇聚层交换机上配置接口IP及OSPF路由协议:
CollectiveSW1(config)#int f0/1
CollectiveSW1(config-if)#no switchport /*把这个接口设置为三层接口(只有三层接口才可以配置ip地址)*/
CollectiveSW1(config-if)#ip address 192.168.1.2 255.255.255.0
CollectiveSW1(config-if)#no sh
CollectiveSW1(config-if)#exit
CollectiveSW1(config)#router ospf 1
CollectiveSW1(config-router)#network 192.168.1.0 0.0.0.255 area 0
CollectiveSW1(config-router)#network 192.168.2.0 0.0.0.255 area 0
CollectiveSW1(config-router)#network 192.168.3.0 0.0.0.255 area 0
CollectiveSW1(config-router)#network 192.168.4.0 0.0.0.255 area 0
CollectiveSW1(config-router)#network 192.168.5.0 0.0.0.255 area 0
CollectiveSW2(config)#int f0/1
CollectiveSW2(config-if)#no switchport
CollectiveSW2(config-if)#ip address 192.168.1.3 255.255.255.0
CollectiveSW2(config-if)#no sh
CollectiveSW2(config-if)#exit
CollectiveSW2(config)#router ospf 1
CollectiveSW2(config-router)#network 192.168.1.0 0.0.0.255 area 0
CollectiveSW2(config-router)#network 192.168.6.0 0.0.0.255 area 0
CollectiveSW2(config-router)#network 192.168.7.0 0.0.0.255 area 0
CollectiveSW2(config-router)#network 192.168.8.0 0.0.0.255 area 0
CollectiveSW2(config-router)#network 192.168.9.0 0.0.0.255 area 0
3、查看路由表及OSPF邻居:
CoreSW1#show ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, 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.1.0/24 is directly connected, Vlan1
O 192.168.2.0/24 [110/2] via 192.168.1.2, 00:16:32, Vlan1
O 192.168.3.0/24 [110/2] via 192.168.1.2, 00:16:17, Vlan1
O 192.168.4.0/24 [110/2] via 192.168.1.2, 00:16:07, Vlan1
O 192.168.5.0/24 [110/2] via 192.168.1.2, 00:16:07, Vlan1
O 192.168.6.0/24 [110/2] via 192.168.1.3, 00:12:30, Vlan1
O 192.168.7.0/24 [110/2] via 192.168.1.3, 00:12:20, Vlan1
O 192.168.8.0/24 [110/2] via 192.168.1.3, 00:12:20, Vlan1
O 192.168.9.0/24 [110/2] via 192.168.1.3, 00:12:10, Vlan1
CoreSW1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
192.168.5.254 1 FULL/BDR 00:00:36 192.168.1.2 Vlan1
192.168.9.254 1 FULL/DROTHER 00:00:35 192.168.1.3 Vlan1
192.168.1.9 1 FULL/DROTHER 00:00:32 192.168.1.9 Vlan1
o开头的路由是通过OSPF协议学到的路由。
4、测试网络的连通性
在任意一台pc上(例如pc1)上ping任意一台pc(例如pc8)都是可以ping通的。