且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q

更新时间:2022-09-27 13:13:11

本节书摘来自异步社区《CCIE路由和交换认证考试指南(第5版) (第1卷)》一书中的第2章,第2.3节VLAN Trunk: ISL和802.1Q,作者 【美】Narbik Kocharians(那比克 科查理安) , 【斯洛伐克】Peter Paluch(彼得 派拉奇),更多章节内容可以访问云栖社区“异步社区”公众号查看

2.3 VLAN Trunk: ISL和802.1Q
通过使用VLAN Trunk链路,交换机、路由器甚至是有适当NIC(网卡)且/或软件驱动的PC,都能够通过一条链路发送去往多个VLAN的流量。为了知道数据帧属于哪个VLAN,发送方交换机、路由器或PC会添加原始以太网数据帧的头部,这个头部中包含表示相关VLAN的VLAN ID字段。本节描述两种Trunk协议的协议详情,接着详述如何配置Trunk。

2.3.1 ISL和802.1Q概念
如果两台设备之间要执行Trunk,它们必须在使用ISL(交换机间链路),还是使用802.1Q上达成一致,因为两者之间有些区别,总结如表2-3所示。


《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q

1SL原来仅支持正常范围的VLAN,但后来进行了改进,能够支持扩展范围的VLAN。
ISL和802.1Q之间的区别主要体现在以下方面:通过Trunk发送数据帧之前,如何给以太网数据帧添加头部。ISL会添加新的26字节头部,以及新的尾部(从而能够使用新的FCS值),然后封装整个原始数据帧。使用执行Trunk行为的设备的源地址(在图2-4中列为SA)来封装头部,而不使用原始数据帧的源MAC地址。ISL使用组播目的地址(在图2-4中列为DA)0100.0C00.0000或0300.0C00.0000。总体来看,ISL数据帧是SNAP封装的数据帧。


《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q

802.1Q会在原始数据帧中(在源地址字段后)插入一个4字节的头部,称为标记。原始数据帧的地址保持不变。正常情况下,以太网控制器会希望在源地址字段后,找到以太网类型字段或802.1Q长度字段。对于802.1Q标记,地址字段后的前两个字节记录着以太网类型值0x8100,表示数据帧包含802.1Q的头部。因为802.1Q并不真正封装原始数据帧,因此通常被称为数据帧标记。图2-4显示了ISL和802.1Q使用的头部内容。

表2-3的最后一行提到了本征VLAN。在Trunk链路上,802.1Q不标记在本征VLAN中发送的数据帧,并且会将所有收到的未标记的数据帧都分配给本征VLAN。本征VLAN特性允许交换机尝试在接口上使用802.1Q Trunk,但如果另一台设备不支持Trunk,本征VLAN的流量仍可以通过链路发送。默认时,本征VLAN是VLAN 1,这也是默认的Access VLAN。Trunk链路两端的本征VLAN必须相同;否则就会出现本征VLAN不匹配,从而导致两个VLAN合并。为了检测并尽可能避免本征VLAN不匹配的不良影响,Cisco交换机对PVST+和快速PVST+部署实施了私有化扩展,允许它们检测并阻塞Trunk链路上不匹配的本征VLAN。此扩展将在第3章中进一步描述。Cisco发现协议(Cisco Discovery Protocol,CDP)将检测并报告本征VLAN不匹配的情况。***做法是在每个Trunk链路上,将本征VLAN从VLAN 1改为其他VLAN,并且不把这个VLAN用于除配置本征VLAN外的其他目的。这就会防止用户进行VLAN跳转攻击,在这种攻击中,用户会发送双标记数据帧,若顶端的标记匹配了Trunk的本征VLAN,Trunk会去除这个顶端标记。

关于Cisco实施的ISL和802.1Q标记的详细信息,可参见Cisco.com发布的技术说明文档“Inter-Switch Link and IEEE 802.1Q Frame Format”,文档ID:17056。

