菜鸟科技网

交换机串口命令有哪些常用操作?

交换机串口命令是网络管理员进行设备配置、监控和故障排查的重要工具,通过串口连接可以实现对交换机的直接管理,尤其在无网络环境或设备初始化配置时不可替代,以下从串口连接基础、常用命令分类、配置实例及注意事项等方面进行详细说明。

交换机串口命令有哪些常用操作?-图1
(图片来源网络,侵删)

串口连接基础

在使用串口命令前,需确保物理连接正确,通常使用Console线(一端为RJ-45,另一端为DB-9或USB)连接交换机的Console口和计算机的串口/USB口,连接后,需通过终端软件(如SecureCRT、PuTTY、Xshell等)建立会话,参数一般设置为:波特率9600、数据位8、停止位1、无校验、无流控制,不同品牌交换机的默认参数可能略有差异,如华为部分型号波特率为115200,需参考设备手册。

常用命令分类及详解

用户模式与特权模式切换

  • 用户模式(User Mode):登录后默认进入,提示符为Switch>,仅能执行基本查看命令。
    Switch>enable        # 从用户模式进入特权模式
    Switch#disable       # 从特权模式返回用户模式
  • 特权模式(Privileged Mode):提示符为Switch#,可查看设备信息、保存配置等。
    Switch#configure terminal  # 进入全局配置模式
    Switch(config)#             # 全局配置模式提示符

基本系统配置

  • 设备命名:便于区分多台设备。
    Switch(config)#hostname Switch-A
  • 管理IP配置:通过Telnet/SSH远程管理时需配置VLAN接口IP。
    Switch(config)#interface vlan 1
    Switch(config-if)#ip address 192.168.1.1 255.255.255.0
    Switch(config-if)#no shutdown
  • 密码设置:包括Console登录密码、特权模式密码等。
    Switch(config)#line console 0
    Switch(config-line)#password console123
    Switch(config-line)#login
    Switch(config)#enable secret privilege123  # 特权模式加密密码

VLAN配置

VLAN用于隔离广播域,提升网络安全性。

Switch(config)#vlan 10                 # 创建VLAN 10
Switch(config-vlan)#name Sales         # 命名VLAN
Switch(config)#interface gigabitethernet 0/1  # 进入接口
Switch(config-if)#switchport mode access    # 设置为接入模式
Switch(config-if)#switchport access vlan 10 # 将接口划入VLAN 10

接口配置

  • 二层接口:默认为二层交换接口,可配置速率、双工模式。
    Switch(config-if)#speed 100
    Switch(config-if)#duplex full
  • 三层接口:需切换为路由模式并配置IP。
    Switch(config-if)#no switchport
    Switch(config-if)#ip address 10.1.1.1 255.255.255.0

路由配置

  • 静态路由:适用于小型网络固定路径。
    Switch(config)#ip route 192.168.2.0 255.255.255.0 10.1.1.2
  • 动态路由:如RIP协议配置。
    Switch(config)#router rip
    Switch(config-router)#version 2
    Switch(config-router)#network 192.168.1.0

端口安全

限制接口接入的MAC地址数量,防止非法设备接入。

Switch(config-if)#switchport port-security
Switch(config-if)#switchport port-security maximum 2  # 最大2个MAC
Switch(config-if)#switchport port-security violation shutdown  # 违规关闭端口

DHCP服务配置

为客户端自动分配IP地址。

交换机串口命令有哪些常用操作?-图2
(图片来源网络,侵删)
Switch(config)#ip dhcp pool POOL1
Switch(dhcp-config)#network 192.168.1.0 255.255.255.0
Switch(dhcp-config)#default-router 192.168.1.1
Switch(dhcp-config)#dns-server 8.8.8.8
Switch(config)#ip dhcp excluded-address 192.168.1.1 192.168.1.10  # 排除静态IP

网络服务启用

  • Telnet/SSH:远程管理协议。
    Switch(config)#line vty 0 4
    Switch(config-line)#transport input ssh  # 仅允许SSH
    Switch(config-line)#login local
    Switch(config)#username admin password admin123  # 创建本地用户
  • SNMP:网络监控协议。
    Switch(config)#snmp-server community public RO  # 只读 community

系统维护命令

  • 保存配置:防止重启丢失。
    Switch#write memory  # 或 copy running-config startup-config
  • 重启设备
    Switch#reload
  • 查看信息
    Switch#show running-config  # 查看当前配置
    Switch#show vlan brief       # 查看VLAN信息
    Switch#show ip route         # 查看路由表
    Switch#show interface status # 查看接口状态

配置实例:单交换机VLAN划分与接口配置

假设需将交换机的1-10口划入VLAN 10(销售部),11-20口划入VLAN 20(技术部),配置步骤如下:

  1. 进入全局配置模式:Switch#configure terminal
  2. 创建VLAN并命名:
    Switch(config)#vlan 10
    Switch(config-vlan)#name Sales
    Switch(config)#vlan 20
    Switch(config-vlan)#name Tech
  3. 配置接入端口:
    Switch(config)#interface range gigabitethernet 0/1-10
    Switch(config-if-range)#switchport mode access
    Switch(config-if-range)#switchport access vlan 10
    Switch(config)#interface range gigabitethernet 0/11-20
    Switch(config-if-range)#switchport mode access
    Switch(config-if-range)#switchport access vlan 20
  4. 保存配置:Switch#write memory

注意事项

  1. 命令区分大小写:多数交换机命令不区分大小写,但参数(如密码、VLAN名)可能区分。
  2. 配置备份:重要设备需定期备份配置,可通过TFTP服务器上传:
    Switch#copy running-config tftp://192.168.1.100/backup.cfg
  3. 误操作恢复:若配置错误,可通过erase startup-config清除启动配置,重启后恢复默认。
  4. 日志记录:开启日志功能便于排查问题:
    Switch(config)#logging synchronous  # 防止日志干扰命令输入
    Switch(config)#logging buffer 4096  # 设置日志缓冲区大小

相关问答FAQs

Q1: 串口连接后提示“Authentication failed”如何解决?
A: 可能原因包括密码错误、用户名不存在或终端参数不匹配,建议检查Console登录密码是否正确,确认波特率、数据位等参数与交换机默认设置一致(如华为S5700默认波特率为9600),若忘记密码,需通过设备恢复模式重置配置。

Q2: 如何通过串口命令查看交换机的MAC地址表?
A: 在特权模式下执行show mac-address-table命令,可查看接口、MAC地址、VLAN及类型(动态/静态)。

Switch#show mac-address-table
          Mac Address Table
-----------------------------------
Vlan    Mac Address       Type     Ports
----    -----------       -------- -----
  10    00e0-fc12-3456    dynamic  Gi0/1
  20    00e0-fc34-5678    dynamic  Gi0/11

若需清除动态MAC地址,可执行clear mac-address-table dynamic命令。

交换机串口命令有哪些常用操作?-图3
(图片来源网络,侵删)
分享:
扫描分享到社交APP
上一篇
下一篇