计网实验2-虚拟局域网VLAN实验

虚拟局域网VLAN实验

Date : 2021-10-23

搭建拓扑图

实验软件:【GNS3模拟器、SecureCRT】后续DTP实验需要用Cisco Packet Tracer上做。建议直接使用Packet Tracer。

四台个人主机和两个交换机组成。

实验拓扑图

实验步骤概述

  1. 为每台PC配置IP地址
  2. 为每台交换机配置vlan
  3. 更改交换机接口的状态,查看接口状态协商结果

为PC配置IP地址

要求

PC名称IP地址子网掩码
A1192.168.1.1255.255.255.0
A2192.168.1.2255.255.255.0
A3192.168.1.3255.255.255.0
B1192.168.1.4255.255.255.0
B2192.168.1.5255.255.255.0

配置过程

注意:

  1. Packet Tracer给PC机配置IP如下图所示:
  • 双击PC机
  • 点击顶部栏的Config
  • 点击左侧栏INTERFACE下的FastEthernet接口
  • 在右侧面板中设置IP地址和子网掩码
    Tracer配IP
  1. PC机命令行打开方式:
  • 双击PC机
  • 点击顶部栏的Desktop
  • 点击Command Prompt图标即可进入命令行
    PC机打开命令行
  1. Packet Tracer默认不是特权模式,使用enable命令进入特权模式。
> enable
# ...

A1:(其他PC机同理)

A1# config terminal
A1(config)# interface f0/0
A1(config-if)# ip address 192.168.1.1 255.255.255.0
A1(config-if)# no shutdown
A1(config-if)# end
A1#

测试

使用ping 255.255.255.255 repeat 1发送受限广播(只发送一个包,避免多个包干扰)

在A1处使用。

A1# ping 255.255.255.255 repeat 1

Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 255.255.255.255, timeout is 2 seconds:

Reply to request 0 from 192.168.1.3, 108 ms
Reply to request 0 from 192.168.1.4, 108 ms
Reply to request 0 from 192.168.1.2, 108 ms
Reply to request 0 from 192.168.1.5, 108 ms

配置VLAN

注:当前使用c3640关闭三层路由功能模拟二层交换机,由于ios太旧,使用的vlan配置命令比较旧。

要求

VLAN numberVLAN nameswitchport
2techswitch1: f0/1, f0/3
3salesswitch2: f0/1, f0/2; switch1: f0/2

配置过程

  • switch1
Switch1# vlan database
Switch1(vlan)# vlan 2 name tech
VLAN 2 added:
    Name: tech
Switch1(vlan)# vlan 3 name sales
VLAN 3 added:
    Name: sales
Switch1(vlan)# exit
APPLY completed.
Exiting....

Switch1# config terminal
Switch1(config)# interface f0/1
Switch1(config-if)# switchport mode access
Switch1(config-if)# switchport access vlan 2
Switch1(config-if)# exit

Switch1(config)# interface f0/2
Switch1(config-if)# switchport mode access
Switch1(config-if)# switchport access vlan 3
Switch1(config-if)# exit

Switch1(config)# interface f0/3
Switch1(config-if)# switchport mode access  
Switch1(config-if)# switchport access vlan 2
Switch1(config-if)# exit

Switch1(config)# interface f0/11  
Switch1(config-if)# switchport mode trunk
Switch1(config-if)# end
  • switch2
Switch2# vlan database
Switch2(vlan)# vlan 3 name sales
VLAN 3 added:
    Name: sales
Switch2(vlan)# exit
APPLY completed.
Exiting....

Switch2# config terminal
Switch2(config)# interface f0/1 - 2
Switch2(config-if-range)# switchport mode access
Switch2(config-if-range)# switchport access vlan 3
Switch2(config-if-range)# exit

Switch2(config)# interface f0/11
Switch2(config-if)# switchport mode trunk
Switch2(config-if)# end