2.3.2 ISL和802.1Q配置
Cisco交换机使用动态 Trunk协议(DTP)来动态获知线缆另一端的设备是否希望使用Trunk,若是,使用哪种Trunk协议。这个协议减轻了交换网络初始部署的负担,同时最小化了两交换机之间由于端口配置的不匹配导致的配置错误。

DTP根据接口上定义的DTP模式来获知是否执行Trunk。DTP模式有以下这些。

dynamic auto:接口将自动协商接口模式;然而,偏向于成为Access接口。
dynamic desirable:接口将自动协商接口模式;然而,偏向于成为Trunk接口。
在这些模式之中,dynamic desirable有更高的优先级——如果两个接口都配置了dynamic,但一个配置为auto,另一个配置为desirable,最终的操作模式将是Trunk。如果两台设备中任意一台同时支持ISL和802.1Q,DTP也会协商Trunk上的封装类型。如果两台设备同时支持两种Trunk类型,它们将选择ISL。如果DTP协商失败,任何使用dynamic模式的接口,无论是desirable还是auto,都将运行为Access接口。接下来一节“Trunk配置的兼容性”进一步介绍了不同的DTP模式及其组合。

不同类型的Cisco交换机有不同的默认DTP模式。例如,较早的Catalyst 2950和3550型号默认为dynamic desirable模式。之后的Catalyst型号,如2960、3560或3750,默认为dynamic auto模式。关于具体交换机平台和IOS版本的权威信息可通过对应的命令手册进行查询。

虽然DTP和VTP是独立的协议,但DTP却在其消息中承载VTP域名。只有在两交换机上的VTP域名相同时,或者一台交换机未配置VTP域名时(即使用NULL域名),交换机才能成功协商链路的操作模式。使用VTP域名进行DTP协商,其背后的原因是在不同的VTP域中,可能有不同的VLAN集合,并且在每个VTP域中,相同编号的VLAN可以用作不同目的(这就是网络一开始被划分成几个VTP域的原因——保证VLAN数据库分离且独立)。因此,交换机不应将链路启用为Trunk,因为将VLAN从一个VTP域扩展到另一个VTP域,会导致不良后果。

将DTP模式设置为desirable,交换机可以轻松连接,它们也会动态建立Trunk。不过工程师也可以手动配置Trunk,并通过show命令验证结果。表2-4列出了一些与Trunk相关的关键Catalyst IOS命令。


《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q

图2-5列出了几条关于Switch1上的Trunk配置和状态的详细信息,如例2-6所示。R1未配置为Trunk,所以Switch1协商Trunk失败。Switch2是Catalyst 3550交换机,它同时支持ISL和802.1Q,所以它们将协商使用Trunk并使用ISL。Switch3和Switch4是Catalyst 2950交换机,它们只支持802.1Q;因此,与Switch1协商使用Trunk,但选择802.1Q作为Trunk协议。虽然在本书写作时Catalyst 3550和2950都已经停产,但它们的默认接口设置dynamic desirable,很好地展示了将其连接并使得链路动态成为Trunk是多么简单的事情。较新的Catalyst型号,如2960、3560、3750或3850系列,默认设置是dynamic auto,所以使用图2-5中相同的拓扑,但装配这些平台的设备,协商结果会变成Access模式。


《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q

正因为工程师能够配置端口相互协商它们的工作模式,因此一个接口上也可以同时有switchport access和switchport trunk命令。虽然乍一看让人困惑,但这些命令只是定义如果接口为Access接口或Trunk接口,接口将会如何工作。与当前未使用的接口操作模式相关的命令会显示出来,但也会被忽略。

例2-6 Trunk配置及show命令示例——Switch1

! The administrative mode of dynamic desirable (trunking) and negotiate (trunking
! encapsulation) means that Switch1 attempted to negotiate to trunk, but the
! operational mode of static access means that trunking negotiation failed.
! The reference to "operational trunking encapsulation" of native means that
! no tagging occurs.

