4. 动手配置:Cisco、Huawei、Juniper 的 Auto-Neg 开关
理论说完了,咱们直接进设备。这章我带你过一遍三大厂商的配置命令。别小看这步,很多线上故障就是“我以为配好了,其实没有”。
每个厂商的语法不太一样,但逻辑是通的——无非是 speed 和 duplex 两个参数。自动协商开启时,这两个参数都是 auto;手动固定时,就得成对设置。
⚠️ 核心原则:链路两端要么都开 Auto-Neg,要么都手动固定成一样的速率/双工。一端Auto一端手动,大概率出故障。我曾经在半夜被叫起来处理过一个丢包问题,查了半天就是思科手动100M全双工,对端华为开了Auto——最终协商成了100M半双工。
4.1 Cisco IOS / IOS-XE
思科的命令最直观。进入接口后,缺省就是 auto。如果你想确认或手动改,参考下面几步。
查看当前状态
Switch# show interfaces GigabitEthernet0/1
GigabitEthernet0/1 is up, line protocol is up
Hardware is Gigabit Ethernet, address aabb.cc00.0100 (bia aabb.cc00.0100)
MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
Keepalive set (10 sec)
Full-duplex, 1000Mb/s, media type is 10/100/1000BaseTX
input flow-control is on, output flow-control is unsupported
...
看到 Full-duplex, 1000Mb/s 就对了。如果显示 Auto-negotiation is on,说明协商启用。
手动关闭自动协商
注意:千兆端口通常不允许关闭 Auto-Neg(IEEE 标准强制),但百兆或10M端口可以。
Switch(config)# interface FastEthernet0/1
Switch(config-if)# speed 100
Switch(config-if)# duplex full
这两条一敲,自动协商就被禁用了。为什么?因为你手动指定了速率和双工,端口不会再发送 FLP/NLP 脉冲。
💡 我个人的习惯:在配完手动参数之后,一定跑一次
show interfaces status 确认 Operational 值与配置一致。有一次我配了100M全双工,结果对面设备掉了电,端口状态直接 down,我以为是配置错了——其实是物理层的问题。
重新开启自动协商
Switch(config-if)# speed auto
Switch(config-if)# duplex auto
或者直接恢复缺省:
Switch(config-if)# no speed
Switch(config-if)# no duplex
4.2 Huawei VRP
华为的命令风格偏“英文全拼”。进入接口后,缺省也是 Auto。
查看当前状态
<Huawei> display interface GigabitEthernet 0/0/1
GigabitEthernet0/0/1 current state : UP (ifindex: 12)
Line protocol current state : UP
Description: TO-CORE
Switch Port, PVID : 1, Hash arithmetic : According to SIP-XOR-DIP,Maximal MAC learning:16384
Non-virtual MAC number : 0
Port link-type: access
Auto-negotiation is enabled
Input flow-control: off, output flow-control: off
Duplex: Full, Speed: 1000Mbps
...
看到 Auto-negotiation is enabled 和 Duplex: Full, Speed: 1000Mbps。
手动关闭 Auto-Neg
[Huawei-GigabitEthernet0/0/1] undo negotiation auto
[Huawei-GigabitEthernet0/0/1] speed 100
[Huawei-GigabitEthernet0/0/1] duplex full
这里要注意:华为的 undo negotiation auto 只是关闭协商能力,你必须接着配 speed 和 duplex,否则端口可能起不来。我见过有人只敲了 undo negotiation auto 忘记配速率,结果接口一直 down。
恢复自动协商
[Huawei-GigabitEthernet0/0/1] negotiation auto
这条命令会同时将 speed 和 duplex 改回 auto,不用额外配。
4.3 Juniper JunOS
Juniper 的风格是“层次化”。配置在 edit interfaces 下。
查看当前状态
root@juniper> show interfaces ge-0/0/0 extensive
Physical interface: ge-0/0/0, Enabled, Physical link is Up
Interface index: 137, SNMP ifIndex: 508
Link-level type: Ethernet, MTU: 1514, Speed: 1000mbps, Duplex: Full
...
Auto-negotiation: enabled
Speed: 1000mbps, Duplex: Full
...
手动关闭自动协商
root@juniper# set interfaces ge-0/0/0 gigether-options no-auto-negotiation
root@juniper# set interfaces ge-0/0/0 speed 100m
root@juniper# set interfaces ge-0/0/0 link-mode full-duplex
提交生效:
root@juniper# commit
⚠️ 避坑指南:Juniper 的
no-auto-negotiation 需要在 gigether-options 层级下配置。如果你的是 FastEthernet 接口(比如 fe-0/0/0),那要用 fastether-options。我曾在一次升级项目里搞混了,配了不存在的选项,commit 时直接报语法错误。
重新开启自动协商
root@juniper# delete interfaces ge-0/0/0 gigether-options no-auto-negotiation
root@juniper# delete interfaces ge-0/0/0 speed
root@juniper# delete interfaces ge-0/0/0 link-mode
root@juniper# commit
4.4 三大厂商命令对比
为了方便你快速查阅,我整理了一个表。你把它截图存手机里,上架时直接翻。
| 操作 | Cisco | Huawei | Juniper |
|---|---|---|---|
| 查看 Auto-Neg 状态 | show interfaces |
display interface |
show interfaces extensive |
| 关闭 Auto-Neg | speed 100 / duplex full |
undo negotiation auto / speed 100 / duplex full |
set no-auto-negotiation / set speed 100m / set link-mode full-duplex |
| 开启 Auto-Neg | speed auto / duplex auto 或 no speed / no duplex |
negotiation auto |
删除 no-auto-negotiation、speed、link-mode |
| 提交生效 | 即时生效 | 即时生效 | commit |
4.5 核心配置流程
下面这张图把整个决策逻辑串起来了。你配置前,先按这个图走一遍,基本不会出错。
📌 关键点:无论你选哪个厂商,最终都要检查端口 operational 速率和双工是否与预期一致。不要只看配置,链路层实际情况才是真理。
4.6 常见配置错误
最后说几个在项目中踩过的坑,你配的时候留个心。
- 只配速率不配双工:有些设备缺省双工是 auto,但速率你设了 100M,结果双工协商成半双工。所以 always 成对设置。
- 光口强制关闭 Auto-Neg:千兆及以上光口(SFP/SFP+),802.3 标准不允许关闭自协商,强行关可能导致端口 flap。我遇到过有人把 10G 光口设了
no auto-negotiation,结果链路丢包率高达 20%。 - 配完后没 commit(Juniper):Juniper 的配置是候选集,不 commit 就不生效。上架前一定要养成
commit check+commit的习惯。 - 两端厂商不同,默认策略有差异:比如老版本的 Cisco 端口缺省会开启
auto-mdix,而华为可能没有。这点在配手动固定时尤其要小心。
💡 我自己的做法:每次改完 Auto-Neg 配置,我会立刻在两端设备上同时跑一个抓包(
tcpdump -i any -e 或者用嵌入式 Ethtool)看有没有 FLP/NLP 脉冲。如果一端关了协商,另一端还在发脉冲,那就能快速定位问题。