TRUNK是端口汇聚的意思,允许交换机与交换机、交换机与路由器、主机与交换机或路由器之间通过两个或多个端口并行连接同时传输以提供更高带宽、更大吞吐量, 大幅度提供整个网络能力。VLAN TRUNK一般是你设置了多个VLAN后,想通过一个端口传输多个VLAN,这个后需要把该端口设置为TRUNK了。 
当一个VLAN跨过不同的交换机时,在同一VLAN上但是却是在不同的交换机上的计算机进行通讯时需要使用Trunk。Trunk技术使得一条物理线路可以传送多个VLAN的数据。交换机从属于某一VLAN(例如VLAN 3)的端口接收到数据,在Trunk链路上进行传输前,会加上一个标记,表明该数据是VLAN 3的;到了对方交换机,交换机会把该标记去掉,只发送到属于VLAN 3的端口。

如果是不同台的交换机上相同id的vlan要相互通信,那么可以通过共享的trunk端口就可以实现,如果是同一台上不同id的vlan/不同台不同id的vlan它们之间要相互通信,需要通过第三方的路由来实现。


实验一

trunk实验

设备:2台PC  1台二层交换机   1台路由器

要求PC1和PC2分别在不同的vlan和网段,要求相互ping通


配置

R1

R1#conf terminal

R1(config)#int f0/1

R1(config-if)#no shutdown

R1(config)#int f0/1.1

R1(config-subif)#encapsulation dot1Q 10

R1(config-subif)#ip address 192.168.2.254255.255.255.0

R1(config-subif)#exit

R1(config)#int f0/1.2

R1(config-subif)#encapsulation dot1Q 20

R1(config-subif)#ip add 192.168.4.254255.255.255.0

R1(config-subif)#end

R1#show ip in br

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet0/0            unassigned      YES unset administratively down down   

FastEthernet0/1            unassigned      YES unset up                    up     

FastEthernet0/1.1          192.168.2.254   YES manual up                    up     

FastEthernet0/1.2          192.168.4.254   YES manual up                    up     

 

 

SW1:

sw1#vlan database

sw1(vlan)#vlan 10

sw1(vlan)#vlan 20

sw1(vlan)#exit

 

sw1#configure terminal

sw1(config)#int f0/0

sw1(config-if)#switchport mode trunk

sw1(config-if)#switchport trunkencapsulation dot1q

sw1(config-if)#switchport

sw1(config-if)#exit

sw1(config)#no ip routing

sw1(config)#int f0/1

sw1(config-if)#switchport access vlan 10

sw1(config-if)#exit

sw1(config)#interface f0/2

sw1(config-if)#switchport access vlan 20

sw1(config-if)#end

sw1#sho ip in br

Interface                  IP-Address      OK? Method Status                Protocol

FastEthernet0/0            unassigned      YES unset up                    up     

FastEthernet0/1            unassigned      YES unset up                    up     

FastEthernet0/2            unassigned      YES unset up                    up     

FastEthernet0/3            unassigned      YES unset up                    down   

FastEthernet0/4            unassigned      YES unset up                    down   

FastEthernet0/5            unassigned      YES unset up                    down   

         

sw1#show vlan-switch

sw1#show interfaces trunk

 

 

PC1:

PC1(config)#no ip routing

PC1(config-if)#ip add 192.168.2.1255.255.255.0

PC1(config-if)#no shutdown

PC1(config-if)#exit

PC1(config)#ip default-gateway192.168.2.254

PC1(config)#end

 

 

PC2:

PC2(config)#interface f0/0

PC2(config-if)#ip add 192.168.4.1255.255.255.0

PC2(config-if)#no shutdown

PC2(config)#ip default-gateway192.168.4.254

PC2(config)#end

PC2#ping 192.168.4.1

Success rate is 100 percent (5/5),round-trip min/avg/max = 1/1/4 ms

PC2#ping 192.168.4.254

Success rate is 80 percent (4/5),round-trip min/avg/max = 12/18/20 ms

 

PC2#ping 192.168.2.1 

Success rate is 0 percent (0/5)

PC2#ping 192.168.2.254

Success rate is 0 percent (0/5)

PC2#conf terminal

PC2(config)#no ip routing      一定要确保模拟PC的路由器 路由功能关掉



实验二

trunk实验

配置

PC1和PC2 还和之前一样配置

 

SW1:

sw1(config)#int f0/0

sw1(config-if)#ip add 192.168.11.1255.255.255.0

 

% IP addresses may not be configured on L2links.

sw1(config-if)#no switchport

sw1(config-if)#ip add 192.168.11.1255.255.255.0

sw1(config)#end

 

sw1(config)#int vlan 10

sw1(config-if)#ip add 192.168.2.254255.255.255.0

sw1(config-if)#no shutdown

sw1(config-if)#exit

sw1(config)#int vlan 20

sw1(config-if)#ip add 192.168.4.254255.255.255.0

sw1(config-if)#no shutd  

 

 

PC1:

PC1#ping 192.168.2.254

Success rate is 80 percent (4/5),round-trip min/avg/max = 12/18/20 ms

 

PC1#ping 192.168.11.1 

Success rate is 100 percent (5/5),round-trip min/avg/max = 12/14/20 ms








相关文章:

  • 2021-12-04
  • 2021-11-24
  • 2021-06-18
  • 2021-11-25
  • 2021-12-04
  • 2021-11-02
  • 2021-09-22
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2021-08-20
  • 2021-08-19
  • 2021-08-22
  • 2022-01-16
  • 2021-08-03
  • 2022-01-09
相关资源
相似解决方案