华为S5700交换机基础配置命令详解涵盖核心操作:进入系统视图(system-view),设置设备名称(sysname),配置管理IP(interface vlanif),开启远程登录(telnet server enable,user-interface vty),设置登录密码,以及端口基础设置(port link-type,port default vlan)。
华为S5700系列交换机是企业级接入和汇聚层交换机的经典之作,广泛应用于各种网络环境,掌握其基础配置命令是网络管理员必备的技能,本文将详细介绍S5700最常用、最关键的配置命令,帮助您快速上手。
重要提示与准备工作:
- 访问方式: 通常通过Console线首次连接配置,或通过Telnet/SSH远程管理,确保您有合法的登录权限。
- 配置视图: 华为设备采用分层视图结构,常见的视图有:
- 用户视图:
<Huawei>
提示符,执行基本查看、测试命令(如display
,ping
)。 - 系统视图:
[Huawei]
提示符,执行全局配置命令(如sysname
,vlan batch
),在用户视图下输入system-view
进入。 - 接口视图:
[Huawei-GigabitEthernet0/0/1]
提示符,执行针对特定接口的配置(如port link-type
,port default vlan
),在系统视图下输入interface interface-type interface-number
进入(interface GigabitEthernet 0/0/1
)。 - VLAN视图:
[Huawei-vlan10]
提示符,执行针对特定VLAN的配置(如description
),在系统视图下输入vlan vlan-id
进入。
- 用户视图:
- 帮助命令: 在任何视图下,输入 可以查看当前视图下可用的命令列表,输入命令的前几个字母后按
Tab
键可以自动补全命令。 - 保存配置: 配置完成后务必保存! 在用户视图下执行
save
命令,否则设备重启后配置会丢失。
基础系统配置
-
设备命名 (Hostname):
- 作用: 为交换机设置一个易于识别的名称,方便管理。
- 命令:
<Huawei> system-view // 进入系统视图 [Huawei] sysname SW-Core-Floor1 // 将设备命名为 SW-Core-Floor1 [SW-Core-Floor1] // 提示符已改变
-
配置管理IP地址:
- 作用: 为交换机的管理VLAN接口(通常是VLANIF 1或其他管理VLAN)配置IP地址,以便远程管理(Telnet/SSH/Web/SNMP)。
- 步骤:
- 创建VLAN (如果管理VLAN不是1):
[SW-Core-Floor1] vlan batch 100 // 创建VLAN 100 (作为管理VLAN示例)
- 进入VLAN接口视图并配置IP:
[SW-Core-Floor1] interface vlanif 100 // 进入VLANIF 100接口视图 [SW-Core-Floor1-Vlanif100] ip address 192.168.100.1 24 // 配置IP地址192.168.100.1,子网掩码255.255.255.0 (/24) [SW-Core-Floor1-Vlanif100] quit // 退出到系统视图
- 将物理接口加入管理VLAN (如果接口需要访问管理IP):
[SW-Core-Floor1] interface GigabitEthernet 0/0/24 // 进入连接管理终端的接口视图 [SW-Core-Floor1-GigabitEthernet0/0/24] port link-type access // 设置接口为Access模式 [SW-Core-Floor1-GigabitEthernet0/0/24] port default vlan 100 // 将接口加入VLAN 100 [SW-Core-Floor1-GigabitEthernet0/0/24] quit
- 创建VLAN (如果管理VLAN不是1):
-
配置默认网关:
- 作用: 使交换机能够访问其他网段的设备(如网管服务器、互联网)。
- 命令:
[SW-Core-Floor1] ip route-static 0.0.0.0 0.0.0.0 192.168.100.254 // 设置默认网关为192.168.100.254
-
配置远程登录 (Telnet/SSH – 强烈推荐SSH):
- 作用: 允许管理员通过网络远程管理交换机。
- 基本Telnet配置 (安全性较低,仅作示例,生产环境建议SSH):
[SW-Core-Floor1] user-interface vty 0 4 // 进入VTY 0到4的虚拟终端线路视图 [SW-Core-Floor1-ui-vty0-4] authentication-mode password // 设置认证方式为密码认证 [SW-Core-Floor1-ui-vty0-4] set authentication password cipher Huawei@123 // 设置登录密码为Huawei@123 (cipher表示加密存储) [SW-Core-Floor1-ui-vty0-4] protocol inbound telnet // 允许Telnet协议接入 (或 all) [SW-Core-Floor1-ui-vty0-4] quit
- 配置SSH (更安全): 需要生成RSA密钥对、创建SSH用户、指定服务类型和认证方式,步骤略复杂,建议参考华为官方文档配置。
接口配置
-
接口基本参数:
- 描述 (Description):
[SW-Core-Floor1] interface GigabitEthernet 0/0/1 [SW-Core-Floor1-GigabitEthernet0/0/1] description To-PC-UserA // 给接口添加描述信息
- 启用/禁用接口:
[SW-Core-Floor1-GigabitEthernet0/0/1] shutdown // 禁用接口 (默认是开启的) [SW-Core-Floor1-GigabitEthernet0/0/1] undo shutdown // 启用接口
- 双工模式与速率 (通常Auto即可):
[SW-Core-Floor1-GigabitEthernet0/0/1] undo negotiation auto // 关闭自协商 (慎用) [SW-Core-Floor1-GigabitEthernet0/0/1] speed 100 // 强制速率100Mbps [SW-Core-Floor1-GigabitEthernet0/0/1] duplex full // 强制全双工 // 恢复自协商 [SW-Core-Floor1-GigabitEthernet0/0/1] negotiation auto
- 描述 (Description):
-
配置接口链路类型 (Access/Trunk/Hybrid):
- Access接口: 通常用于连接终端设备(PC、打印机、IP电话、AP),只允许一个VLAN的流量通过(PVID)。
[SW-Core-Floor1] interface GigabitEthernet 0/0/5 [SW-Core-Floor1-GigabitEthernet0/0/5] port link-type access // 设置为Access模式 [SW-Core-Floor1-GigabitEthernet0/0/5] port default vlan 10 // 将该接口加入VLAN 10 (即设置PVID=10)
- Trunk接口: 通常用于交换机之间的互联,允许多个VLAN的流量通过,需要指定允许通过的VLAN列表和Native VLAN (PVID)。
[SW-Core-Floor1] interface GigabitEthernet 0/0/24 // 假设连接另一台交换机 [SW-Core-Floor1-GigabitEthernet0/0/24] port link-type trunk // 设置为Trunk模式 [SW-Core-Floor1-GigabitEthernet0/0/24] port trunk allow-pass vlan 10 20 100 // 允许VLAN 10, 20, 100通过 [SW-Core-Floor1-GigabitEthernet0/0/24] port trunk pvid vlan 1 // 设置Native VLAN (PVID) 为1 (默认值,可根据需要修改)
- Hybrid接口: 功能更灵活,兼具Access和Trunk特性,可以同时以Tagged和Untagged方式发送多个VLAN的流量,配置略复杂,此处不展开。
- Access接口: 通常用于连接终端设备(PC、打印机、IP电话、AP),只允许一个VLAN的流量通过(PVID)。
VLAN配置
-
创建VLAN:
[SW-Core-Floor1] vlan batch 10 20 30 // 一次性创建VLAN 10, 20, 30 [SW-Core-Floor1] vlan 100 // 创建单个VLAN 100 (并进入VLAN视图) [SW-Core-Floor1-vlan100] description Department-Finance // (可选) 为VLAN 100添加描述 [SW-Core-Floor1-vlan100] quit
-
将接口加入VLAN (已在接口配置部分说明):
- 对于Access接口:使用
port default vlan <vlan-id>
。 - 对于Trunk接口:使用
port trunk allow-pass vlan <vlan-id-list>
允许VLAN通过。
- 对于Access接口:使用
-
配置VLAN接口 (SVI – Switch Virtual Interface):
- 作用: 为三层交换机上的VLAN提供IP层接口,实现VLAN间路由。
- 命令:
[SW-Core-Floor1] interface vlanif 10 // 进入VLANIF 10接口视图 [SW-Core-Floor1-Vlanif10] ip address 192.168.10.1 24 // 为VLAN 10配置网关IP [SW-Core-Floor1-Vlanif10] quit // 同样方法配置其他需要路由的VLAN的VLANIF
生成树协议 (STP/RSTP/MSTP) 配置
- 作用: 防止二层环路,提供冗余链路备份,S5700默认启用MSTP。
- 基本配置 (通常需要全局和接口视图配合):
[SW-Core-Floor1] stp mode mstp // 确认模式为MSTP (默认) [SW-Core-Floor1] stp region-configuration // 进入MST域配置视图 [SW-Core-Floor1-mst-region] region-name MyNetwork // 配置MST域名 [SW-Core-Floor1-mst-region] revision-level 1 // 配置修订级别 [SW-Core-Floor1-mst-region] instance 1 vlan 10 20 // 将VLAN 10, 20映射到实例1 [SW-Core-Floor1-mst-region] instance 2 vlan 30 100 // 将VLAN 30, 100映射到实例2 [SW-Core-Floor1-mst-region] active region-configuration // 激活配置 [SW-Core-Floor1-mst-region] quit [SW-Core-Floor1] stp instance 1 root primary // 设置本交换机为实例1的根桥 [SW-Core-Floor1] stp instance 2 root secondary // 设置本交换机为实例2的备份根桥 // 在连接终端的Access接口上,通常可以关闭STP以节省资源 (确保该接口不会形成环路) [SW-Core-Floor1] interface GigabitEthernet 0/0/5 [SW-Core-Floor1-GigabitEthernet0/0/5] stp disable // 在该接口禁用STP [SW-Core-Floor1-GigabitEthernet0/0/5] quit
链路聚合 (Eth-Trunk) 配置
- 作用: 将多个物理接口捆绑成一个逻辑接口,增加带宽、提供冗余。
- 配置步骤:
- 创建Eth-Trunk接口:
[SW-Core-Floor1] interface Eth-Trunk 1 // 创建Eth-Trunk 1 (并进入Eth-Trunk视图) [SW-Core-Floor1-Eth-Trunk1] quit
- 配置Eth-Trunk工作模式 (LACP静态/动态):
[SW-Core-Floor1] interface Eth-Trunk 1 [SW-Core-Floor1-Eth-Trunk1] mode lacp-static // 设置为LACP静态模式 (常用) // 或 mode lacp-dynamic (动态LACP) / mode manual load-balance (手工负载分担) [SW-Core-Floor1-Eth-Trunk1] quit
- 将物理接口加入Eth-Trunk:
[SW-Core-Floor1] interface GigabitEthernet 0/0/23 [SW-Core-Floor1-GigabitEthernet0/0/23] eth-trunk 1 // 将G0/0/23加入Eth-Trunk 1 [SW-Core-Floor1-GigabitEthernet0/0/23] quit [SW-Core-Floor1] interface GigabitEthernet 0/0/24 [SW-Core-Floor1-GigabitEthernet0/0/24] eth-trunk 1 // 将G0/0/24加入Eth-Trunk 1 [SW-Core-Floor1-GigabitEthernet0/0/24] quit
- 配置Eth-Trunk接口参数 (如链路类型): 像配置普通物理接口一样配置Eth-Trunk接口(如
port link-type trunk
,port trunk allow-pass vlan ...
)。
- 创建Eth-Trunk接口:
访问控制列表 (ACL) 配置
- 作用: 过滤流量,实现安全策略。
- 基本ACL (基于源IP):
[SW-Core-Floor1] acl 2000 // 创建基本ACL 2000 (2000-2999范围) [SW-Core-Floor1-acl-basic-2000] rule 5 deny source 192.168.10.100 0 // 拒绝源IP 192.168.10.100 (0表示精确匹配) [SW-Core-Floor1-acl-basic-2000] rule 10 permit source any // 允许其他所有源IP [SW-Core-Floor1-acl-basic-2000] quit
- 高级ACL (基于IP五元组等):
[SW-Core-Floor1] acl 3000 // 创建高级ACL 3000 (3000-3999范围) [SW-Core-Floor1-acl-adv-3000] rule 5 deny tcp source 192.168.20.0 0.0.0.255 destination 10.1.1.1 0 destination-port eq 80 // 拒绝192.168.20.0/24网段访问10.1.1.1的80端口(TCP) [SW-Core-Floor1-acl-adv-3000] rule 10 permit ip // 允许其他所有IP流量 [SW-Core-Floor1-acl-adv-3000] quit
- 应用ACL (通常在接口入方向或VLANIF应用):
[SW-Core-Floor1] interface GigabitEthernet 0/0/10 // 应用在接口入方向 [SW-Core-Floor1-GigabitEthernet0/0/10] traffic-filter inbound acl 2000 // 在入方向应用ACL 2000 [SW-Core-Floor1-GigabitEthernet0/0/10] quit // 或在VLANIF应用 (用于过滤路由流量) [SW-Core-Floor1] interface vlanif 20 [SW-Core-Floor1-Vlanif20] traffic-filter inbound acl 3000 [SW-Core-Floor1-Vlanif20] quit
常用查看与维护命令
- 查看运行配置:
display current-configuration
(在用户或系统视图) - 查看保存的配置:
display saved-configuration
(在用户视图) - 查看接口状态与统计:
display interface brief
/display interface [interface-type interface-number]
(如display interface GigabitEthernet 0/0/1
) - 查看VLAN信息:
display vlan
/display vlan vlan-id
- 查看MAC地址表:
display mac-address
- 查看ARP表:
display arp
- 查看路由表:
display ip routing-table
- 查看STP状态:
display stp brief
/display stp [interface interface-type interface-number]
- 查看Eth-Trunk状态:
display eth-trunk [trunk-id]
- 查看ACL配置与应用:
display acl all
- Ping测试:
ping [ip-address]
(在用户视图)
原创文章,发布者:酷番叔,转转请注明出处:https://cloud.kd.cn/ask/6805.html