1. 程式人生 > >使用三層交換機實現VLAN間通訊

使用三層交換機實現VLAN間通訊

實現PC0能與PC1、PC2、PC3通訊


1.先配置使得vlan內通訊,vlan間通訊隔離
對switch0
Switch>ena
Switch#conf 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/23
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int f0/24
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f0/1
Switch(config-if)#switchport mode trunk

Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#no shutdown


對switch1
Switch>ena
Switch#conf 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-if)#int f0/24
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 10
Switch(config-if)#int f0/23
Switch(config-if)#switchport mode access
Switch(config-if)#switchport access vlan 20
Switch(config-if)#int f0/1
Switch(config-if)#switchport mode trunk

Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up

Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#no shutdown
對三層交換機
Switch>ena
Switch#conf 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
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)#switchport trunk allowed vlan all
Switch(config-if)#no shutdown
Switch(config-if)#int f0/2
Switch(config-if)#switchport trunk encapsulation dot1q  //以dot1q封裝埠
Switch(config-if)#switchport mode trunk              //將埠設定為trunk模式
Switch(config-if)#switchport trunk allowed vlan all
Switch(config-if)#no shutdown
Switch(config-if)#end


此時已經配置完成vlan內可以通訊,vlan間通訊隔離
先設定主機IP
PC0:192.168.10.3   255.255.255.0   
PC1:192.168.20.3   255.255.255.0   
PC2:192.168.10.2   255.255.255.0   
PC3:192.168.20.2   255.255.255.0   


2.在三層交換機上配SVI
Switch>ena
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#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.1 255.255.255.0
Switch(config-if)#no shutdown
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.1 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit

3.在三層交換機上開啟路由功能
Switch(config)#ip routing

4.設定主機閘道器(相應vlan SVI)
PC0:192.168.10.1
PC1:192.168.20.1
PC2:192.168.10.1
PC3:192.168.20.1

對PC0


已實現vlan間通訊