配置Trunk

本文详细描述了如何在实验环境中配置NativeVLAN和Trunk,包括创建VLAN、划分端口、配置Trunk的封装类型、NativeVLAN选择以及安全设置,通过实例展示了VLAN内主机间的通信验证。
摘要由CSDN通过智能技术生成

1、实验目的

通过本实验可以掌握:

  1. Native VLAN 的含义和配置。
  2. IEEE802.1q 封装。
  3. Trunk 配置和调试方法。

2、实验拓扑

配置 Trunk 的实验拓扑如下图所示。

3、实验步骤

3.1 在交换机S1、S2上创建 VLAN 并把端口划分到相应的VLAN中

(1)配置交换机S1
S1(config)#vlan 2
S1(config-vlan)#name jishubu
S1(config-vlan)#exit
S1(config)#vlan 3
S1(config-vlan)#name caiwubu
S1(config-vlan)#exit
S1(config)#interface gigabitEthernet 1/0/1
S1(config-if)#switchport mode access 
S1(config-if)#switchport access vlan 2
S1(config-if)#exit
S1(config)#interface gigabitEthernet 1/0/2
S1(config-if)#switchport mode access 
S1(config-if)#switchport access vlan 3
S1(config-if)#exit
(2)配置交换机S2
S2(config)#vlan 2
S2(config-vlan)#name jishubu
S2(config-vlan)#exit
S2(config)#vlan 3
S2(config-vlan)#name caiwubu
S2(config-vlan)#exit
S2(config)#interface gigabitEthernet 1/0/1
S2(config-if)#switchport mode access 
S2(config-if)#switchport access vlan 2
S2(config-if)#exit
S2(config)#interface gigabitEthernet 1/0/2
S2(config-if)#switchport mode access 
S2(config-if)#switchport access vlan 3
S2(config-if)#exit

3.2 配置Trunk

(1)配置交换机S1
S1(config)#interface gigabitEthernet 1/0/24
S1(config-if)#switchport trunk encapsulation dot1q 
//配置Trunk链路的封装类型,有的交换机,例如,Cisco 2960的IOS只支持dot1q封装,因此无须执行该命令。由于ISL 封装是 Cisco私有技术,实际应用中很少使用
S1(config-if)#switchport mode trunk 
//配置端口模式为Trunk。被配置为Trunk 的端口,执行命令show vlan时将看不到该端口
S1(config-if)#switchport trunk native vlan 199
//在Trunk链路上配置Native VLAN,默认 Native VLAN为 VLAN1
S1(config-if)#switchport nonegotiate 
//关闭链路 DTP自动协商功能
S1(config-if)#switchport trunk allowed vlan 1-3
//配置 Trunk链路只允许VLAN1~VLAN3的数据包通过
S1(config-if)#exit

【技术要点】

switchport trunk allowed vlan命令有以下选项。

  1. VLAN ID: VLAN列表,可以采用2,3,4~100这种形式,其含义为Trunk链路上允许列表中指明的VLAN的数据流量通过。
  2. add:在原有的列表中允许新增加的 VLAN数据通过Trunk链路。
  3. all:允许所有的 VLAN数据通过Trunk链路,这是默认配置。
  4. except:除指定 VLAN以外的 VLAN的数据都允许通过Trunk链路。
  5. none:不允许任何VLAN的数据通过Trunk链路。
  6. remove:在原有的列表中禁止指定的 VLAN 数据通过Trunk链路。

需要注意的是,如果 Trunk链路上允许的VLAN列表配置不正确,可能造成网络连通性出现问题。

(2)配置交换机S2

S2(config)#interface gigabitEthernet 1/0/24
S2(config-if)#switchport trunk encapsulation dot1q 
S2(config-if)#switchport mode trunk 
S2(config-if)#switchport trunk native vlan 199
S2(config-if)#switchport nonegotiate 
S2(config-if)#switchport trunk allowed vlan 1-3
S2(config-if)#exit

【技术要点】

  • 配置Trunk时,同一链路的两端封装要相同,不能一端是ISL,另一端是dot1q。
  • 配置Native VLAN为不存在的VLAN,目的是避免VLAN跳跃攻击,提升网络安全。
  • 如果Trunk链路两端的Native VLAN不相同,CDP会检测到Native VLAN不匹配,交换机S2提示如下信息:
%CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on GigabitEthernet1/0/24 (1), with S1 GigabitEthernet1/0/24 (199).
  • 从网络安全角度考虑,关闭Trunk的自动协商,直接把端口配置为Trunk模式。

4、实验调试

4.1 查看端口 Trunk 信息

S1#show interfaces trunk 
Port        Mode         Encapsulation  Status        Native vlan
Gig1/0/24   on           802.1q         trunking      199
 
Port        Vlans allowed on trunk
Gig1/0/24   1-3
 
Port        Vlans allowed and active in management domain
Gig1/0/24   1,2,3
 
Port        Vlans in spanning tree forwarding state and not pruned
Gig1/0/24   1,2,3

4.2 查看交换机端口信息

S1#show interfaces gigabitEthernet 1/0/24 switchport 
Name: Gig1/0/24
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Off
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 199 (Inactive)
Voice VLAN: none
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Administrative private-vlan trunk native VLAN: none
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk private VLANs: none
Operational private-vlan: none
Trunking VLANs Enabled: 1-3
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL
Protected: false
Appliance trust: none

4.3 测试 VLAN 内主机之间的通信状态

(1)PC1 ping PC4 可以通信

(2)PC2 ping PC3 可以通信

(1)和(2)的测试结果说明同一个VLAN中的主机是可以跨越Trunk链路进行通信的。

至此实验结束。

  • 25
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值