运用三层交换机实现不同VLAN之间的通信.
实验的拓扑图:
实验条件:两台主机,一个二层交换机,一个三层交换机
配置概要:
二层交换机的f0/3接口设置为trunk口,f0/1和f0/2口设置为access口
三层交换机的f0/1接口设置为trunk口,否则VLAN端口up(设置成trunk口的时候不能直接设置为trunk口,模拟器会显示不成功,因此先设置为access口再设置为trunk口)
三层交换机要开启路由功能(ip routing)
具体配置如下图:
二层交换机的配置:
Switch>ena
Switch>ena
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#int f0/1 //划分VLAN
Switch(config-if)#ssw
Switch(config-if)#sw
Switch(config-if)#switchport mo
Switch(config-if)#switchport acc
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#int f0/2 //划分VLAN
Switch(config-if)#sw
Switch(config-if)#switchport acc
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
Switch(config)#
Switch(config)#
Switch(config)#int f0/3
Switch(config-if)#sw
Switch(config-if)#switchport mo
Switch(config-if)#switchport mode tr
Switch(config-if)#switchport mode trunk //f0/3端口设置为trunk口
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to up
Switch(config-if)#
Switch con0 is now available
三层交换机的配置:
Switch>ena
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#
Switch(config)#
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#exit
Switch(config)#
Switch(config)#
Switch(config)#int f0/1
Switch(config-if)#sw
Switch(config-if)#switchport mo
Switch(config-if)#switchport mode tr
Switch(config-if)#switchport mode trunk //设置trunk口显示创建失败
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.
Switch(config-if)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
Switch(config-if)#ip add 192.168.10.254 255.255.255.0 //设置网关
Switch(config-if)#no shut
Switch(config-if)#
Switch(config-if)#
Switch(config-if)#exit
Switch(config)#int vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
Switch(config-if)#ip add 192.168.20.254 255.255.255.0
Switch(config-if)#no shut
Switch(config-if)#exit
Switch(config)#ip routing //三层交换机启动路由功能
Switch(config)#
Switch(config)#
Switch(config)#
Switch(config)#int f0/1
Switch(config-if)#sw
Switch(config-if)#switchport mo
Switch(config-if)#switchport mode acc
Switch(config-if)#switchport mode access //先设置为access口
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to down
Switch(config-if)#switchport mode tr
Switch(config-if)#switchport mode trunk //再设置为trunk口
不同VLAN之间的主机互ping: