Linux 关闭链路自动协商功能

链路自动协商以本端口根据对端设备的端口的连接速度和双工模式,彼此将模式与连接速度调整到最高的公共水平。

在Linux操作系统环境中,我们需要使用ethtool工具来进行配置。

1.安装工具

  • RHEL
$ sudo yum -y install ethtool 
  • Debian
$ sudo apt-get install ethtool

2.查看网卡当前速度,双工或其它信息

$ sudo ethtool -s eth2
Settings for eth2:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Supported pause frame use: Symmetric
	Supports auto-negotiation: Yes
	Supported FEC modes: Not reported
	Advertised link modes:  1000baseT/Full
	Advertised pause frame use: Symmetric
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Speed: 1000Mb/s
	Duplex: Full
	Port: Twisted Pair
	PHYAD: 1
	Transceiver: internal
	Auto-negotiation: on
	MDI-X: on (auto)
	Supports Wake-on: pumbg
	Wake-on: g
	Current message level: 0x00000007 (7)
			       drv probe link
	Link detected: yes

3.变更网卡速度,双工

将网卡eth2速度固定1000M,双工,且关闭自动协商

$ sudo ethtool -s eth2 speed 1000 duplex full autoneg off

以上操作为临时操作,重启操作系统后配置会还原。

4.写入配置文件中(永久状态)

  • RHEL
$ echo ETHTOOL_OPTS=\"speed 1000 duplex full autoneg off\" | sudo tee -a /etc/sysconfig/network-scripts/ifcfg-eth2
  • Debian
auto eth2
iface eth2 inet static
  pre-up /usr/sbin/ethtool -s eth2 autoneg off speed 1000 duplex full

5.交换机侧配置

以华为交换机为例

interface GigabitEthernet0/0/xx
 undo negotiation auto
 speed 1000