背景
如图,PC0和PC3在vlan10里面,但是不在同一个交换机上,PC1和PC2在vlan20里面,但是也不在同一个交换机上,现在需要实现PC0和PC3可以通讯,和其他的不能通讯,PC1和PC2可以通讯,和其他的不能通讯。
简单的说就是让他们可以跨交换机在同一个vlan中通讯,两台交换机之间只能一条线连接,而不是一个VLAN一条线连接。
交换机0和交换机1相互连接的端口都为F0/1
连接
交换机0与交换机1使用f0/1端口相连
PC0使用的是交换机0的F0/5端口
PC1使用的是交换机1的F0/10端口
PC2使用的是交换机0的F0/10端口
PC3使用的是交换机1的F0/5端口
PC配置
PC0
地址:192.168.1.2
掩码:255.255.255.0
网关:192.168.1.1
PC1
地址:192.168.1.3
掩码:255.255.255.0
网关:192.168.1.1
PC2
地址:192.168.1.4
掩码:255.255.255.0
网关:192.168.1.1
PC3
地址:192.168.1.5
掩码:255.255.255.0
网关:192.168.1.1
操作
交换机O的设置
创建vlan
先划分出两个vlan,一个vlan10,一个vlan20
Switch>en
Switch#conf
Configuring from terminal, memory, or network [terminal]?
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)#
划分端口到对应的vlan
把PC0和PC2连接的端口划分到指定的vlan中,PC0是vlan10,PC2是vlan20
Switch(config)#in
Switch(config)#interface f0/5
Switch(config-if)#sw
Switch(config-if)#switchport a
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#in
Switch(config)#interface f0/10
Switch(config-if)#sw
Switch(config-if)#switchport a
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
Switch(config)#
设置交换机相连的端口
把f0/1端口设置为trunk模式,然后保存配置
Switch(config)#in
Switch(config)#interface f0/1
Switch(config-if)#sw
Switch(config-if)#switchport m
Switch(config-if)#switchport mode t
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)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#wr
Switch#write
Building configuration...
[OK]
Switch#
到此交换机0设置完毕
交换机1的设置
创建vlan
同样,先创建vlan10和vlan20
Switch>ena
Switch#conf
Configuring from terminal, memory, or network [terminal]?
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)#
划分端口到对应的vlan
Switch(config)#in f0/5
Switch(config-if)#sw
Switch(config-if)#switchport a
Switch(config-if)#switchport access vlan 10
Switch(config-if)#exit
Switch(config)#in f0/10
Switch(config-if)#sw
Switch(config-if)#switchport a
Switch(config-if)#switchport access vla
Switch(config-if)#switchport access vlan 20
Switch(config-if)#exit
Switch(config)#
设置交换机相连的端口
把f0/1端口设置为trunk模式,然后保存配置
Switch(config)#in f0/1
Switch(config-if)#sw m t
Switch(config-if)#exit
Switch(config)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#wri
Switch#write
Building configuration...
[OK]
Switch#
测试
PC0(192.168.1.2)和PC3(192.168.1.5)可以通讯,和PC1(192.168.1.3)不能通讯
PC2(192.168.1.4)和PC1(192.168.1.3)可以通讯,和PC3(192.168.1.5)不能通讯
原理
交换机之间的vlan是不能相互通讯的即使使用的是同一个网段的网络,只能在同一个vlan通讯,即使是跨交换机也是只能在同一个vlan中通讯,但是明明两个交换机有多个VLAN,中间确只用一条线相连就可以进行多个VLAN跨交换机通讯,最主要的就是两台交换机相连的端口模式设置为了trunk模式。