如何控制networking接口的顺序?

我正在尝试configuration一个带有3个NIC的机器,前两个是内置GbE控制器,第三个是10GbE控制器。 通过NetworkManager,我configuration了第一个GbE网卡(当时是eth0),使用静态IP地址。 第二块GbE网卡将在单独的专用networking上configuration,而10GbE网卡现在还没有被使用。

当我重新启动机器时,eth0,eth1,eth2等的顺序似乎是随机的。 有时eth0会拿起静态IP地址,有时候会被识别为eth1并获取一个DHCP地址。 在这种情况下,我需要在重新configuration之前交换电缆。

如何控制sorting,使特定的物理网卡始终以eth0或eth1forms出现,而无需更改下次重新启动?

RHEL 6中仍然支持的方法是通过udev设备规则。

应该有一个自动生成的/etc/udev/rules.d/70-persistent-net.rules强制一致的命名:

 # This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # PCI device 0x8086:0x10c9 (igb) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:1d:d1:30", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x8086:0x10c9 (igb) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:90:1d:d1:31", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" 

如果没有,您可以使用与您自己的MAC地址相似的语法强制持久设备命名。

对于RHEL 6和未来,支持的方式是一致的networking设备命名 。 这可以确保所有的接口获得一个有意义的名字,这个名字是基于硬件的,并且在系统的整个生命周期中保持不变(如果你不改变硬件的话,通常即使你这样做也是如此)。

(请注意,在RHEL 7中,使用了不同的命名格式 。)

要切换到它,您需要重新安装系统 ,并且在安装时,您必须在启动安装介质时以及每次启动系统时传递内核命令行选项biosdevname=1

也许有人会发现这些信息有用:首先,在RHEL7中,您不需要重新安装系统来更改接口命名约定。

注意:需要引导参数:

 a) With no parameters or net.ifnames=1 used, the names will use systemd Predictable Network Interface Names b) With biosdevname=1 used, the names will be managed by udev (technically systemd-udev) using Consistent Network Device Naming c) With net.ifnames=0 and biosdevname=0 both specified, traditional ("kernel names") ethX names will be used; if udev rules are also added they can rename the interfaces to anything except eth 

例:

 Edit /etc/default/grub append selected params eg. biosdevname=0 net.ifnames=0 grub2-mkconfig -o /boot/grub2/grub.cfg 

而在主题的情况下:当你需要调整所有接口的顺序时,程序很简单:

 mv /etc/udev/rules.d/70-persistent-net.rules /root/ (New udev rules will be generated at next boot) Adjust configuration files in /etc/sysconfig/network-scripts/ifcfg-eth* [Edit device name, connection name, HWADDR etc.] Reboot and then udev will generate rules basing on configuration files - if you did it properely. 

正如RedHat 文档所build议的那样,您可以在接口configuration文件中指定HWADDR=MAC-address参数。

HWADDR = MAC地址,其中MAC地址是以AA:BB:CC:DD:EE:FF格式表示的以太网设备的硬件地址。 必须在包含多个NIC的计算机中使用此指令,以确保为接口分配正确的设备名称,而不pipe每个NIC的模块的configuration加载顺序如何。 该指令不应与MACADDR一起使用。

正如HBruijn所提到的,rhel6中的sorting是/etc/udev/rules.d/70-persistent-net.rules。 这个文件是由/ lib / udev / write_net_rules写的。

如果由于某种原因,你需要一个任意的,预定义的networking接口顺序,你可以用你自己的脚本replace这个脚本来创build70-persistent-net.rules文件。 这确保它不会被覆盖。

您可以使用获取设备信息

 lspci | grep -i ethernet 

获取设备列表

 ethtool -i ethx ethtool -P ethx 

获取每个MAC地址(关联PCI @ / MAC @)。