本清单提供了对 Huawei 网络设备的入门简要概述,以及 Huawei 网络设备常用命令示例
基本知识
VRP
- 华为数据通信产品的通用网络操作平台,可用于设备管理和配置
- 支持命令简写,输入命令时可通过提示获取完整写法
- 例如:
undo in en 取消系统信息显示,完整命令为 undo info-center enable
- 如果简写存在歧义,则需要输入更完整的命令
视图
视图(View)是指命令行界面(CLI)的操作层级,不同视图可执行不同范围的命令。
| 视图 |
进入方式 |
说明 |
| 用户视图 |
登录设备后默认进入 |
可执行监控、查看信息等命令(如 display version) |
| 系统视图 |
system-view |
可执行全局配置命令 |
| 接口视图 |
interface 接口名(如 interface GigabitEthernet0/0/1) |
用于配置接口相关参数(IP、速率、VLAN等) |
| ACL 视图 |
acl 编号(如 acl 3000) |
用于定义访问控制规则 |
| VLAN 视图 |
vlan VLAN_ID(如 vlan 10) |
用于创建、修改或删除 VLAN |
| OSPF 视图 |
ospf 进程号(如 ospf 1) |
用于配置 OSPF 动态路由 |
| AAA 视图 |
aaa |
用于配置认证、授权与计费 |
TXT
1 2 3 4 5 6 7
| 用户视图 └── system-view (系统视图) ├── interface GigabitEthernet0/0/1 (接口视图) ├── vlan 10 (VLAN视图) ├── acl 3000 (ACL视图) ├── ospf 1 (OSPF视图) └── aaa (AAA视图)
|
基本操作
系统信息
查看信息
BASH
1 2 3
| display version display current-configuration display mac-address
|
重命名设备
在系统视图下:sysname RENAME
切换语言
BASH
1 2
| language-mode [English, Chinese]
|
设置标题
BASH
1 2
| header login information 信息 header shell information 信息
|
取消调试信息
撤销操作
- 可用于恢复默认配置
- 可用于禁用某些功能
- 可用于删除某些配置
BASH
1 2 3 4 5 6
| undo sysname
undo in en
undo ip address
|
恢复出厂设置
reset saved-configuration
历史命令
使用上箭头或 ctrl+p 可访问上一命令
使用下箭头或 ctrl+n 可访问下一命令
默认保存10条命令
显示历史命令
display history-command
设置系统时钟
BASH
1 2 3 4
|
clock datetime 12:00:00 2020-02-02 clock timezone BJ add 08:00:00
|
mac 地址
BASH
1 2 3 4 5 6 7 8
|
mac-address static MAC-Address e0/0/0 vlan VlanID
reset arp all
|
退出
quit 命令用于从任意视图退回上一个视图
return 这是立刻退回至用户视图
保存配置
save
重启
登录管理
STelnet 方式
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| stelnet server enable
int vlanif 1 ip add 192.168.1.254 24
rsa local-key-pair create
ssh cl fi en
ssh user admin authentication-type password
ssh user admin service-type stelnet
|
AAA 登录
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13
| aaa
local-user admin password cipher 123456 privilege level 2
local-user admin service-type ssh quit user-interface vty 0 4 authentication-mode aaa protocol inbound ssh quit
ssh client first-time enable
|
命令级别
- 0 参观级 只能进行如诊断工具命令(ping,tracert),部分 display 命令
- 1 监控级 主要用于系统维护,业务故障诊断,包括部分display,debugging命令
- 2 配置级 主要用于业务配置,包括路由,各个网络层次命令,可向用户提供直接网络服务
- 3 - 15 为管理级,涉及系统基本运行,系统支撑模块等
Console 接口登录
永不超时
BASH
1 2
| user-interface console 0 idle-timeout 0
|
密码认证
BASH
1 2 3
| user-interface console 0 authentication-mode password set authentication password simple 123456
|
AAA认证
BASH
1 2 3 4 5 6 7
| user-interface console 0 authentication-mode aaa quit aaa local-user admin password simple 123456 local-user admin password cipher 123456 local-user admin service-type terminal
|
Telnet 方式
password 登录
BASH
1 2 3 4 5
| user-interface vty 0 4 authentication-mode password set authentication password simple 123456 user privilege level 2 idle-timeout 15
|
AAA 登录
BASH
1 2 3 4 5 6 7 8 9
| aaa
local-user admin password cipher 123456 privilege level 2
local-user admin service-type telnet quit user-interface vty 0 4 authentication-mode aaa quit
|
远程 IP
BASH
1 2 3 4 5
| int vlanif 1 ip add 192.168.1.254 24
192.168.1.1 24
|
接口配置
接口组
BASH
1 2 3
| port-group 1 group-member e0/0/2 to e0/0/8
|
接口模式
BASH
1 2 3 4 5
|
int e0/0/1 port link-type access port link-type trunk
|
接口带宽
BASH
1 2 3 4 5 6 7 8 9
| int e0/0/1
speed 10 | 100 | Auto
undo negotiation auto
|
接口双工模式
BASH
1 2 3 4 5 6
| int e0/0/1
duplex full | half
|
配置 trunk
BASH
1 2
| interface g0/0/1 port link-type trunk
|
all 为通过所有 vlan, VlanId 为指定 vlan,多个vlan以空格隔开
BASH
1
| port trunk allow-pass vlan VlanId | all
|
vlan 配置
查看 vlan
display vlan
创建 vlan
BASH
1 2 3 4 5 6 7 8 9 10 11 12
| vlan VlanId
description VLANNAME
undo vlan VlanId
vlan batch 10 20 30
vlan batch 10 to 30
|
分配 vlan
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| interface E0/0/1
port link-type access
port default vlan 10
port-group 1
group-member e0/0/5 to e0/0/8
port link-type access
port default vlan 10
|
交换机配置
STP (Spanning Tree Protocol)
即生成树协议
可将有环路的物理拓扑变为无环路的逻辑拓扑,从而为网络提供安全机制,使得冗余拓扑中不会产生交换环路问题
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
stp enable
stp mode stp
stp priority 0
stp root primary
stp root secondary
|
链路聚合
BASH
1 2 3 4 5 6 7 8 9
| interface eth-trunk 1 quit interface g0/0/1 eth-trunk 1
port link-type trunk
|
在聚合接口下添加成员
BASH
1 2 3
| trunkport g0/0/1 trunkport g0/0/1 to g0/0/2
|
接口汇聚是将交换机间的多条物理链路合并为一条逻辑链路,以提升带宽并实现链路冗余备份。
RSTP(Rapid Spanning Tree Protocol)
- RSTP(快速生成树协议)是对 STP 的改进版
- 当网络故障发生时,STP 的拓扑结构需要较长时间收敛,而 RSTP 可在 1 秒内完成
- 配置方式与 STP 基本一致
不同点:
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| stp enable
stp mode rstp
stp edged-port enable
|
DHCP(Dynamic Host Configuration Protocol)
即动态主机配置协议
可有规划的划分 IP 地址,也可避免用户私设 IP 引起的地址冲突
三层交换机可充当 DHCP 服务器,能动态分配 IP 地址及 DNS 服务地址等网络参数
可以使得用户零配置上网
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
dhcp enable
ip pool V10
network 10.10.10.0 mask 255.0.0.0
gateway-list 10.10.10.254
lease 8
dns-list 5.5.5.5
dhcp select global
dhcp select interface
excluded-ip-address 10.10.10.5 10.10.10.15
|
路由配置
查看路由
BASH
1 2
| display ip routing-table
|
VRRP (Virtual Router Redundancy Protocol)
即虚拟路由器冗余协议
是一种选择协议,可将虚拟路由器责任动态分配至局域网内的一台 VRRP 路由器
控制虚拟路由器 IP 地址的 VRRP 路由器为 Master 路由器,负责将数据包进行分发
一旦 Master 不可用,可提供动态的故障转移机制
由 Backup 路由器代替 Master路由器故障时的工作
允许虚拟路由器的 IP 地址作为 终端主机的默认第一跳路由
优势为更高的默认路由的可用性,无须在终端主机上配置动态路由或路由发现协议
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
vrrp vrid 1 virtual-ip 192.168.100.254
vrrp vrid 1 priority 150
vrrp vrid 1 preempt-mode timer delay 5
vrrp vrid 1 track interface g0/0/23
display vrrp brief
display vrrp 1
|
单臂路由
划分 vlan 之后,vlan 是无法互通的,但是使用单臂路由可以解决此问题。
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int g0/0/0.1
dot1q termination vid 10
arp broadcast enable
|
静态路由
适用于规模较小,不经常变动,简单的网络环境
BASH
1 2 3 4 5 6 7 8
|
ip route-static 目标网段 掩码 下一跳地址
|
默认路由
默认路由与静态路由配置基本相同。
唯一不同的就是路由的配置。
BASH
1
| ip rou 0.0.0.0 0.0.0.0 下一跳地址
|
浮动路由
就是路由器之间多个接口相连,并配置接口优先级。
配置与静态,默认路由基本相同。
BASH
1 2
| ip rou 目标网段 掩码 下一跳地址 ip rou 目标网段 掩码 下一跳地址 pr 权重
|
OSPF
首先配置完毕相关接口及IP。
单域
BASH
1 2 3 4 5 6 7 8
|
ospf 1
area 0
net x.x.x.x 反码
|
多域
与单域配置基本相同,只是需要划分多个 OSPF 区域。
需要注意,路由器相连接口需要划分到一个区域。
BASH
1 2 3 4 5 6 7 8 9
| ospf 1 area 0
net x.x.x.x 反码
area 1
net x.x.x.x 反码
|
动态路由 RIP
配置基本相同。
BASH
1 2 3 4 5 6 7 8 9 10 11
|
rip
v 2
summary always
net x.x.x.x
|
路由重分发
大型网络中,有时有多种路由协议共存,此时需要进行路由重分发。
BASH
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
import-route ospf 1
import-route rip 1
|
网络安全
接口安全
BASH
1 2 3 4 5 6 7 8 9 10 11
|
port-security enable
port-security mac-address sticky MAC-ADDRESS
port-security max-mac-num 1
port-security protect-action shutdown
port-security aging-time 300
|
访问控制列表(Access Control List)
- 由一系列规则组成的集合,通过规则对报文分类处理。
- 通常由若干条 deny(拒绝) |
permit(允许) 语句组成。
基本访问控制列表
范围只能在 2000 - 2999。
BASH
1 2 3 4 5 6 7 8 9 10
| acl 2000
rule deny source IP-ADDRESS MASK
traffic-filter outbound acl 2000
|
高级访问控制列表
范围 3000 - 3999。
BASH
1 2 3 4 5 6 7 8
| acl 3000
rule 5 deny tcp source IP-ADDRESS MASK destination IP-ADDRESS MASK destination-port range 20 21
rule 10 permit tcp source IP-ADDRESS MASK destination IP-ADDRESS MASK destination-port eq 80
|
应尽量在靠近源地址的接口上应用;允许某个网段后,应拒绝其他网段。对于 FTP,需要同时指定 FTP(21)和 FTP-DATA(20)端口。