2025-10-14-计算机网络实验二-交换机基本配置与远程登录(Telnet)
一、实验目标
掌握:
- 交换机的不同模式切换
 - 交换机的基本配置(改名、设密码、查看配置)
 - 交换机接口和 VLAN 配置
 - 通过 telnet 登录交换机
 
二、实验拓扑
连接关系:
PC2 <—— 直通线 ——> Switch0
IP 地址分配(举例学号末两位为 55):
| 设备 | 接口 | IP 地址 | 子网掩码 | 
|---|---|---|---|
| PC2 | FastEthernet0 | 10.1.1.55 | 255.255.255.0 | 
| Switch0 | VLAN1 | 10.1.1.65 | 255.255.255.0 | 
三、实验步骤与命令讲解
1️ 模式切换练习
在交换机 CLI 中操作:
| 模式 | 提示符 | 进入命令 | 说明 | 
|---|---|---|---|
| 用户模式 | Switch> | 
——(开机默认) | 只能查看基本信息 | 
| 特权模式 | Switch# | 
enable | 
可以查看和保存配置 | 
| 全局配置模式 | Switch(config)# | 
configure terminal | 
可以修改全局参数 | 
| 接口配置模式 | Switch(config-if)# | 
interface fastethernet0/1 | 
配置具体端口参数 | 
提示:
- 输入 
?可以查看该模式下能用的命令 Ctrl+Z或end返回上一级exit退出当前模式
2️ 修改交换机名称和设置口令
Switch> enable                          # 进入特权模式
Switch# configure terminal              # 进入全局配置模式
Switch(config)# hostname Switch2950     # 修改主机名
Switch2950(config)# enable secret cisco # 设置特权模式加密密码
Switch2950(config)# line console 0      # 进入控制台配置
Switch2950(config-line)# password cisco # 设置 console 口令
Switch2950(config-line)# login          # 开启登录验证
Switch2950(config-line)# exit
Switch2950(config)# line vty 0 4        # 进入远程登录配置
Switch2950(config-line)# password cisco # 设置 telnet 密码
Switch2950(config-line)# login
Switch2950(config-line)# exit
Switch2950(config)# service password-encryption # 对明文密码加密
Switch2950(config)# end
命令解释:
hostname:修改设备名字enable secret:设置进入特权模式的加密密码line console 0:进入控制台口配置视图line vty 0 4:进入虚拟终端(Telnet)配置login:开启密码验证service password-encryption:对配置文件中的密码加密
3️ 配置接口与 VLAN 管理 IP
Switch2950# configure terminal
Switch2950(config)# interface vlan 1
Switch2950(config-if)# ip address 10.1.1.65 255.255.255.0
Switch2950(config-if)# no shutdown
Switch2950(config-if)# exit
Switch2950(config)# interface fastethernet0/1
Switch2950(config-if)# switchport mode access
Switch2950(config-if)# switchport access vlan 1
Switch2950(config-if)# no shutdown
Switch2950(config-if)# end
命令解释:
interface vlan 1:进入 VLAN 1 接口配置,用作管理 IPip address:设置 IP 地址no shutdown:开启接口(默认关闭)switchport mode access:指定为普通接入口(非 trunk)switchport access vlan 1:将该端口加入 VLAN 1
4️ 查看与保存配置
Switch2950# show running-config     # 查看当前运行配置
Switch2950# copy running-config startup-config
说明:
show running-config:查看当前配置copy running-config startup-config:保存配置(否则重启后会丢失)
5️ 在 PC 上设置 IP
在 PC2 → Desktop → IP Configuration 中设置:
IP Address: 10.1.1.55
Subnet Mask: 255.255.255.0
Default Gateway: 10.1.1.65
6️ 测试连通性
在 PC 命令行输入:
ping 10.1.1.65
出现:
Reply from 10.1.1.65: bytes=32 time<1ms TTL=255
表示配置成功。
7️ Telnet 登录验证(可选进阶)
在 PC 命令行输入:
telnet 10.1.1.65输入密码
cisco登录成功后输入:
enable再输入特权密码(也是
cisco)
表示已通过 Telnet 远程管理交换机。
四、常用命令速查表
| 功能 | 命令 | 
|---|---|
| 进入特权模式 | enable | 
| 进入全局配置 | configure terminal | 
| 查看配置 | show running-config | 
| 保存配置 | copy running-config startup-config | 
| 修改设备名 | hostname XXX | 
| 设置特权密码 | enable secret 密码 | 
| 设置 console 密码 | line console 0 → password 密码 → login | 
| 设置 telnet 密码 | line vty 0 4 → password 密码 → login | 
| 配置 VLAN IP | interface vlan 1 → ip address X.X.X.X 255.255.255.0 | 
| 启动接口 | no shutdown | 
| 查看端口状态 | show interfaces status | 
运行结果
- 网络拓扑图

 - PC2 ping 交换机成功