Switch1# show int fa 0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: dynamic desirable
Operational Mode: static access
Administrative Trunking Encapsulation: negotiate
Operational Trunking Encapsulation: native
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
Administrative private-vlan host-association: none
Administrative private-vlan mapping: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001

Protected: false
Unknown unicast blocked: disabled
Unknown multicast blocked: disabled

Voice VLAN: none (Inactive)
Appliance trust: none

! Next, the show int gig 0/1 trunk command shows the configured mode
! (desirable), and the current status (n-isl), meaning negotiated ISL. Note
! that the trunk supports the extended VLAN range as well.

Switch1# show int gig 0/1 trunk
Port     Mode    Encapsulation Status     Native vlan
Gi0/1    desirable  n-isl     trunking    1

Port     Vlans allowed on trunk
Gi0/1    1-4094

Port     Vlans allowed and active in management domain
Gi0/1    1,21-22
Port     Vlans in spanning tree forwarding state and not pruned
Gi0/1    1,21-22

! Next, Switch1 lists all three trunks - the segments connecting to the other
! three switches - along with the type of encapsulation.

Switch1# show int trunk
Port    Mode       Encapsulatio   Status     Native vlan
Fa0/12   desirable    n-802.1q     trunking     1
Fa0/24   desirable    n-802.1q     trunking     1
Gi0/1    desirable    n-isl      trunking     1

Port    Vlans allowed on trunk
Fa0/12   1-4094
Fa0/24   1-4094
Gi0/1    1-4094

Port    Vlans allowed and active in management domain
Fa0/12   1,21-22
Fa0/24   1,21-22
Gi0/1    1,21-22

Port    Vlans in spanning tree forwarding state and not pruned
Fa0/12   1,21-22
Fa0/24   1,21-22
Gi0/1    1,21-22

如例2-7所示,在较新的Catalyst平台上,show dtp命令显示出全局和单个接口上DTP的操作模式。

注释:
较新的Catalyst交换机系列(如2960、3560、3750、3650和3850)在还没有实施任何配置时,接口的默认设置是这样的:模式设置为dynamic auto,本征VLAN设置为1,Access VLAN设置为1,Trunk封装设置为auto(如果同时支持ISL和dot1q的话)或dot1q,允许传输VLAN的信息,工程师可以修剪VLAN 2~1001。较旧的2950和3550交换机型号,默认模式设置为dynamic desirable。
例2-7 SW1上的show dtp命令输出

SW1# show dtp
Global DTP information
     Sending DTP Hello packets every 30 seconds
     Dynamic Trunk timeout is 300 seconds
     12 interfaces using DTP

! The TOS/TAS/TNS stand for Trunk Operating/Administrative/Negotiation Status
! The TOT/TAT/TNT stand for Trunk Operating/Administrative/Negotiation Type
! In the following output, Fa0/12 is configured as dynamic desirable

SW1# show dtp interface fa0/12
DTP information for FastEthernet0/12:
  TOS/TAS/TNS:                TRUNK/DESIRABLE/TRUNK
  TOT/TAT/TNT:                ISL/NEGOTIATE/ISL
  Neighbor address 1:             00179446B30E
  Neighbor address 2:            000000000000
  Hello timer expiration (sec/state):    19/RUNNING
  Access timer expiration (sec/state):   289/RUNNING
  Negotiation timer expiration (sec/state): never/STOPPED
  Multidrop timer expiration (sec/state):   never/STOPPED
  FSM state:                  S6:TRUNK
  # times multi & trunk            0
  Enabled:                   yes
  In STP:                   no

 Statistics
 ----------
  3 packets received (3 good)
  0 packets dropped
      0 nonegotiate, 0 bad version, 0 domain mismatches,
      0 bad TLVs, 0 bad TAS, 0 bad TAT, 0 bad TOT, 0 other
  6 packets output (6 good)
      3 native, 3 software encap isl, 0 isl hardware native
  0 output errors
  0 trunk timeouts
  2 link ups, last link up on Mon Mar 01 1993, 00:14:09
  2 link downs, last link down on Mon Mar 01 1993, 00:14:02

