菜鸟科技网

思科2960交换机常用命令有哪些?

思科2960交换机作为企业网络中常用的接入层设备,其命令配置是网络管理的基础,掌握常用命令有助于实现网络初始化、VLAN划分、端口管理、安全策略部署等功能,以下从设备初始化、VLAN配置、端口管理、安全设置、链路聚合、IP路由及维护命令等方面进行详细说明。

思科2960交换机常用命令有哪些?-图1
(图片来源网络,侵删)

设备初始化与基础配置

首次配置交换机时,需通过Console口连接,使用终端软件(如SecureCRT)设置波特率9600、8数据位、无校验、1停止位,进入命令行界面后,首先进入全局配置模式:

Switch> enable          // 从用户模式进入特权模式
Switch# configure terminal  // 进入全局配置模式
Switch(config)# hostname SW-2960-24     // 设置设备主机名
Switch(config)# enable secret cisco123   // 设置特权模式加密密码
Switch(config)# line console 0          // 进入控制台线路配置模式
Switch(config-line)# password console   // 设置控制台登录密码
Switch(config-line)# login             // 启用密码验证
Switch(config-line)# exit
Switch(config)# line vty 0 15          // 进入虚拟终端线路配置模式
Switch(config-line)# password telnet   // 设置远程登录密码
Switch(config-line)# login
Switch(config)# exit
Switch# write memory                     // 保存配置

VLAN配置

VLAN用于隔离广播域,提升网络安全性,创建VLAN并分配端口:

Switch(config)# vlan 10                // 创建VLAN 10
Switch(config-vlan)# name Sales         // 命名VLAN
Switch(config-vlan)# exit
Switch(config)# vlan 20
Switch(config-vlan)# name IT
Switch(config-vlan)# exit
Switch(config)# interface fa0/1         // 进入接口配置模式
Switch(config-if)# switchport mode access // 设置为接入端口
Switch(config-if)# switchport access vlan 10 // 将端口划分到VLAN 10
Switch(config-if)# exit
Switch(config)# interface range fa0/2-10 // 批量配置端口
Switch(config-if-range)# switchport mode access
Switch(config-if-range)# switchport access vlan 20

端口管理

端口状态与速率双工设置

Switch(config)# interface fa0/1
Switch(config-if)# speed 100          // 设置速率为100Mbps
Switch(config-if)# duplex full        // 设置全双工模式
Switch(config-if)# no shutdown        // 启用端口

端口安全(限制MAC地址数量)

Switch(config)# interface fa0/1
Switch(config-if)# switchport port-security   // 启用端口安全
Switch(config-if)# switchport port-security maximum 2 // 最多允许2个MAC地址
Switch(config-if)# switchport port-security violation shutdown // 违规关闭端口

安全设置

SSH登录配置

Switch(config)# ip domain-example.com  // 设置域名
Switch(config)# crypto key generate rsa  // 生成RSA密钥
Switch(config)# username admin secret password123 // 创建SSH用户
Switch(config)# line vty 0 15
Switch(config-line)# transport input ssh  // 仅允许SSH登录
Switch(config-line)# login local       // 使用本地用户认证

BPDU防护(防止STP攻击)

Switch(config)# spanning-tree portfast default // 启用PortFast(接入端口跳过STP检测)
Switch(config)# spanning-tree bpduguard default // 启用BPDU防护,收到BPDU时关闭端口

链路聚合(EtherChannel)

将多个物理端口捆绑为逻辑链路,增加带宽和冗余:

Switch(config)# interface range fa0/1-2
Switch(config-if-range)# channel-group 1 mode active  // 创建聚合组1,LACP模式
Switch(config-if-range)# exit
Switch(config)# interface port-channel 1  // 进入聚合接口
Switch(config-if)# switchport mode trunk  // 设置为Trunk模式

IP路由与三层功能

2960系列为二层交换机,但部分型号支持基本三层功能(如SVI接口):

思科2960交换机常用命令有哪些?-图2
(图片来源网络,侵删)
Switch(config)# interface vlan 10       // 创建SVI接口
Switch(config-if)# ip address 192.168.10.1 255.255.255.0 // 配置VLAN 10网关
Switch(config-if)# no shutdown
Switch(config)# ip routing             // 启用IP路由(仅支持部分型号)

维护与故障排查

查看配置与状态

Switch# show running-config            // 查看当前配置
Switch# show vlan brief                // 查看VLAN摘要信息
Switch# show interface status         // 查看端口状态
Switch# show mac address-table        // 查看MAC地址表
Switch# show spanning-tree vlan 10    // 查看VLAN 10的STP状态

清除配置与重启

Switch# erase startup-config          // 清除启动配置
Switch# reload                        // 重启交换机

常用命令速查表

功能类别 命令示例 说明
进入配置模式 configure terminal 从特权模式进入全局配置模式
创建VLAN vlan 10 创建VLAN 10
端口划分VLAN switchport access vlan 10 将端口划入VLAN 10
启用端口安全 switchport port-security 开启端口安全功能
配置Trunk switchport mode trunk 设置端口为Trunk模式
查看MAC地址表 show mac address-table 显示MAC地址与端口映射关系
保存配置 write memorycopy running-config startup-config 保存当前配置到NVRAM

相关问答FAQs

Q1: 如何将交换机恢复到出厂设置?
A1: 恢复出厂设置需通过以下步骤:

  1. 断电重启交换机,在启动过程中按住Mode按钮直至进入BootRom模式;
  2. 输入flash_init初始化Flash;
  3. 输入delete flash:config.text删除配置文件;
  4. 输入boot重启交换机,重启后配置将恢复为默认值。

Q2: 交换机端口显示“err-disabled”状态的原因及解决方法?
A2: 常见原因包括:

  • 端口安全违规(如MAC地址超限);
  • BPDU防护触发;
  • 链路协商失败(如双工模式不匹配)。
    解决方法:
  1. 查看错误原因:show interface statusshow log
  2. 手动恢复端口:configure terminalinterface fa0/1shutdownno shutdown
  3. 若为端口安全违规,需调整switchport port-security maximum值或清除违规MAC地址。
思科2960交换机常用命令有哪些?-图3
(图片来源网络,侵删)
分享:
扫描分享到社交APP
上一篇
下一篇