华为交换机实战命令大全(附应用场景)

Lear 2025-06-07 11:00:00
Categories: > > Tags:

华为交换机实战命令大全(附应用场景)

一、基础配置篇

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 # 进入特权模式
system-view

# 查看设备信息
display version
display device

# 配置管理IP(VLAN接口)
interface Vlanif 1
ip address 192.168.1.254 255.255.255.0
quit

# 配置Telnet远程登录
user-interface vty 0 4
authentication-mode password
set authentication password simple 123456
protocol inbound telnet

二、VLAN配置核心命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 # 创建VLAN
vlan batch 10 20 30

# 批量配置端口模式
port-group group-member GigabitEthernet 0/0/1 to GigabitEthernet 0/0/24
port link-type access
quit

# 将端口加入VLAN
interface GigabitEthernet 0/0/5
port link-type trunk
port trunk allow-pass vlan 10 20
port trunk pvid vlan 10

# 查看VLAN状态
display vlan

三、端口安全实战配置

1
2
3
4
5
# MAC地址绑定
interface GigabitEthernet 0/0/10
mac-address learning disable action discard
port-security enable
port-security mac-address sticky 5489-98c3-5d6a

四、路由协议配置

1
2
3
4
5
6
7
 # 静态路由
ip route-static 10.1.1.0 255.255.255.0 192.168.1.1

# OSPF配置
ospf 1 router-id 1.1.1.1
area 0
network 192.168.1.0 0.0.0.255

五、链路聚合(Eth-Trunk)

1
2
3
4
5
6
7
8
9
10
11
 # 创建聚合组
interface Eth-Trunk 1
mode lacp-static
quit

# 添加物理端口
interface range GigabitEthernet 0/0/23 to 0/0/24
eth-trunk 1

# 验证配置
display eth-trunk 1

六、生成树协议(STP)

1
2
3
4
5
6
7
8
 # 修改生成树模式
stp mode rstp

# 配置根桥
stp root primary

# 查看生成树状态
display stp brief

**

七、SSH安全登录

1
2
3
4
5
6
7
8
9
 # 生成RSA密钥
rsa local-key-pair create

# 配置SSH用户
ssh user admin authentication-type password
ssh user admin service-type stelnet

# 启用STelnet服务
stelnet server enable

八、ACL访问控制

1
2
3
4
5
6
7
8
 # 创建高级ACL
acl 3000
rule 5 deny tcp source 192.168.10.0 0.0.0.255 destination 10.1.1.0 0.0.0.255
destination-port eq 3389

# 应用ACL到接口
interface Vlanif 10
traffic-filter inbound acl 3000

九、QoS流量管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 # 创建流量分类
traffic classifier video
if-match dscp ef

# 定义流行为
traffic behavior video
remark dscp af41
car cir 10000

# 策略应用
qos policy video_policy
classifier video behavior video
interface GigabitEthernet 0/0/8
qos apply policy video_policy inbound

十、维护与排错命令

1
2
3
4
5
6
7
8
9
10
11
12
13
 # 查看端口统计
display interface brief

# 抓包诊断
capture-packet interface GigabitEthernet 0/0/5

# 日志查看
display logbuffer

# 配置文件管理
save
display current-configuration
reset saved-configuration