3.4 Trunk进阶配置

实验目的:

1、掌握Native vlanAllow vlan的配置。

2、理解Native vlanAllow vlan的功能。

实验拓扑:

214231493.png

实验步骤:

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、根据图中拓扑,在交换机SW1SW2上创建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

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

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

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

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[PL1]

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

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 vlan1变成10,而allow vlan则只允许vlan1020和其他默认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

PingingLab传世经典系列《CCNA完全配置宝典》-3.4 <wbr>Trunk进阶配置 底层数据分组如下:

再让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

PingingLab传世经典系列《CCNA完全配置宝典》-3.4 <wbr>Trunk进阶配置 底层数据分组如下:

从上面对比可以看出,一般的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

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

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

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

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

此实验完成。


[PL1]将默认的Native vlan1修改为10.

[PL2]默认trunk允许所有vlan,此处修改为允许1020;除此之外还需要将默认的1,1002-1005加入,有些设备则可以直接通过:

Switchport trunk allowed 10,20

==========================================

PingingLab·高品质IT教育提供商

CCIE 实验室·IT项目实战·高端人才定制

深圳拼客信息科技有限公司·广州大学城外环西路站

新浪微博:@拼客科技PingingLab  @PingingLab-陈鑫杰

PingingLab微信公众号:pinginglab

PingingLab技术交流群:240920680