技术 · 思考 · 实践 · 成长

首页/计算机网络/正文

华为路由器 / 交换机常用配置命令完全指南

计算机网络143 次阅读

华为路由器/交换机使用 VRP 操作系统,命令风格是「视图 + 命令」:先进入对应视图,再执行配置。这篇按「基础操作 → 接口 → VLAN → 路由 → 服务 → 排错」的顺序整理常用命令,可直接当速查表。参考:华为技术支持。

一、VRP 视图与命令行技巧

视图提示符进入方式
用户视图<Huawei>登录后默认
系统视图[Huawei]system-view
接口视图[Huawei-GigabitEthernet0/0/1]interface g0/0/1
协议视图[Huawei-ospf-1]ospf 1
用户界面视图[Huawei-ui-vty0-4]user-interface vty 0 4
<Huawei> system-view        # 进入系统视图
[Huawei] quit                # 返回上一级
[Huawei] return              # 直接回用户视图(Ctrl+Z)
[Huawei] ?                   # 查看当前视图可用命令
[Huawei] interface ?         # 查看参数提示
[Huawei] display version | include VRP   # 管道过滤

二、设备基础操作

<Huawei> display current-configuration    # 当前配置
<Huawei> display saved-configuration      # 已保存配置
<Huawei> display clock
<Huawei> clock timezone CST add 08:00:00

[Huawei] sysname R1                       # 修改设备名
[R1] save                                 # 保存配置
[R1] reboot                               # 重启
[R1] reset saved-configuration            # 清空配置(谨慎)

配置完一定 save,否则重启丢失。

三、接口配置

[R1] interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1] ip address 192.168.1.1 24
[R1-GigabitEthernet0/0/1] undo shutdown
[R1-GigabitEthernet0/0/1] description to-LAN
[R1-GigabitEthernet0/0/1] quit

[R1] display ip interface brief
[R1] display interface GigabitEthernet 0/0/1

四、VLAN 与 Access/Trunk

[SW1] vlan batch 10 20 30
[SW1] interface GigabitEthernet 0/0/1
[SW1-GigabitEthernet0/0/1] port link-type access
[SW1-GigabitEthernet0/0/1] port default vlan 10
[SW1-GigabitEthernet0/0/1] quit

[SW1] interface GigabitEthernet 0/0/24
[SW1-GigabitEthernet0/0/24] port link-type trunk
[SW1-GigabitEthernet0/0/24] port trunk allow-pass vlan 10 20 30
[SW1-GigabitEthernet0/0/24] quit

[SW1] display vlan
[SW1] display port vlan active

五、链路聚合 Eth-Trunk

[SW1] interface Eth-Trunk 1
[SW1-Eth-Trunk1] mode lacp-static
[SW1-Eth-Trunk1] trunkport GigabitEthernet 0/0/23
[SW1-Eth-Trunk1] trunkport GigabitEthernet 0/0/24
[SW1-Eth-Trunk1] port link-type trunk
[SW1-Eth-Trunk1] port trunk allow-pass vlan all
[SW1-Eth-Trunk1] quit

[SW1] display eth-trunk 1

六、STP / RSTP 防环

[SW1] stp mode rstp
[SW1] stp enable
[SW1] display stp brief
[SW1] display stp root

接入层可开 stp edged-port enable 让接终端的端口快速转发。

七、静态路由与默认路由

[R1] ip route-static 192.168.2.0 24 10.0.0.2
[R1] ip route-static 0.0.0.0 0 10.0.0.2
[R1] display ip routing-table
[R1] display ip routing-table protocol static

八、OSPF 基础

[R1] ospf 1 router-id 1.1.1.1
[R1-ospf-1] area 0
[R1-ospf-1-area-0.0.0.0] network 192.168.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0] network 10.0.0.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0] quit

[R1] display ospf peer brief
[R1] display ospf routing

九、DHCP 服务

[R1] dhcp enable
[R1] ip pool lan
[R1-ip-pool-lan] network 192.168.1.0 mask 255.255.255.0
[R1-ip-pool-lan] gateway-list 192.168.1.1
[R1-ip-pool-lan] dns-list 114.114.114.114
[R1-ip-pool-lan] quit
[R1] interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1] dhcp select global
[R1] display ip pool

十、NAT

# Easy IP
[R1] acl 2000
[R1-acl-basic-2000] rule permit source 192.168.1.0 0.0.0.255
[R1-acl-basic-2000] quit
[R1] interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0] nat outbound 2000

# 端口映射
[R1-GigabitEthernet0/0/0] nat server protocol tcp global current-interface 8080 inside 192.168.1.10 80

十一、ACL

[R1] acl 3000
[R1-acl-adv-3000] rule deny tcp source 192.168.2.0 0.0.0.255 destination 192.168.1.10 0 destination-port eq 80
[R1-acl-adv-3000] rule permit ip
[R1] interface GigabitEthernet 0/0/1
[R1-GigabitEthernet0/0/1] traffic-filter inbound acl 3000
[R1] display acl 3000

十二、远程管理(SSH)

[R1] aaa
[R1-aaa] local-user admin password irreversible-cipher StrongPass123!
[R1-aaa] local-user admin privilege level 15
[R1-aaa] local-user admin service-type ssh
[R1-aaa] quit

[R1] stelnet server enable
[R1] user-interface vty 0 4
[R1-ui-vty0-4] authentication-mode aaa
[R1-ui-vty0-4] protocol inbound ssh
[R1-ui-vty0-4] quit
[R1] ssh user admin authentication-type password

十三、查看与排错

display version
display current-configuration
display interface brief
display ip routing-table
display arp
display mac-address
display logbuffer
ping -c 4 192.168.1.1
tracert 8.8.8.8

排错顺序:链路(接口 up/down)→ 二层(VLAN/MAC)→ 三层(IP/路由)→ 策略(ACL/NAT)→ 应用。

十四、总结

华为设备是「视图 + 命令」,配置完 save;接口、VLAN、Trunk、聚合、STP 是二层基础;静态路由/OSPF 是三层基础;DHCP/NAT/ACL/SSH 是常用服务;排错从接口与路由表看起。

照顾好自己,如果尚有余力,记得保护美好的东西,不畏不惧赤诚善良。

评论交流

0 条评论 · 支持多级回复
验证码
暂无评论,来说说你的想法吧

相关文章

继续阅读