实验目的:

1、掌握Native vlan和Allow vlan的配置。

2、理解Native vlan和Allow vlan的功能。

实验拓扑:

实验步骤:

1、依据图中拓扑配置4台主机的IP地址,其中PC通过路由器模拟,配置如下:

PC1(config)#int f0/0

PC1(config-if)#no shutdown

PC1(config-if)#ip address 192.168.1.1 255.255.255.0

PC1(config-if)#exit

PC2(config)#int f0/0

PC2(config-if)#no shutdown

PC2(config-if)#ip address 192.168.1.2 255.255.255.0

PC2(config-if)#exit

PC3(config)#int f0/0

PC3(config-if)#no shutdown

PC3(config-if)#ip address 192.168.2.3 255.255.255.0

PC3(config-if)#exit

PC4(config)#int f0/0

PC4(config-if)#no shutdown

PC4(config-if)#ip address 192.168.2.4 255.255.255.0

PC4(config-if)#exit

 2、根据图中拓扑,在交换机SW1和SW2上创建VLAN,然后将接口放置到对应VLAN中,如下=>

SW1上配置:

SW1#vlan database

SW1(vlan)#vlan 10 name VLAN_10

SW1(vlan)#vlan 20 name VLAN_20

SW1(vlan)#exit

SW1(config)#int f0/2

SW1(config-if-range)#switchport mode access

SW1(config-if-range)#switchport access vlan 10

SW1(config-if-range)#exit

SW1(config)#int f0/3

SW1(config-if-range)#switchport mode access

SW1(config-if-range)#switchport access vlan 20

SW1(config-if-range)#exit

SW2上配置:

SW2#vlan database

SW2(vlan)#vlan 10 name VLAN_10

SW2(vlan)#vlan 20 name VLAN_20

SW2(vlan)#exit

SW2(config)#int f0/2

SW2(config-if-range)#switchport mode access

SW2(config-if-range)#switchport access vlan 10

SW2(config-if-range)#exit

SW2(config)#int f0/3

SW2(config-if-range)#switchport mode access

SW2(config-if-range)#switchport access vlan 20

SW2(config-if-range)#exit

查看VLAN信息,如下:

SW1#show vlan-switch brief


VLAN Name                     Status    Ports

---- -------------------------------- --------- -------------------------------

1    default                     active  Fa0/1,Fa0/4, Fa0/5, Fa0/6, Fa0/7

                                           Fa0/8, Fa0/9, Fa0/10, Fa0/11

                                         Fa0/12, Fa0/13, Fa0/14, Fa0/15

10   VLAN_10                    active    Fa0/2

20   VLAN_20                    active    Fa0/3

1002 fddi-default                    active   

1003 token-ring-default               active   

1004 fddinet-default                  active   

1005 trnet-default                    active 

SW2#show vlan-switch brief


VLAN Name                      Status    Ports

---- -------------------------------- --------- -------------------------------

1    default                     active Fa0/1,Fa0/4, Fa0/5, Fa0/6, Fa0/7

                                           Fa0/8, Fa0/9, Fa0/10, Fa0/11

                                         Fa0/12, Fa0/13, Fa0/14, Fa0/15

10   VLAN0010                   active    Fa0/2

20   VLAN0020                   active    Fa0/3

1002  fddi-default                 active   

1003 token-ring-default               active   

1004 fddinet-default                  active   

1005 trnet-default                    active 

此时,SW1和SW2上不同交换机已经创建,并且不同接口放置在对应VLAN中。

3、部署Trunk技术,并实现Trunk优化。默认情况下,Trunk上native vlan为1,即从vlan1的数据不打标签,要求将native vlan改为10;其次,Trunk

允许所有的vlan数据通过,要求只允许vlan 10和20通过。配置如下:

SW1(config)#int f0/0

SW1(config-if)#switchport trunk encapsulation dot1q

SW1(config-if)#switchport mode trunk

SW1(config-if)#switchport trunk native vlan 10 

SW1(config-if)#switchport trunk allowed 1,1002-1005,10,20 

SW1(config-if)#exit

SW2配置如下:

SW2(config)#int f0/0

SW2(config-if)#switchport trunk encapsulation dot1q

SW2(config-if)#switchport mode trunk

SW2(config-if)#switchport trunk native vlan 10

SW2(config-if)#switchport trunk allowed vlan 1,1002-1005,10,20

SW2(config-if)#exit

查看Trunk链路状态,如下:

SW1#show interfaces trunk


Port      Mode         Encapsulation  Status        Native vlan

Fa0/0     on           802.1q         trunking      10


Port      Vlans allowed on trunk

Fa0/0     1,10,20,1002-1005


Port      Vlans allowed and active in management domain

Fa0/0     1,10,20

Port      Vlans in spanning tree forwarding state and not pruned

Fa0/0     1,10,20

可以看到,native vlan从1变成10,而allow vlan则只允许vlan10、20和其他默认vlan数据通过。

4、进入Trunk优化测试,要验证native vlan的效果,可以通过抓包来达到,例如先让PC1 ping PC2,并在trunk上抓包:

PC1#ping 192.168.1.2


Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 28/42/64 ms

 底层数据分组如下:

再让PC3 ping PC4,并抓包,如下:

PC3#ping 192.168.2.4

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.2.4, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 28/40/60 ms

  底层数据分组如下:

从上面对比可以看出,一般的vlan经过trunk链路需要打上标签,而native vlan无需打上标签。

5、验证Allow vlan功能,将允许的vlan改为只允许vlan20通过,配置如下:

SW1(config)#int f0/0

SW1(config-if)#switchport trunk allowed vlan 1,20,1002-1005

SW1(config-if)#exit

SW2(config)#int f0/0

SW2(config-if)#switchport trunk allowed vlan 1,20,1002-1005

SW2(config-if)#exit

此时让PC1 ping PC2,如下:

PC1#ping 192.168.1.2


Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:

.....

Success rate is 0 percent (0/5)

再让PC3 ping PC4,如下:

PC3#ping 192.168.2.4


Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 192.168.2.4, timeout is 2 seconds:

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 24/36/60 ms

从上面可以看出,没有被allow的vlan没法通过trunk链路!

通过以上两种trunk优化的部署,我们可以得出:

①Native vlan可以使得特定vlan在经过trunk的时候无需打上标签,交换机全局只允许一个native vlan,默认为native vlan 1,一般将native vlan修改为需要大数据处理的vlan,由此可以减轻交换机的压力。另外,交换机双方的native vlan必须一致,否则,由于Cisco交换机开启CDP协议,若检测到不一致,则链路会down!

②Allow vlan可以使特定的vlan在trunk上面跑,通过此技术,可以限制一些垃圾数据如广播泛洪的影响,达到流量优化。

此实验完成。