使用三层交换机实现VLAN间通信

实现PC0能与PC1、PC2、PC3通信

使用三层交换机实现VLAN间通信_第1张图片

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   

使用三层交换机实现VLAN间通信_第2张图片

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间通信_第3张图片

已实现vlan间通信


你可能感兴趣的:(CCNA)