H3C&Cisco命令对照
都支持| in
<关键字> 的输出过滤方式。
用?
查看当前帮助。
思科在配置模式下要执行命令时应使用do
关键字。
业务高频
功能描述 | Cisco | H3C |
---|---|---|
查看MAC地址表 | show mac address-table |
display mac-address |
查看ARP表 | show arp |
display arp |
查看LLDP邻居 | show cdp neighbors detail |
dis lldp neighbor-information <interface g1/0/48> verbose /disp lldp neighbor-information list |
快速查看各端口信息(包括VLANIF) | show ip interface brief |
display interface brief |
查看所有VLAN信息 | show vlan |
display vlan all |
写入配置 | write |
save |
查看当前配置 | show ru |
dis current-configuration |
查看ACL配置 | show access-lists |
dis acl all |
tftp备份配置/恢复配置 【首先备份】 |
【特权模式】copy running-config tftp: / copy tftp: running-config 后write |
【用户视图】tftp 192.168.2.2 put startup.cfg /tftp 192.168.2.2 get startup.cfg |
查看文件列表 | dir | dir |
端口操作
功能描述 | 思科 (Cisco) | 华三 (H3C) |
---|---|---|
批量选择端口 | interface range type slot/port - slot/port (例如: int range g1/0/1 - 24 ) |
interface range type slot/port to slot/port (例如: int range g1/0/1 to g1/0/24 ) |
interface range type slot/port, type slot/port (例如: int range g1/0/1, g1/0/3 ) |
interface range type slot/port, type slot/port (例如: int range g1/0/1, g1/0/3 ) |
|
端口组/别名 | - | interface range name [name] interface [interface-list] (例如: int range name myGroup interface g1/0/1 to g1/0/12 ) |
配置Access端口 | switchport mode access switchport access vlan [vlan-id] |
port link-type access port access vlan [vlan-id] 或 port default vlan [vlan-id] |
配置Trunk端口 | switchport mode trunk switchport trunk encapsulation dot1q switchport trunk allowed vlan [vlan-list] |
port link-type trunk port trunk permit vlan [vlan-list] |
端口速率与双工 | speed [10 | 100 | 1000 | auto] duplex [half | full | auto] |
speed [10 | 100 | 1000 | auto] duplex [half | full | auto] |
端口描述 | description [description-string] |
description [description-string] |
关闭/开启端口 | shutdown no shutdown |
shutdown undo shutdown |
保存配置 | copy running-config startup-config 或 write memory |
save |
-
思科注意事项:
- 在
interface range
模式下,所有配置命令会立即应用到所有选中的端口上。 - 使用
show vlan brief
或show interfaces status
来验证端口VLAN成员关系和其他状态。 - 思科交换机的端口默认是动态协商模式(dynamic desirable),为连接终端设备,建议配置为
switchport mode access
。
- 在
-
华三注意事项:
-
H3C V7版本:支持与思科相似的
interface range
命令进行批量配置。 -
H3C V5版本:通常使用端口组(port-group) 方式进行批量配置。需要先创建端口组并添加成员,然后在端口组视图中进行配置。
# 创建端口组示例 (V5版本常用) system-view port-group manual [group-name] # 创建手工端口组 group-member [interface-range] # 添加端口成员,如 GigabitEthernet 1/0/1 to GigabitEthernet 1/0/24 port link-type access port access vlan 10 quit
-
使用
display interface brief
或display vlan brief
来验证配置结果。
-
端口安全
- Cisco
# 进入特权模式
Switch> enable
#进入全局配置模式
Switch> configure terminal
# 进入接口模式
Switch(config)# interface <interface-id> # 例如 FastEthernet0/1 或 GigabitEthernet0/1
# 端口安全通常要求在Access模式的端口上配置
Switch(config-if)# switchport mode access
# 开启端口安全
Switch(config-if)# switchport port-security
#设定该端口允许学习的最大MAC地址数 默认为1
Switch(config-if)# switchport port-security maximum <数量>
#------------------------------------------------------------------------------------------------
# 【Option1】使用Sticky自动学习并绑定MAC地址:
Switch(config-if)# switchport port-security mac-address sticky
# 【Option2】手动绑定特定的MAC地址
Switch(config-if)# switchport port-security mac-address <MAC地址> # 例如 0000.1111.2222
#------------------------------------------------------------------------------------------------
#设置违规处理模式 静默丢弃/带记录的丢弃/禁用端口 默认为shutdown
Switch(config-if)# switchport port-security violation { protect | restrict | shutdown }
#------------------------------------------------------------------------------------------------
#回到全局配置模式 exit 后:
#若端口因违规被关闭(err-disable),可先shutdown再no shutdown该接口,或配置自动恢复
Switch(config)# errdisable recovery cause psecure-violation
# 设置恢复检测间隔,例如300秒
Switch(config)# errdisable recovery interval <秒数>
- H3C
# 进入系统视图
<H3C> system-view
# 进入指定接口视图
[H3C] interface GigabitEthernet 1/0/1
[H3C-GigabitEthernet1/0/1] port-security enable # 启用端口安全功能
#------------------------------------------------------------------------------------------------
# 【Option1】autoLearn(自动学习) 此模式允许端口自动学习MAC地址并将其转换为安全MAC地址(Sticky MAC)
[H3C-GigabitEthernet1/0/1] port-security max-mac-count 2 # 设置该端口最大学习MAC地址数量为2
[H3C-GigabitEthernet1/0/1] port-security port-mode autolearn # 当端口工作于autoLearn模式后,无法更改端口安全允许的最大MAC地址数。
# 【Option2】secure(静态绑定)
[H3C-GigabitEthernet1/0/1] port-security mac-address security 0001-0001-0002 vlan 10
[H3C-GigabitEthernet1/0/1] port-security port-mode secure
新机配置应该在全局维度启用端口安全
<H3C> system-view
[H3C] port-security enable
对于已经autoLearn到max-mac-count之后又要新增设备的情况:
Can't add the security MAC address for the number of security MAC addresses on the interface has reached the maximum.
[H3C-GigabitEthernet1/0/1] dis this # (在终端外备份当前port-security配置)
[H3C-GigabitEthernet1/0/1] undo port-security port-mode # 先关闭autoLearn
[H3C-GigabitEthernet1/0/1] port-security max-mac-count 3 # 调整对应数量
[H3C-GigabitEthernet1/0/1] port-security port-mode autolearn # 再次启用autoLearn
[H3C-GigabitEthernet1/0/1] port-security mac-address security sticky 0000-8544-d326 vlan 10 # 绑定之前备份地址+新地址
通常记录表
功能分类 | 功能描述 | Cisco | H3C |
---|---|---|---|
基础操作 | 进入特权模式/系统视图 | enable |
system-view |
进入配置模式 | configure terminal |
- | |
显示当前运行配置 | show running-config |
display current-configuration |
|
显示已保存的启动配置 | show startup-config |
display saved-configuration |
|
保存配置 | copy running-config startup-config 或 write |
save |
|
显示系统版本信息 | show version |
display version |
|
退出当前配置模式/返回上级视图 | exit |
quit |
|
退回用户视图 | end |
return |
|
设置设备主机名 | hostname <name> |
sysname <name> |
|
重启设备 | reload |
reboot |
|
取消/关闭当前设置 | no |
undo |
|
接口配置 | 进入指定接口视图 | interface <interface-type> <number> |
interface <interface-type> <number> |
开启接口(取消关闭) | no shutdown |
undo shutdown |
|
关闭接口 | shutdown |
shutdown |
|
VLAN配置 | 创建VLAN | vlan <vlan-id> |
vlan <vlan-id> |
进入VLAN接口视图 | interface vlan <vlan-id> |
interface vlan <vlan-id> |
|
配置端口为Access模式 | switchport mode access |
port link-type access |
|
将Access端口加入指定VLAN | switchport access vlan <vlan-id> |
port access vlan <vlan-id> |
|
配置端口为Trunk模式 | switchport mode trunk |
port link-type trunk |
|
允许特定VLAN通过Trunk端口 | switchport trunk allowed vlan <vlan-list> |
port trunk permit vlan <vlan-list> |
|
查看VLAN信息 | show vlan |
display vlan |
|
路由配置 | 查看路由表 | show ip route |
display ip routing-table |
配置静态路由 | ip route <network> <mask> <next-hop> |
ip route-static <network> <mask> <next-hop> |
|
配置默认路由 | ip route 0.0.0.0 0.0.0.0 <next-hop> |
ip route-static 0.0.0.0 0.0.0.0 <next-hop> |
|
启用OSPF路由进程 | router ospf <process-id> |
ospf <process-id> |
|
宣告OSPF网络 | network <network> <wildcard-mask> area <area-id> |
area <area-id> network <network> <wildcard-mask> |
|
其他常用 | 查看接口状态与配置 | show interface [<interface-type> <number>] |
display interface [<interface-type> <number>] |
查看ARP表 | show arp |
display arp |
|
持续ping | ping <ip-address> repeat <count> |
ping -c <count> <ip-address> |
|
路径追踪 | traceroute <ip-address> |
tracert <ip-address> |
|
查看日志信息 | show logging |
display logbuffer |