1.允许、活跃及修剪的VLAN
虽然Trunk可以支持VLAN 1~4096,但工程师仍可以使用几种机制,来减少实际可以通过Trunk的VLAN数量。首先,工程师可以使用接口命令switchport trunk allowed,禁止Trunk链路承载相应VLAN的流量。其次,允许通过Trunk链路发送的VLAN在变为活跃状态之前,工程师必须在交换机上配置相应VLAN。最后,工程师可以使用VTP来修剪Trunk上的VLAN,这样以来,交换机就会停止通过Trunk转发来自该VLAN的数据帧。

show interface trunk命令显示了每个类别中的VLAN,如例2-6中的最后一条命令所示。分类总结如下。

允许的VLAN:每个Trunk默认允许所有的VLAN。然而,工程师可以从允许的VLAN列表中添加或移除VLAN,使用的命令是switchport trunk allowed。
允许且活跃:为了成为活跃VLAN,首先VLAN必须在Trunk的允许列表中(基于Trunk配置),其次VLAN必须在交换机的VLAN配置中,最后VLAN必须为活跃状态(而不是休眠或本地关闭状态)。在使用PVST+时,STP实例活跃地运行在Trunk上,Trunk负责承载这个类别中列出的VLAN。
活跃且为修剪:这个类别是“允许且活跃”列表的子集,包含VTP修剪的VLAN,以及PVST+认为是阻塞接口的VLAN。
2.Trunk配置的兼容性
在多数生产网络中,整个网络中的交换机Trunk都使用相同的标准配置。例如,与其使用DTP来协商是否使用Trunk,许多工程师会自己配置Trunk接口总是使用Trunk(使用命令switchport mode trunk),而在不应该使用Trunk的接口上禁用DTP。IOS中包含几条命令,能够对具体网段是否使用Trunk构成影响。由于许多企业使用常见标准,因此工程师很容易忘记相关命令工作的细微差别。本节涵盖了这些细节。

有两条IOS命令能够影响两台交换机建立Trunk的过程:接口命令switchport mode和switchport nonegotiate定义了DTP是否会尝试协商Trunk,以及在尝试时使用何种规则。此外,网段上任一端交换机接口的设置都将决定Trunk是否能够成功建立。

表2-5总结了Trunk的配置选项。第一列表示一台交换机上的配置,最后一列为另一台交换机上的配置,并且这个配置将会致使两台交换机之间使用Trunk。


《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q
《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q
《CCIE路由和交换认证考试指南(第5版) (第1卷)》——2.3节VLAN Trunk: ISL和802.1Q

入向SP交换机收到802.1Q数据帧,然后使用额外的802.1Q头部来标记每个进入该接口的数据帧,这称为S-标记(原始的客户标记被称为C-标记,SP交换机不会修改或处理C-标记)。在本例中,所有客户1的数据帧在经过WAN时,都被标记为VLAN 5;客户2的数据帧被标记为VLAN 6。在出向接口移除S-标记之后,客户交换机会看到C-标记完好的原始802.1Q数据帧,并且可以正确地翻译VLAN ID信息。接收方SP交换机(本例中为SP-SW2)可以基于额外的VLAN S-标记,使多个客户的流量相互分离。

注意如果SP-SW1和SP-SW2之间的Trunk使用VLAN 5作为本征VLAN,来自客户1的数据帧在此Trunk上将不会被添加S-标记。因此,在SP-SW2收到这些数据帧时只有C-标记,SP-SW2会按照C-标记中指示的VLAN进行处理,而不是由VLAN 5进行处理。这可能会导致客户1的流量泄露给另一个客户、被误转发或丢入黑洞。为了避免这种情况,工程师通常需要为SP的交换机配置vlan dot1q tag native命令,来从根本上停用本征VLAN的概念,并无视本征VLAN设置而标记Trunk上的所有数据帧。

