目的:让PC1 ping通 PC3 ,PC2 ping通 PC4
PC1配置ip地址 # PC的网关指向vlan的ip地址
LSW1:
vlan batch 10 20 #在交换机上创建vlan 10 和 vlan 20
interface Vlanif10 #进入vlan 10
ip address 192.168.10.254 255.255.255.0 #给vlan 10配置ip地址
interface Vlanif20 #进入vlan 20
ip address 192.168.20.254 255.255.255.0 #给vlan 20配置ip地址
interface GigabitEthernet0/0/1 #进入g0/0/1接口
port link-type trunk #将此接口的模式改为trunk
port trunk allow-pass vlan 2 to 4094 #配置此接口允许所有vlan通过
interface GigabitEthernet0/0/2
port link-type access #将此接口模式改为accrss
port default vlan 10 #只允许vlan 10通过
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
LSW2:
interface Vlanif10
ip address 192.168.10.254 255.255.255.0
interface Vlanif20
ip address 192.168.20.254 255.255.255.0
interface GigabitEthernet0/0/1
port link-type trunk
port trunk allow-pass vlan 2 to 4094
interface GigabitEthernet0/0/2
port link-type access
port default vlan 10
interface GigabitEthernet0/0/3
port link-type access
port default vlan 20
效果: