一、实验说明:按照网络拓扑图连接并设置好PC机的IP地址,要求PC1、PC2属于VLAN 12,PC3、PC4属于VLAN 34,现通过实验实现VLan 12与VLan 34间的互通,PC1~PC4两两任意互通。

附网络拓扑图:


不同VLan的连通_不同VLan的连通 不同VLan间的路由

交换机一上的配置:

Switch>enable

Switch#configure terminal

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#hostname SW1

SW1(config)#no ip domain lookup

SW1(config)#line console 0

SW1(config-line)#exec-timeout 0 0

SW1(config-line)#exit

SW1(config)#vlan 12

SW1(config-vlan)#exit

SW1(config)#vlan 34

SW1(config-vlan)#exit

SW1(config)#interface f0/1

SW1(config-if)#no shutdown

SW1(config-if)#switchport mode access

SW1(config-if)#switchport access vlan 12

SW1(config-if)#exit

SW1(config)#interface f0/4

SW1(config-if)#no shutdown

SW1(config-if)#switchport mode access

SW1(config-if)#switchport access vlan 34

SW1(config-if)#exit

SW1(config)#interface f0/24

SW1(config-if)#no shutdown

SW1(config-if)#switchport mode trunk


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


SW1(config-if)#exit



交换机二上的配置:

Switch>enable

Switch#configure terminal

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#hostname SW2

SW2(config)#line console 0

SW2(config-line)#exec-timeout 0 0

SW2(config-line)#exit

SW2(config)#vlan 12

SW2(config-vlan)#exit

SW2(config)#vlan 34

SW2(config-vlan)#exit

SW2(config)#interface f0/2

SW2(config-if)#no shutdown

SW2(config-if)#switchport mode access

SW2(config-if)#switchport access vlan 12

SW2(config-if)#exit

SW2(config)#interface f0/3

SW2(config-if)#no shutdown

SW2(config-if)#switchport mode access

SW2(config-if)#switchport access vlan 34

SW2(config-if)#exit

SW2(config)#interface f0/24

SW2(config-if)#no shutdown

SW2(config-if)#switchport mode trunk

SW2(config-if)#exit


     @以下四行配置多层交换与级联交换机的互联链路为trunk

SW2(config)#interface f0/23

SW2(config-if)#no shutdown

SW2(config-if)#switchport mode trunk

SW2(config-if)#end

SW2(config-if)#



多层交换机的配置:

Switch>enable

Switch#configure terminal

Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#hostname MLSW-VLan-Gateway

MLSW-VLan-Gateway(config)#ip routing     //开启多层交换机的路由功能,很重要!

    @使用的是逻辑接口,为每个VLAN配置一个网关IP

MLSW-VLan-Gateway(config)#vlan 12

MLSW-VLan-Gateway(config-vlan)#exit

MLSW-VLan-Gateway(config)#vlan 34

MLSW-VLan-Gateway(config-vlan)#interface vlan 12

MLSW-VLan-Gateway(config-if)#no shutdown

MLSW-VLan-Gateway(config-if)#ip address 192.168.12.254 255.255.255.0

MLSW-VLan-Gateway(config-if)#exit

MLSW-VLan-Gateway(config)#interface vlan 34

MLSW-VLan-Gateway(config-if)#no shutdown

MLSW-VLan-Gateway(config-if)#ip address 192.168.34.254 255.255.255.0

MLSW-VLan-Gateway(config-if)#exit

     @以下四行配置多层交换与级联交换机的互联链路为trunk

MLSW-VLan-Gateway(config)#interface f0/23

MLSW-VLan-Gateway(config-if)#no shutdown

MLSW-VLan-Gateway(config-if)#switchport trunk encapsulation dot1q  //必须手动设置封装协议

MLSW-VLan-Gateway(config-if)#switchport mode trunk

MLSW-VLan-Gateway(config-if)#end