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

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

  • 虚拟局域网VLAN实验
    • 搭建拓扑图
    • 实验步骤概述
    • 为PC配置IP地址
      • 要求
      • 配置过程
      • 测试
    • 配置VLAN
      • 要求
      • 配置过程
      • 测试
        • 测试Switch1
        • 测试Switch2
        • ping测试
    • 配置DTP
      • 要求与问题
      • 配置过程
        • negotiate状态(默认)
        • nonegotiate状态
      • 测试
        • negotiate状态下

虚拟局域网VLAN实验

Date : 2021-10-23

搭建拓扑图

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

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

计网实验2-虚拟局域网VLAN实验_第1张图片

实验步骤概述

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

为PC配置IP地址

要求

PC名称 IP地址 子网掩码
A1 192.168.1.1 255.255.255.0
A2 192.168.1.2 255.255.255.0
A3 192.168.1.3 255.255.255.0
B1 192.168.1.4 255.255.255.0
B2 192.168.1.5 255.255.255.0

配置过程

注意:

  1. Packet Tracer给PC机配置IP如下图所示:
  • 双击PC机
  • 点击顶部栏的Config
  • 点击左侧栏INTERFACE下的FastEthernet接口
  • 在右侧面板中设置IP地址和子网掩码
    计网实验2-虚拟局域网VLAN实验_第2张图片
  1. PC机命令行打开方式:
  • 双击PC机
  • 点击顶部栏的Desktop
  • 点击Command Prompt图标即可进入命令行
    计网实验2-虚拟局域网VLAN实验_第3张图片
  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 number VLAN name switchport
2 tech switch1: f0/1, f0/3
3 sales switch2: 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  

截图信息如下:
计网实验2-虚拟局域网VLAN实验_第4张图片

  • 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就是接口形成的模式。
计网实验2-虚拟局域网VLAN实验_第5张图片

  • 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 - trunk Switch2 - dynamic desirable Switch2 - dynamic auto
    Switch1 - trunk trunk trunk trunk
    Switch1 - dynamic desirable trunk trunk trunk
    Switch1 - dynamic auto trunk trunk access
  • 问题二:将Switch1设置为nonegotiate模式,Switch2仍为negotiate模式,再考察以下组合,哪些可以形成Trunk?在配置时与两者都是negotiate模式时有什么区别?注意:考虑将Switch1设置为nonegotiate模式时,Switch1还能否设置为dynamic desirable或dynamic auto模式?

    - Switch2 - trunk Switch2 - dynamic desirable Switch2 - dynamic auto
    Switch1 - trunk trunk trunk trunk
    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
  • 其他状态测试结果排列组合试一试,不赘述了。

你可能感兴趣的:(计算机网络,网络,VLAN实验,DTP实验,nonegotiate,trunk)