华为交换机常见基础配置的命令案例

华为交换机基础配置命令手册

基本配置模式切换
命令 作用 模式提示符
system-view (sys) 从用户视图进入系统视图 [HUAWEI]
interface ethernet 0/0/1 (int g0/0/1) 进入接口视图 [HUAWEI-GigabitEthernet0/0/1]
vlan 10 创建并进入VLAN视图 [HUAWEI-vlan10]
quit (q) 返回上一级视图 –
return (ret) 直接返回用户视图
save 保存当前配置 (用户视图下)设备管理配置(主机名、远程管理)

配置设备主机名

system-view
[HUAWEI] sysname SW-Core-01 # 将交换机命名为 SW-Core-01

配置管理IP地址,用于远程Telnet/SSH

[SW-Core-01] interface vlanif 1 # 进入管理VLAN接口(通常用VLAN1)
[SW-Core-01-Vlanif1] ip address 192.168.1.100 24 # 配置IP和掩码
[SW-Core-01-Vlanif1] quit

开启Telnet服务并设置认证方式

[SW-Core-01] telnet server enable # 默认可能已开启
[SW-Core-01] user-interface vty 0 4 # 进入VTY用户界面视图(0到4共5个会话)
[SW-Core-01-ui-vty0-4] authentication-mode password # 设置认证方式为密码验证
[SW-Core-01-ui-vty0-4] set authentication password cipher YourPassword123! # 设置登录密码
[SW-Core-01-ui-vty0-4] protocol inbound all # 允许Telnet和SSH协议
[SW-Core-01-ui-vty0-4] quit

(推荐)配置更安全的SSH登录

[SW-Core-01] stelnet server enable # 开启SSH服务
[SW-Core-01] rsa local-key-pair create # 生成本地RSA密钥对
[SW-Core-01] user-interface vty 0 4
[SW-Core-01-ui-vty0-4] authentication-mode aaa # 认证模式改为AAA
[SW-Core-01-ui-vty0-4] protocol inbound ssh # 仅允许SSH
[SW-Core-01-ui-vty0-4] quit
[SW-Core-01] aaa
[SW-Core-01-aaa] local-user admin password cipher YourSSHPassword456! # 创建用户和密码
[SW-Core-01-aaa] local-user admin privilege level 15 # 设置用户权限等级为最高15
[SW-Core-01-aaa] local-user admin service-type ssh # 用户服务类型为SSH
[SW-Core-01-aaa] quit

VLAN 基础配置

创建VLAN

[SW-Core-01] vlan batch 10 20 30 # 批量创建VLAN 10, 20, 30

将接口(Access口)划入VLAN

[SW-Core-01] interface gigabitethernet 0/0/1
[SW-Core-01-GigabitEthernet0/0/1] port link-type access # 设置端口模式为Access
[SW-Core-01-GigabitEthernet0/0/1] port default vlan 10 # 将端口划入VLAN 10
[SW-Core-01-GigabitEthernet0/0/1] quit

配置Trunk口,允许多个VLAN通过(常用于连接交换机或路由器)

[SW-Core-01] interface gigabitethernet 0/0/24
[SW-Core-01-GigabitEthernet0/0/24] port link-type trunk # 设置端口模式为Trunk
[SW-Core-01-GigabitEthernet0/0/24] port trunk allow-pass vlan 10 20 30 # 允许VLAN 10,20,30通过

或者允许所有VLAN通过:port trunk allow-pass vlan all

[SW-Core-01-GigabitEthernet0/0/24] quit

三层交换与VLAN间路由

要让不同VLAN之间能够通信,需要配置SVI(交换虚拟接口)。

为VLAN 10 配置网关IP

[SW-Core-01] interface vlanif 10
[SW-Core-01-Vlanif10] ip address 192.168.10.1 24 # 此IP将作为VLAN 10内所有设备的网关
[SW-Core-01-Vlanif10] quit

为VLAN 20 配置网关IP

[SW-Core-01] interface vlanif 20
[SW-Core-01-Vlanif20] ip address 192.168.20.1 24
[SW-Core-01-Vlanif20] quit

配置默认路由,指向上层路由器,用于访问互联网或其他网络

[SW-Core-01] ip route-static 0.0.0.0 0.0.0.0 192.168.1.1 # 下一跳为上联路由器的IP
5. 常用查看与诊断命令

这些命令在用户视图 () 下执行,用于监控和排障。
命令 作用
display current-configuration (dis cur) 查看当前运行配置
display saved-configuration (dis sav) 查看已保存的配置
display vlan 查看VLAN信息
display interface brief (dis int b) 查看所有接口状态摘要(非常常用!)
display ip interface brief (dis ip int b) 查看三层接口IP状态
display mac-address 查看MAC地址表
display arp 查看ARP表
display logbuffer 查看日志缓冲区
ping 192.168.1.1 测试网络连通性
tracert 192.168.1.1 追踪数据包路径

一个完整的配置示例:为新办公室配置接入交换机

场景: 将G0/0/1-10口给员工(VLAN 10),G0/0/11-20口给访客(VLAN 20),G0/0/24口上联核心交换机(Trunk)。

sys
sysname SW-Access-01

创建VLAN

vlan batch 10 20

配置接入端口

int range gigabitethernet 0/0/1 to 0/0/10
port link-type access
port default vlan 10

int range gigabitethernet 0/0/11 to 0/0/20
port link-type access
port default vlan 20

配置上联Trunk端口

interface gigabitethernet 0/0/24
port link-type trunk
port trunk allow-pass vlan 10 20 # 允许VLAN 10和20通过

配置管理IP和远程登录

interface vlanif 1
ip address 192.168.1.101 24
quit
telnet server enable
user-interface vty 0 4
authentication-mode password
set authentication password cipher MyTelnetPass123!
protocol inbound all
quit

保存配置

save
希望这份详实的命令案例能对您的工作有所帮助!您可以将其作为速查手册。

© 版权声明
THE END
如果内容对您有所帮助,就支持一下吧!
点赞0 分享
豆紅安子骰珑玲的头像 - 鹿快
评论 抢沙发

请登录后发表评论

    暂无评论内容