交换机之间应该使用交叉线,交换机与主机之间应该使用直通线
实验目标:
1.学会配置trunk,实现端到端VLAN的通信
2.配置trunk的流量控制
3.修改native vlan
实验步骤:
1.根据拓扑图,在SW0,SW1创建VLAN并命名
2.在SW0,SW1划分端口至相应的VLAN,并配置PC的IP地址
3.使用静态trunk模式,配置SW0,SW1之间的trunk
4.测试端到端VLAN的通信
5.在trunk上移除VLAN3的流量,使得SW0和SW1之间的VLAN3不能通信
6.在trunk上允许VLAN3的流量,使得SW0和SW1之间的VLAN3能通信
7.修改native VLAN 为90
VLAN不可能都在一台交换机上部署,要使跨交换机VLAN之间能够通,用trunk(端与端之间VLAN的通信)
实验拓扑图:
第一步:配置IP 地址
在SW0和SW1创建VLAN并命名+划分端口至相应的VLAN
SW0:
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 2 //创建VLAN2
Switch(config-vlan)#name fd //将VLAN2命名为fd
Switch(config-vlan)#exit
Switch(config)#vlan 3 //创建VLAN2
Switch(config-vlan)#name it //将VLAN2命名为it
Switch(config-vlan)#exit
Switch(config)#interface fastethernet 0/1 //端口 1
Switch(config-if)#switchport access vlan 2 /将端口 1 加入 vlan2 中
Switch(config-if)#exit
Switch(config)#interface fastethernet 0/2 //端口 2
Switch(config-if)#switchport access vlan 2 //将端口 2 加入 vlan2 中
Switch(config-if)#exit
Switch(config)#interface range fa0/3-5 //端口 3,4,5
Switch(config-if-range)#switchport access vlan 3 //将端口 3,4,5 加入 vlan2 中
Switch(config-if-range)#exit
Switch(config)#do show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/6, Fa0/7, Fa0/8, Fa0/9
Fa0/10, Fa0/11, Fa0/12, Fa0/13
Fa0/14, Fa0/15, Fa0/16, Fa0/17
Fa0/18, Fa0/19, Fa0/20, Fa0/21
Fa0/22, Fa0/23, Fa0/24
2 fd active Fa0/1, Fa0/2 //端口1,2是VLAN2
3 it active Fa0/3, Fa0/4, Fa0/5 //端口3,4,5是VLAN3
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
Switch(config)#
SW1:
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#do show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/1, Fa0/2, Fa0/3, Fa0/4
Fa0/5, Fa0/6, Fa0/7, Fa0/8
Fa0/9, Fa0/10, Fa0/11, Fa0/12
Fa0/13, Fa0/14, Fa0/15, Fa0/16
Fa0/17, Fa0/18, Fa0/19, Fa0/20
Fa0/21, Fa0/22, Fa0/23, Fa0/24
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
Switch(config)#
Switch(config)#vlan 2 // 创建VLAN 2
Switch(config-vlan)#name fd //命名
Switch(config-vlan)#exit
Switch(config)#vlan 3 // 创建VLAN 3
Switch(config-vlan)#name it //命名
Switch(config-vlan)#exit
Switch(config)#interface fastethernet0/1 // 端口1
Switch(config-if)#switchport ?
access Set access mode characteristics of the interface
mode Set trunking mode of the interface
native Set trunking native characteristics when interface is in
trunking mode
nonegotiate Device will not engage in negotiation protocol on this
interface
port-security Security related command
priority Set appliance 802.1p priority
trunk Set trunking characteristics of the interface
voice Voice appliance attributes
Switch(config-if)#switchport access vlan 2 //划分端口1到VLAN2
Switch(config-if)#exit
Switch(config)#interface fastethernet 0/2 // 端口2
Switch(config-if)#switchport access vlan 3 // 划分端口2到VLAN3
Switch(config-if)#exit
Switch(config)#do show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa0/3, Fa0/4, Fa0/5, Fa0/6
Fa0/7, Fa0/8, Fa0/9, Fa0/10
Fa0/11, Fa0/12, Fa0/13, Fa0/14
Fa0/15, Fa0/16, Fa0/17, Fa0/18
Fa0/19, Fa0/20, Fa0/21, Fa0/22
Fa0/23, Fa0/24
2 fd active Fa0/1
3 it active Fa0/2
1002 fddi-default active
1003 token-ring-default active
1004 fddinet-default active
1005 trnet-default active
Switch(config)#
Switch#
%SYS-5-CONFIG_I: Configured from console by console
第三步:测试
端与端相同的VLAN不连通,一个交换机下的相同VLAN连通
第四步:使用静态trunk模式,配置SW0,SW1之间的trunk
SW0:
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface faste ?
<0-9> FastEthernet interface number
Switch(config)#interface fastEthernet 0/24
Switch(config-if)#switchport mode trunk /设置端口 24为 trunk 模式
SW1:
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface fastEthernet 0/24 /交换机1的24端口
Switch(config-if)#switchport mode trunk /24端口设为trunk模式
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#show run
Building configuration...
Current configuration : 1046 bytes
!
version 12.1
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch
!
!
spanning-tree mode pvst
!
interface FastEthernet0/1
switchport access vlan 2
!
interface FastEthernet0/2
switchport access vlan 3
!
interface FastEthernet0/3
!
interface FastEthernet0/4
!
interface FastEthernet0/5
!
interface FastEthernet0/6
!
interface FastEthernet0/7
!
interface FastEthernet0/8
!
interface FastEthernet0/9
!
interface FastEthernet0/10
!
interface FastEthernet0/11
!
interface FastEthernet0/12
!
interface FastEthernet0/13
!
interface FastEthernet0/14
!
interface FastEthernet0/15
!
interface FastEthernet0/16
!
interface FastEthernet0/17
!
interface FastEthernet0/18
!
interface FastEthernet0/19
!
interface FastEthernet0/20
!
interface FastEthernet0/21
!
interface FastEthernet0/22
!
interface FastEthernet0/23
!
interface FastEthernet0/24
switchport mode trunk
!
interface Vlan1
no ip address
shutdown
!
!
line con 0
!
line vty 0 4
login
line vty 5 15
login
!
!
end
测试端到端VLAN的通信
在trunk上移除VLAN3的流量,使得SW0和SW1之间的VLAN3不能通信
SW0:
Switch(config)#do show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-1005
Port Vlans allowed and active in management domain
Fa0/24 1,2,3
Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 none
Switch(config)#interface fastethernet 0/24 /
Switch(config-if)#switchport trunk ?
allowed Set allowed VLAN characteristics when interface is in trunking mode
native Set trunking native characteristics when interface is in trunking
mode
Switch(config-if)#switchport trunk allowed vlan remove 3 /将VLAN3从vlan允许移除
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-2,4-1005 //不允许VLAN3通过24端口
Port Vlans allowed and active in management domain
Fa0/24 1,2
Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 1,2
Switch#
SW1同样也是如上操作,
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface faste ?
<0-9> FastEthernet interface number
Switch(config)#interface fastEthernet 0/24
Switch(config-if)#switchport mode trunk
Switch(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/24, changed state to up
Switch(config-if)#exit
Switch(config)#do show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-1005
Port Vlans allowed and active in management domain
Fa0/24 1,2,3
Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 none
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport ?
access Set access mode characteristics of the interface
mode Set trunking mode of the interface
native Set trunking native characteristics when interface is in
trunking mode
nonegotiate Device will not engage in negotiation protocol on this
interface
port-security Security related command
priority Set appliance 802.1p priority
trunk Set trunking characteristics of the interface
voice Voice appliance attributes
Switch(config-if)#switchport access ?
vlan Set VLAN when interface is in access mode
Switch(config-if)#switchport mode ?
access Set trunking mode to ACCESS unconditionally
dynamic Set trunking mode to dynamically negotiate access or trunk mode
trunk Set trunking mode to TRUNK unconditionally
Switch(config-if)#switchport mode access ?
<cr>
Switch(config-if)#switchport trunk ?
allowed Set allowed VLAN characteristics when interface is in trunking mode
native Set trunking native characteristics when interface is in trunking
mode
Switch(config-if)#switchport trunk allowed vlan remove 3
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-2,4-1005
Port Vlans allowed and active in management domain
Fa0/24 1,2
Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 1,2
Switch#
结果:
VLAN3不允许通过,其他VLAN可以。
在trunk上允许VLAN3的流量,使得SW0和SW1之间的VLAN3能通信
核心:
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport trunk allowed vlan add 3
SW0,SW1一样:
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport trunk allowed vlan add 3
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 1
Port Vlans allowed on trunk
Fa0/24 1-1005
Port Vlans allowed and active in management domain
Fa0/24 1,2,3
Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 1,2,3
Switch#
Switch#
PC0 ping PC5 通
PC2 ping PC6 通
修改native VLAN 为90
Switch>enable
Switch#config t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport trunk ?
allowed Set allowed VLAN characteristics when interface is in trunking mode
native Set trunking native characteristics when interface is in trunking
mode
Switch(config-if)#switchport trunk native vlan 90 //这句话
Switch(config-if)#end
Switch#
%SYS-5-CONFIG_I: Configured from console by console
Switch#show interface trunk
Port Mode Encapsulation Status Native vlan
Fa0/24 on 802.1q trunking 90 //结果
Port Vlans allowed on trunk
Fa0/24 1-1005
Port Vlans allowed and active in management domain
Fa0/24 1,2,3
Port Vlans in spanning tree forwarding state and not pruned
Fa0/24 1,2,3
Switch#
Switch#
Switch#
%CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on FastEthernet0/24 (90), with Switch FastEthernet0/24 (1).
每60s报错一次,因为native vlan 不同
%CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on FastEthernet0/24 (90), with Switch FastEthernet0/24 (1).
%CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on FastEthernet0/24 (90), with Switch FastEthernet0/24 (1).
%CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on FastEthernet0/24 (90), with Switch FastEthernet0/24 (1).
%CDP-4-NATIVE_VLAN_MISMATCH: Native VLAN mismatch discovered on FastEthernet0/24 (90), with Switch FastEthernet0/24 (1).
总结:
创建VLAN并命名:
Switch(config)#vlan 2 //创建VLAN2
Switch(config-vlan)#name fd //将VLAN2命名为fd
将端口划分VLAN:
Switch(config)#interface fastethernet 0/2 // 端口2
Switch(config-if)#switchport access vlan 3 // 划分端口2到VLAN3
将接口设为trunk模式:
Switch(config)#interface fastEthernet 0/24 /交换机1的24端口
Switch(config-if)#switchport mode trunk /24端口设为trunk模式
在trunk上移除VLAN3的流量,使得SW0和SW1之间的VLAN3不能通信:
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport trunk allowed vlan remove 3 /将VLAN3从vlan允许移除
在trunk上允许VLAN3的流量,使得SW0和SW1之间的VLAN3能通信:
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport trunk allowed vlan add 3
修改native VLAN 为90:
Switch(config)#interface fastethernet 0/24
Switch(config-if)#switchport trunk native vlan 90 //这句话