计网实验1——交换机接口配置与VLAN划分
注意事项:
- IP地址、默认网关不需要严格按照文档配置,满足 192.XXX.XX.XX 即可(C类)。
- 创建VLAN后的命名为可选项,不是必要步骤。
1. 实验目的
- 熟悉CISCO Packet Tracer软件功能。
- 掌握二层与三层交换机配置原理并创建子网。
- 掌握网络设备命令行方式及对响应信息的正确解读。
- 按实验要求构造符合要求的实验网络,实现VLAN的划分及VLAN间的通信。
2. 实验器材
- PC一台
- Cisco Packet Tracer 软件
3. 网络拓扑与规划
3.1. 网络设备:
- 4台PC (PC0, PC1, PC2, PC3)
- 1台二层交换机 (2960系列,命名为 SW1)
- 1台三层交换机 (3560或3650系列,命名为 SW0)
3.2. 连接方式:
- PC0 -> SW1 (FastEthernet0/1)
- PC2 -> SW1 (FastEthernet0/3)
- PC1 -> SW1 (FastEthernet0/2)
- PC3 -> SW1 (FastEthernet0/4)
- SW1 (FastEthernet0/24) -> SW0 (FastEthernet0/24)
3.3. IP 地址规划: (使用 192.XXX.XX.XX 网段)
设备 | VLAN | IP 地址 | 子网掩码 | 默认网关 |
---|---|---|---|---|
PC0 | 10 | 192.114.10.10 | 255.255.255.0 | 192.114.10.1 |
PC2 | 10 | 192.114.10.11 | 255.255.255.0 | 192.114.10.1 |
PC1 | 20 | 192.114.20.10 | 255.255.255.0 | 192.114.20.1 |
PC3 | 20 | 192.114.20.11 | 255.255.255.0 | 192.114.20.1 |
SW0 | 10 | 192.114.10.1 | 255.255.255.0 | N/A |
SW0 | 20 | 192.114.20.1 | 255.255.255.0 | N/A |
4. 实验步骤
4.1. 搭建拓扑并配置PC IP地址
- 在Packet Tracer中,按照3.2节所述拖出设备并使用直通线连接。
- 配置PC0:
- 双击PC0 -> Desktop -> IP Configuration.
- IP Address:
192.114.10.10
- Subnet Mask:
255.255.255.0
- Default Gateway:
192.114.10.1
- 配置PC2:
- 双击PC2 -> Desktop -> IP Configuration.
- IP Address:
192.114.10.11
- Subnet Mask:
255.255.255.0
- Default Gateway:
192.114.10.1
- 配置PC1:
- 双击PC1 -> Desktop -> IP Configuration.
- IP Address:
192.114.20.10
- Subnet Mask:
255.255.255.0
- Default Gateway:
192.114.20.1
- 配置PC3:
- 双击PC3 -> Desktop -> IP Configuration.
- IP Address:
192.114.20.11
- Subnet Mask:
255.255.255.0
- Default Gateway:
192.114.20.1
4.2. 配置二层交换机 (SW1)
- 双击SW1 -> CLI选项卡。
- 进入全局配置模式:
1
2
3
4Switch> enable
Switch# configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)# - 配置主机名(可选):
1
2Switch(config)# hostname SW1
SW1(config)# - 创建VLAN 10 和 VLAN 20:
1
2
3
4
5
6SW1(config)# vlan 10
SW1(config-vlan)# name VLAN10_SALES
SW1(config-vlan)# exit
SW1(config)# vlan 20
SW1(config-vlan)# name VLAN20_TECH
SW1(config-vlan)# exit - 配置Access端口并划分VLAN:
- VLAN 10 端口 (连接PC0 - Fa0/1, PC2 - Fa0/3):
1
2
3
4
5
6
7
8
9
10
11
12
13SW1(config)# interface FastEthernet0/1
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 10
SW1(config-if)# spanning-tree portfast
SW1(config-if)# no shutdown
SW1(config-if)# exit
SW1(config)# interface FastEthernet0/3
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 10
SW1(config-if)# spanning-tree portfast
SW1(config-if)# no shutdown
SW1(config-if)# exit - VLAN 20 端口 (连接PC1 - Fa0/2, PC3 - Fa0/4):
1
2
3
4
5
6
7
8
9
10
11
12
13SW1(config)# interface FastEthernet0/2
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
SW1(config-if)# spanning-tree portfast
SW1(config-if)# no shutdown
SW1(config-if)# exit
SW1(config)# interface FastEthernet0/4
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
SW1(config-if)# spanning-tree portfast
SW1(config-if)# no shutdown
SW1(config-if)# exit
- VLAN 10 端口 (连接PC0 - Fa0/1, PC2 - Fa0/3):
- 配置Trunk端口 (FastEthernet0/24 连接到 SW0 Fa0/24):
1
2
3
4
5
6SW1(config)# interface FastEthernet0/24
SW1(config-if)# switchport trunk encapsulation dot1q
SW1(config-if)# switchport mode trunk
SW1(config-if)# switchport trunk allowed vlan 10,20
SW1(config-if)# no shutdown
SW1(config-if)# exit - 保存配置:
1
2SW1(config)# end
SW1# write memory - 验证SW1配置:
1
2
3SW1# show vlan brief
SW1# show interfaces trunk
SW1# show running-config
4.3. 配置三层交换机 (SW0) - 基础部分
- 双击SW0 -> CLI选项卡。
- 进入全局配置模式:
1
2
3Switch> enable
Switch# configure terminal
Switch(config)# - 配置主机名(可选):
1
2Switch(config)# hostname SW0
SW0(config)# - 创建VLAN 10 和 VLAN 20:
1
2
3
4
5
6SW0(config)# vlan 10
SW0(config-vlan)# name SW0_VLAN10
SW0(config-vlan)# exit
SW0(config)# vlan 20
SW0(config-vlan)# name SW0_VLAN20
SW0(config-vlan)# exit - 配置Trunk端口 (FastEthernet0/24 连接到 SW1 Fa0/24):
1
2
3
4
5
6SW0(config)# interface FastEthernet0/24
SW0(config-if)# switchport trunk encapsulation dot1q
SW0(config-if)# switchport mode trunk
SW0(config-if)# switchport trunk allowed vlan 10,20
SW0(config-if)# no shutdown
SW0(config-if)# exit
4.3.A. 初步连通性测试 (配置SVI和启用路由前)
目的: 验证VLAN间的隔离效果,以及PC无法访问尚未配置的网关。
- 测试同VLAN内通信:
- 从PC0 (
192.114.10.10
) ping PC2 (192.114.10.11
):预期结果: 成功。1
C:\> ping 192.114.10.11
- 从PC1 (
192.114.20.10
) ping PC3 (192.114.20.11
):预期结果: 成功。1
C:\> ping 192.114.20.11
- 从PC0 (
- 测试VLAN间通信:
- 从PC0 (
192.114.10.10
) ping PC1 (192.114.20.10
):预期结果: 失败。1
C:\> ping 192.114.20.10
- 从PC0 (
- 测试PC到其配置的默认网关的连通性:
- 从PC0 (
192.114.10.10
) ping其默认网关 (192.114.10.1
):预期结果: 失败。1
C:\> ping 192.114.10.1
记录: 截图上述ping测试的结果,特别是失败的测试,用于对比后续配置完成后的结果。
- 从PC0 (
4.3.B. 配置三层交换机 (SW0) - SVI及路由配置
(继续在SW0的全局配置模式下操作)
- 配置SVI (Switched Virtual Interfaces) 作为VLAN网关:
- VLAN 10 SVI:
1
2
3
4
5SW0(config)# interface Vlan10
SW0(config-if)# ip address 192.114.10.1 255.255.255.0
SW0(config-if)# description Gateway_for_VLAN10
SW0(config-if)# no shutdown
SW0(config-if)# exit - VLAN 20 SVI:
1
2
3
4
5SW0(config)# interface Vlan20
SW0(config-if)# ip address 192.114.20.1 255.255.255.0
SW0(config-if)# description Gateway_for_VLAN20
SW0(config-if)# no shutdown
SW0(config-if)# exit
- VLAN 10 SVI:
- 启用IP路由功能:
1
SW0(config)# ip routing
- 保存配置:
1
2SW0(config)# end
SW0# write memory - 验证SW0配置:确保
1
2
3SW0# show ip interface brief
SW0# show ip route
SW0# show running-configVlan10
和Vlan20
接口状态为up/up
,并且路由表中有对应VLAN的直连路由。
4.4. 最终连通性测试 (配置SVI和启用路由后)
- 再次测试同VLAN内通信 (应仍然成功):
- 从PC0 (
192.114.10.10
) ping PC2 (192.114.10.11
) -> 应成功。 - 从PC1 (
192.114.20.10
) ping PC3 (192.114.20.11
) -> 应成功。
- 从PC0 (
- 再次测试VLAN间通信 (Inter-VLAN Routing):
- 从PC0 (
192.114.10.10
) ping PC1 (192.114.20.10
):预期结果: 成功。1
C:\> ping 192.114.20.10
- 从PC0 (
192.114.10.10
) ping PC3 (192.114.20.11
):预期结果: 成功。1
C:\> ping 192.114.20.11
- 从PC0 (
- 再次测试PC到其默认网关的连通性:
- 从PC0 ping其网关 (
192.114.10.1
):预期结果: 成功。1
C:\> ping 192.114.10.1
- 从PC1 ping其网关 (
192.114.20.1
):预期结果: 成功。1
C:\> ping 192.114.20.1
- 从PC0 ping其网关 (
5. 实验结果与分析 (实验报告内容)
- 配置文件:
- SW1的
show running-config
输出。 - SW0的
show running-config
输出。
- SW1的
- Ping测试截图:
- 初步测试 (4.3.A节): PC0 ping PC2 (成功),PC0 ping PC1 (失败),PC0 ping
192.114.10.1
(失败)。 - 最终测试 (4.4节): PC0 ping PC2 (成功),PC0 ping PC1 (成功),PC0 ping
192.114.10.1
(成功)。
- 初步测试 (4.3.A节): PC0 ping PC2 (成功),PC0 ping PC1 (失败),PC0 ping
- 结果分析:
- 对比初步测试和最终测试的结果,解释VLAN隔离和VLAN间路由实现的过程。
- 简述VLAN配置如何在SW1上隔离了广播域。
- 解释Trunk链路在SW1和SW0之间的作用。
- 说明SW0上SVI的用途以及
ip routing
命令的重要性。 - 根据
show ip route
的输出,分析SW0是如何学习到VLAN 10和VLAN 20的路由的。 - 总结实验成功的关键配置点。
6. 故障排除提示
- PC无法ping通同VLAN内的其他PC:
- 检查PC的IP地址、子网掩码是否在同一网段。
- 检查SW1上对应端口的VLAN分配是否正确 (
show vlan brief
)。 - 检查SW1上对应端口是否为
access
模式且已no shutdown
(show running-config
或show interface <interface> status
)。 - 检查物理连接(在Packet Tracer中看连接线是否为绿色)。
- PC无法ping通不同VLAN的PC,但可以ping通同VLAN的PC:
- 最常见原因: PC的默认网关配置错误或未配置。确保指向SW0上正确的SVI IP地址。
- 检查SW0上对应VLAN的SVI是否已创建、IP地址是否正确、是否已
no shutdown
(show ip interface brief
)。 - 检查SW0上是否已启用
ip routing
(show running-config | include ip routing
或show ip route
)。 - 检查SW1与SW0之间的Trunk链路是否配置正确(两端封装、模式、允许的VLAN是否匹配)。
- 检查SW0的路由表 (
show ip route
) 是否有到达目标VLAN的路由。
- Trunk链路不工作或部分VLAN无法通过:
- 确保两端交换机的Trunk端口封装类型一致 (如
dot1q
)。 - 确保两端交换机的Trunk端口都配置为
switchport mode trunk
。 - 检查
switchport trunk allowed vlan
命令,确保需要的VLAN都被允许通过。如果未指定,则默认允许所有VLAN,但也需检查Native VLAN配置是否一致(一般实验保持默认即可)。
- 确保两端交换机的Trunk端口封装类型一致 (如
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.