测试

  1. 查询vlan配置信息:在模拟器中的命令是show vlan-switch,在现实设备上的命令是show vlan

  2. 查询接口的vlan信息命令:show interface 接口标识 switchport

  3. switch1的预期查询结果:switch1中的f0/1,f0/3都是vlan3状态是access;

    ​ switch1上的f0/2是vlan3状态是access;

    ​ switch1上的f0/11是vlan3状态是trunk.

  4. switch2的预期查询结果:switch2中的f0/1,f0/2都是vlan3状态是access;

    ​ switch2上的f0/11是vlan3状态是trunk.

测试Switch1
  • 查询vlan配置信息
Switch1# show vlan-switch

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/0, Fa0/4, Fa0/5, Fa0/6
                                                Fa0/7, Fa0/8, Fa0/9, Fa0/10
                                                Fa0/12, Fa0/13, Fa0/14, Fa0/15
2    tech                             active    Fa0/1, Fa0/3
3    sales                            active    Fa0/2
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    

VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        1002   1003
2    enet  100002     1500  -      -      -        -    -        0      0   
3    enet  100003     1500  -      -      -        -    -        0      0   
1002 fddi  101002     1500  -      -      -        -    -        1      1003
1003 tr    101003     1500  1005   0      -        -    srb      1      1002
1004 fdnet 101004     1500  -      -      1        ibm  -        0      0   
1005 trnet 101005     1500  -      -      1        ibm  -        0      0  

截图信息如下:
sw1的vlan信息

  • f0/1接口的vlan信息
Switch1# show interface f0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: static access
Operational Mode: static access
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: native
Negotiation of Trunking: Disabled
Access Mode VLAN: 2 (tech)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 2
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none 
Appliance trust: none

其中Administrative Mode就你在接口设置的模式。而Operational Mode就是接口形成的模式。
在这里插入图片描述

  • f0/2接口的vlan信息
Switch1# show interface f0/2 switchport
Name: Fa0/2
Switchport: Enabled
Administrative Mode: static access
Operational Mode: static access
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: native
Negotiation of Trunking: Disabled
Access Mode VLAN: 3 (sales)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 3
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none 
Appliance trust: none
  • f0/11接口的vlan信息
Switch1# show interface f0/11 switchport
Name: Fa0/11
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Disabled
Access Mode VLAN: 0 ((Inactive))
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 1-3
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none 
Appliance trust: none
测试Switch2
  • 查看vlan配置信息
Switch2# show vlan-switch

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/0, Fa0/3, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/12, Fa0/13, Fa0/14
                                                Fa0/15
3    sales                            active    Fa0/1, Fa0/2
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    

VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        1002   1003
3    enet  100003     1500  -      -      -        -    -        0      0   
1002 fddi  101002     1500  -      -      -        -    -        1      1003
1003 tr    101003     1500  1005   0      -        -    srb      1      1002
1004 fdnet 101004     1500  -      -      1        ibm  -        0      0   
1005 trnet 101005     1500  -      -      1        ibm  -        0      0   
  • 查看接口f0/1的vlan信息:
Switch2# show interface f0/1 switchport
Name: Fa0/1
Switchport: Enabled
Administrative Mode: static access
Operational Mode: static access
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: native
Negotiation of Trunking: Disabled
Access Mode VLAN: 3 (sales)
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 3
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none 
Appliance trust: none
  • 查看接口f0/11的vlan信息
Switch2# show interface f0/11 switchport
Name: Fa0/11
Switchport: Enabled
Administrative Mode: trunk
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Disabled
Access Mode VLAN: 0 ((Inactive))
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 1,3
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none 
Appliance trust: none
ping测试
  1. 因为A1和A3在一个虚拟局域网中,所以A1可以ping通A3,而不能ping通A2、B1、B2。
  2. 因为A2和B1、B2在一个虚拟局域网中,所以A2能ping通B1和B2,而不能ping通A1和A2。
  • 在vlan2中测试(在A1上ping)
A1# ping 255.255.255.255 repeat 1

Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 255.255.255.255, timeout is 2 seconds:

