交换机开局配置不像想象中难,难在厂商命令差异和几个默认行为。这篇把华为 VRP、H3C Comware、思科 IOS 三家的开局动作并排放,方便现场对着敲。

一、开局先想清楚五件事

  • 管理 VLAN 与地址:管理地址别放在 VLAN 1,业务与管理分开
  • VLAN 规划:按部门/楼层/业务划分,预留号段,命名写清楚
  • 上行链路:单链路还是聚合?聚合要不要跨设备
  • 三层放哪:交换机做网关,还是把网关交给防火墙/路由器
  • 回滚方案:变更前先导出配置,窗口内保留旧配置文本

二、VLAN 创建与端口划入

华为 VRP:

system-view
vlan 10
 description office
 quit
interface GigabitEthernet0/0/1
 port link-type access
 port default vlan 10

H3C Comware:

system-view
vlan 10
 description office
 quit
interface GigabitEthernet1/0/1
 port link-type access
 port access vlan 10

思科 IOS:

enable
configure terminal
vlan 10
 name office
exit
interface GigabitEthernet1/0/1
 switchport mode access
 switchport access vlan 10

差异点:划 VLAN 这一步,H3C 用 port access vlan,华为用 port default vlan,思科用 switchport access vlan;三家都把「PVID」设成该 VLAN。

三、Trunk 上行与 PVID / Native VLAN

华为:

interface GigabitEthernet0/0/24
 port link-type trunk
 port trunk allow-pass vlan 10 20
 port trunk pvid vlan 10

H3C:

interface GigabitEthernet1/0/24
 port link-type trunk
 port trunk permit vlan 10 20
 port trunk pvid vlan 10

思科:

interface GigabitEthernet1/0/24
 switchport trunk encapsulation dot1q
 switchport mode trunk
 switchport trunk allowed vlan 10,20
 switchport trunk native vlan 10

一句话记法:华为 allow-pass、H3C permit、思科 allowed;PVID / Native 是同一件事(不打标签的那个 VLAN),两端必须一致。

四、链路聚合(Eth-Trunk / Bridge-Aggregation / Port-channel)

华为:

interface Eth-Trunk1
 mode lacp-static
 trunkport GigabitEthernet0/0/1 to GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan all

H3C:

interface Bridge-Aggregation 1
 link-aggregation mode dynamic
 quit
interface range GigabitEthernet1/0/1 to GigabitEthernet1/0/2
 port link-aggregation group 1

思科:

interface range GigabitEthernet1/0/1-2
 channel-group 1 mode active

必须一致:成员口的速率、双工、链路类型、允许 VLAN 要跟聚合口一致,否则成员口不参与转发(H3C 显示 Unselected,华为显示 Unselected,思科 show etherchannel summary 显示不在 Po 里)。

五、管理平面:只留 SSH

华为:

stelnet server enable
user-interface vty 0 4
 authentication-mode aaa
 protocol inbound ssh
aaa
 local-user admin password irreversible-cipher 你的口令
 local-user admin privilege level 15
 local-user admin service-type ssh

H3C:

ssh server enable
line vty 0 4
 authentication-mode scheme
 protocol inbound ssh
local-user admin class manage
 password cipher 你的口令
 service-type ssh
 authorization-attribute user-role network-admin

思科:

crypto key generate rsa modulus 2048
ip ssh version 2
username admin privilege 15 secret 你的口令
line vty 0 4
 transport input ssh
 login local

同时关掉没用的:Telnet、HTTP/Web 管理、SNMP v1/v2 明文团体字;管理源地址用 ACL 收窄(只允许运维网段)。

六、保存与回滚

华为:save
H3C :save force
思科:write memory(或 copy running-config startup-config)

回滚思路:变更前把 display current-configuration / show running-config 存成文本,出问题按段改回;不要指望「没有保存就不会生效」——很多命令是立即生效的。

七、三家命令速查

  • 看端口状态:华为 display interface brief;H3C display interface brief;思科 show interfaces status
  • 看 VLAN:华为 display vlan;H3C display vlan all;思科 show vlan brief
  • 看端口 VLAN:华为 display port vlan;H3C display port vlan active;思科 show interfaces trunk
  • 看 MAC:华为 display mac-address;H3C display mac-address;思科 show mac address-table
  • 看聚合:华为 display eth-trunk 1;H3C display link-aggregation verbose;思科 show etherchannel summary
  • 看生成树:华为 display stp brief;H3C display stp brief;思科 show spanning-tree

八、收尾建议

  • 配置改完立刻导出一份文本,命名带日期,放版本库或共享盘
  • 端口描述、VLAN 名字一定写,三个月后只有描述能救你
  • 现网变更挑业务低峰,关键链路先做聚合再谈优化