通过使用Q-in-Q,SP可以提供VLAN服务,甚至能够应对客户使用重叠VLAN ID的情况。客户对于网络设置的选择有了更大的灵活性,尤其在使用城域以太网服务时。此外,CDP和VTP流量也可以通过Q-in-Q服务透明传输。

在Catalyst交换机上,3550及更高版本的平台上支持Q-in-Q。例2-9显示了配置案例,这些配置相对简单。

例2-9 Catalyst 3560上的Q-in-Q配置示例

! It is assumed that C1-SW1 and C1-SW2 have their ports towards SP-SW1 configured
! as ordinary 802.1Q trunks. On SP-SW1, the vlan dot1q tag native is used to
! force tagging on all VLANs including native VLAN on trunks. Also, because
! a customer's C-tagged frame may already contain 1500 bytes in its payload, this
! payload including the C-tag is considered a new payload in the S-tagged frame,
! and thus may grow up to 1504 bytes. Therefore, the MTU of the resulting frames
! is increased to 1504 bytes using the system mtu commands. Their use must also
! be carefully matched by neighboring devices.

SP-SW1(config)# vlan dot1q tag native
SP-SW1(config)# system mtu 1504 ! Applies to 100Mbps interfaces
SP-SW1(config)# system mtu jumbo 1504 ! Applies to 1Gbps and 10Gbps interfaces
!
SP-SW1(config)# vlan 5
SP-SW1(config-vlan)# name Customer1
SP-SW1(config-vlan)# exit
SP-SW1(config)# vlan 6
SP-SW1(config-vlan)# name Customer2
SP-SW1(config-vlan)# exit

! The Fa0/24 interface connects to SP-SW2. This interface is configured as an
! ordinary trunk port

SP-SW1(config)# interface FastEthernet0/24
SP-SW1(config-if)# switchport trunk encapsulation dot1q
SP-SW1(config-if)# switchport mode trunk

! The Fa0/1 interface connects to C1-SW1. Here, apart from 802.1Q-in-Q tunneling,
! the switch is also configured to tunnel selected Layer2 management protocols.
! To assign all Customer1's traffic to SP's VLAN 5, switchport access vlan 5 is
! used.

SP-SW1(config)# interface FastEthernet0/1
SP-SW1(config-if)# switchport mode dot1q-tunnel
SP-SW1(config-if)# switchport access vlan 5
SP-SW1(config-if)# l2protocol-tunnel cdp
SP-SW1(config-if)# l2protocol-tunnel lldp
SP-SW1(config-if)# l2protocol-tunnel stp
SP-SW1(config-if)# l2protocol-tunnel vtp

! The Fa0/2 interface connects to C2-SW1. This is the basic 802.1Q-in-Q tunneling
! configuration without any Layer2 management protocol tunneling

SP-SW1(config)# interface FastEthernet0/2
SP-SW1(config-if)# switchport mode dot1q-tunnel
SP-SW1(config-if)# switchport access vlan 6

! The show interfaces Fa0/1 switchport shows that the interface is operating
! in QinQ tunneling mode. The show vlan (not shown here for brevity) would display
! the Fa0/1 in the Customer1 VLAN just like an ordinary access port.

SP-SW1# show interfaces fa0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: tunnel
Operational Mode: tunnel
Administrative Trunking Encapsulation: negotiate
Operational Trunking Encapsulation: native
Negotiation of Trunking: Off
Access Mode VLAN: 5 (Customer1)
Trunking Native Mode VLAN: 1 (default)
Administrative Native VLAN tagging: enabled
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 Native VLAN tagging: enabled
Administrative private-vlan trunk encapsulation: dot1q
Administrative private-vlan trunk normal VLANs: none
Administrative private-vlan trunk associations: none
Administrative private-vlan trunk mappings: none
Operational private-vlan: none
Trunking VLANs Enabled: ALL
Pruning VLANs Enabled: 2-1001
Capture Mode Disabled
Capture VLANs Allowed: ALL

Protected: false
Unknown unicast blocked: disabled
Unknown multicast blocked: disabled
Appliance trust: none
SP-SW1#