VLAN的基本配置和包传输路径测试

来源:互联网 发布:mac上的网游 编辑:程序博客网 时间:2024/05/29 16:08

VLAN基本配置网络拓扑如下

配置S2

创建vlan

Switch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#vlan 10Switch(config-vlan)#name teacherSwitch(config-vlan)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#---------------------------------------------------------------------------------------------Switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#vlan 20Switch(config-vlan)#name studentSwitch(config-vlan)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#

查看vlan是否已创建

Switch#show vlanVLAN 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/2410   teacher                          active    20   student                          active    1002 fddi-default                     act/unsup 1003 token-ring-default               act/unsup 1004 fddinet-default                  act/unsup 1005 trnet-default                    act/unsup VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------1    enet  100001     1500  -      -      -        -    -        0      010   enet  100010     1500  -      -      -        -    -        0      020   enet  100020     1500  -      -      -        -    -        0      01002 fddi  101002     1500  -      -      -        -    -        0      0   1003 tr    101003     1500  -      -      -        -    -        0      0   1004 fdnet 101004     1500  -      -      -        ieee -        0      0   1005 trnet 101005     1500  -      -      -        ibm  -        0      0   VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------Remote SPAN VLANs------------------------------------------------------------------------------Primary Secondary Type              Ports------- --------- ----------------- ------------------------------------------Switch# 

为VLAN分配端口

Switch# conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#inter fa0/18Switch(config-if)#switch mode accessSwitch(config-if)#switch access vlan 20Switch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#Switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#inter fa0/11Switch(config-if)#switch mode accessSwitch(config-if)#switch access vlan 10Switch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#

建立trunk链路

Switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#inter fa0/3Switch(config-if)#switch mode trunkSwitch(config-if)#%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upSwitch(config-if)#switch trunk allowed valn 10,20                                        ^% Invalid input detected at '^' marker.Switch(config-if)#switch trunk allowed vlan 10,20Switch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#

show 显示配置后的结果

Switch#show vlanVLAN Name                             Status    Ports---- -------------------------------- --------- -------------------------------1    default                          active    Fa0/1, Fa0/2, Fa0/4, Fa0/【这里没有Fa0/3了,说明trunk配置可以】                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9                                                Fa0/10, Fa0/12, Fa0/13, Fa0/14                                                Fa0/15, Fa0/16, Fa0/17, Fa0/19                                                Fa0/20, Fa0/21, Fa0/22, Fa0/23                                                Fa0/2410   teacher                          active    Fa0/1120   student                          active    Fa0/181002 fddi-default                     act/unsup 1003 token-ring-default               act/unsup 1004 fddinet-default                  act/unsup 1005 trnet-default                    act/unsup VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------1    enet  100001     1500  -      -      -        -    -        0      010   enet  100010     1500  -      -      -        -    -        0      020   enet  100020     1500  -      -      -        -    -        0      01002 fddi  101002     1500  -      -      -        -    -        0      0   1003 tr    101003     1500  -      -      -        -    -        0      0   1004 fdnet 101004     1500  -      -      -        ieee -        0      0   1005 trnet 101005     1500  -      -      -        ibm  -        0      0   VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------Remote SPAN VLANs------------------------------------------------------------------------------Primary Secondary Type              Ports------- --------- ----------------- ------------------------------------------Switch#

配置S0

Switch>enSwitch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#valn 10                ^% Invalid input detected at '^' marker.Switch(config)#vlan 10Switch(config-vlan)#name webSwitch(config-vlan)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#vlan 20Switch(config-vlan)#name mailSwitch(config-vlan)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#

给两个vlan配置相应的端口

Switch#Switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#inter fa0/2Switch(config-if)#switch mode accessSwitch(config-if)#switch access vlan 10Switch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#inter fa0/4Switch(config-if)#switch mode accessSwitch(config-if)#switch access vlan 20Switch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#

配置trunk端口

Switch#conf tEnter configuration commands, one per line.  End with CNTL/Z.Switch(config)#inter fa0/3Switch(config-if)#switch mode trunkSwitch(config-if)#switch trunk allowed vlan 10.20Switch(config-if)#switch trunk allowed vlan 10,20Switch(config-if)#endSwitch#%SYS-5-CONFIG_I: Configured from console by consoleSwitch#

show显示配置后的结果

Switch#show vlanVLAN Name                             Status    Ports---- -------------------------------- --------- -------------------------------1    default                          active    Fa0/1, 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/2410   web                              active    Fa0/220   mail                             active    Fa0/41002 fddi-default                     act/unsup 1003 token-ring-default               act/unsup 1004 fddinet-default                  act/unsup 1005 trnet-default                    act/unsup VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------1    enet  100001     1500  -      -      -        -    -        0      010   enet  100010     1500  -      -      -        -    -        0      020   enet  100020     1500  -      -      -        -    -        0      01002 fddi  101002     1500  -      -      -        -    -        0      0   1003 tr    101003     1500  -      -      -        -    -        0      0   1004 fdnet 101004     1500  -      -      -        ieee -        0      0   1005 trnet 101005     1500  -      -      -        ibm  -        0      0   VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------Remote SPAN VLANs------------------------------------------------------------------------------Primary Secondary Type              Ports------- --------- ----------------- ------------------------------------------Switch#

查看S2上的trunk端口

Switch#show inter trunkPort        Mode         Encapsulation  Status        Native vlanFa0/3       on           802.1q         trunking      1Port        Vlans allowed on trunkFa0/3       10,20Port        Vlans allowed and active in management domainFa0/3       10,20Port        Vlans in spanning tree forwarding state and not prunedFa0/3       10,20Switch#

查看S0上的trunk端口

Switch#show inter trunkPort        Mode         Encapsulation  Status        Native vlanFa0/3       on           802.1q         trunking      1Port        Vlans allowed on trunkFa0/3       10,20Port        Vlans allowed and active in management domainFa0/3       10,20Port        Vlans in spanning tree forwarding state and not prunedFa0/3       10,20Switch#

在PC0上ping mail服务器

在PC0上ping另一个VLAN中的服务器

在VLAN20中的PC0去pingVLAN10中的PC1

对于另一个VLAN中的设备同理

包传输路径测试

在同一VLAN中通信
由PC0到S2的ICMP数据包

S2即将要发出的数据包,可以看到帧已经被插入了一段标记


S2通过TRUNK链路发送给S0,S0收到数据包,可以看出此时帧中带着被插入的标记


S0要发出的数据包如下,可见已经去掉了标记,

sever收到数据包

准备发回数据包,要发回的数据包如下

原创粉丝点击