实验目的:

1、掌握Trunk的基础配置。

2、理解Trunk的功能。

实验拓扑:

实验步骤:

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技术,SW1配置如下:

SW1(config)#int f0/0

SW1(config-if)#switchport trunk encapsulation dot1q  

SW1(config-if)#switchport mode trunk 

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)#exit

查看Trunk链路状态,如下:

SW1#show interfaces trunk


Port      Mode         Encapsulation  Status        Native vlan

Fa0/0     on           802.1q         trunking      1


Port      Vlans allowed on trunk

Fa0/0     1-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

此时Trunk链路已经起来。

4.测试通过部署Trunk链路,VLAN10和VLAN20的数据能否经过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 = 32/42/64 ms

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 = 44/56/68 ms

从以上可以看到,Trunk链路可以同时承载不同VLAN的流量,相比之前“一个VLAN一根网线”的解决方案,Trunk方案不仅部署方便,而且非常节省端口资源,做到“n个VLAN一根网线”。当然,由于Trunk链路默认承载所有VLAN流量,会有很多垃圾流量在上面,这就需要实现Trunk优化。此实验完成。