交换机实现不同VLAN的通信
本实验是由一个三层交换机和一个两个交换机来实现的。
PC机划分VLAN后便于管理和通信。但是有的时候,不同的VLAN之间需要通信。这就需要在三层交换机上在两个VLAN之间设置虚拟默认网关,该网关就是两个VLAN的默认网关。
试验的拓扑图如下所示:
按照该图连接好后,设置PC机的IP。将主机0和2 设置在同一个网络,将主机1和3设置在同一个网段。
然后对三层交换机进行端口设置。
对两台交换机进行设置,使其能够进行通信(即将其连接端口设置为TRUNK模式)
对三层交换机命令代码如下:
Switch(config)#interface fastEthernet 0/3
Switch(config-if)#switchport mode trunk
%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)#no shutdown
同样两层交换机的命令代码如下:
Switch(config)#interface fastEthernet 0/3
Switch(config-if)#switchport mode trunk
%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)#no shutdown
 
 
划分VLAN10和VLAN20
Switch>enable
Switch#configure terminal
Switch(config)#vlan 10
Switch(config-vlan)#exit
Switch(config)#vlan 20
然后将端口0/1 和0/2分别划分在VLAN10和VLAN20中
命令代码如下:
Switch(config)#interface fastEthernet 0/1
Switch(config-if)#switchport access vlan 10
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#interface fastEthernet 0/2
Switch(config-if)#switchport access vlan 20
Switch(config-if)#no shutdown
此时如果对PC0和PC2进行PING操作,结果是联通的。但是PC0与PC1PING不通。
要想PC0与PC1PING通需要对三层交换机进行如下端口设置(即在两个VLAN上设置虚拟端口)
Switch(config-if)#interface vlan 10
Switch(config-if)#ip address 192.168.1.3 255.255.255.0
Switch(config-if)#no shutdown
Switch(config)#interface vlan 20
Switch(config-if)#ip address 192.168.2.3 255.255.255.0
Switch(config-if)#no shutdown
此时链路中的任何一台PC机都可以联通;
 
 
 
 
需要注意的是:两个VLAN的虚拟地址是两个VLAN各自的默认网关:
这是我的笔记  希望对大家有所帮助;