Reply to request 0 from 192.168.1.3, 20 ms
  • 在vlan3中测试(在A2上ping)
A2# ping 255.255.255.255 repeat 1

Type escape sequence to abort.
Sending 1, 100-byte ICMP Echos to 255.255.255.255, timeout is 2 seconds:

Reply to request 0 from 192.168.1.4, 20 ms
Reply to request 0 from 192.168.1.5, 20 ms

配置DTP

注:GNS3软件无法做DTP实验,以下改换成Cisco Packet Tracer软件做的。

要求与问题

  • 问题一:将Switch1和Switch2都设置为negotiate模式,考察以下组合,哪些可以形成Trunk?

    -Switch2 - trunkSwitch2 - dynamic desirableSwitch2 - dynamic auto
    Switch1 - trunktrunktrunktrunk
    Switch1 - dynamic desirabletrunktrunktrunk
    Switch1 - dynamic autotrunktrunkaccess
  • 问题二:将Switch1设置为nonegotiate模式,Switch2仍为negotiate模式,再考察以下组合,哪些可以形成Trunk?在配置时与两者都是negotiate模式时有什么区别?注意:考虑将Switch1设置为nonegotiate模式时,Switch1还能否设置为dynamic desirable或dynamic auto模式?

    -Switch2 - trunkSwitch2 - dynamic desirableSwitch2 - dynamic auto
    Switch1 - trunktrunktrunktrunk
    Switch1 - dynamic desirable---
    Switch1 - dynamic auto---
  • 问题分析

    1. 在两边都是negotiate(默认)的模式下,只有两边都是dynamic auto状态时不能形成Trunk。因为auto是被动模式,双方都在等待对方找自己协商。
    2. 在只有Switch1是nonegotiate模式下,Switch1是不能处于dynamic状态的。nonegotiate是不用协商(禁发DTP)就启用Trunk,所以Switch2无论出于哪种状态都会形成Trunk。

配置过程

通过下面的配置方法,把上面的3*3的状态都设置一遍。

negotiate状态(默认)
  • switch1配置
Switch1# config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch1(config)#int f0/11
Switch1(config-if)# shutdown

%LINK-5-CHANGED: Interface FastEthernet0/11, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/11, changed state to down
Switch1(config-if)# switchport mode dynamic desirable
Switch1(config-if)# no shutdown
  • switch2配置
Switch2# config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch2(config)# interface f0/11
Switch2(config-if)# shutdown

%LINK-5-CHANGED: Interface FastEthernet0/11, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/11, changed state to down
Switch2(config-if)# switchport mode dynamic auto
Switch2(config-if)# no shutdown
nonegotiate状态
Switch1# config terminal
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)# interface f0/11
Switch(config-if)# shutdown

%LINK-5-CHANGED: Interface FastEthernet0/11, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/11, changed state to down
Switch(config-if)# switchport nonegotiate
Command rejected: Conflict between 'nonegotiate' and 'dynamic' status.
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport nonegotiate
Switch(config-if)# no shutdown

%LINK-5-CHANGED: Interface FastEthernet0/11, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/11, changed state to up
Switch(config-if)# end

注意:Command rejected: Conflict between ‘nonegotiate’ and ‘dynamic’ status. 说明nonegotiate状态下接口不能是dynamic模式。

测试

通过show interface f0/11 switchport命令观察接口状态。

negotiate状态下
  • Switch1上
Switch1# show interface f0/11 switchport
Name: Fa0/11
Switchport: Enabled
Administrative Mode: dynamic desirable
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
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: 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
  • Switch2上
Switch2# show interface f0/11 switchport
Name: Fa0/11
Switchport: Enabled
Administrative Mode: dynamic auto
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: On
Access Mode VLAN: 1 (default)
Trunking Native Mode VLAN: 1 (default)
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: 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
  • 其他状态测试结果排列组合试一试,不赘述了。
  • 13
    点赞
  • 67
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值