可以通过修改 .mac 地址来设置一致的接口命名/etc/udev/rules.d/70-persistent-net.rules
。
- 能否通过 PCI 插槽编号建立一致的接口命名? (我尝试过但失败了)
- 除了 MAC 地址之外,还有其他方法可以定义一致的接口命名吗?
我使用的是 Ubuntu 14.04。
如果我将 4 端口 NIC 插入最顶部的 pci 插槽,则修改70-persistent-net.rules
每个 pci 插槽不起作用:
$ lspci -D | grep -i 以太
0000:04:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
0000:04:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
0000:05:00.0 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
0000:05:00.1 Ethernet controller: Intel Corporation 82576 Gigabit Network Connection (rev 01)
0000:0b:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
0000:0c:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
这是我使用的文件:/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.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="aa:bb:cc:dd:ee:ff", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x8086:0x10d3 (e1000e)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:aa:bb:cc:dd:ee", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:04:00.0", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:04:00.1", NAME="eth3"
SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:05:00.0", NAME="eth4"
SUBSYSTEM=="net", ACTION=="add", KERNELS="0000:05:00.1", NAME="eth5"
现在,如果我在同一个插槽中插入一个两端口网卡:
0000:02:00.0 Ethernet controller: Intel Corporation 82580 Gigabit Fiber Network Connection (rev 01)
0000:02:00.1 Ethernet controller: Intel Corporation 82580 Gigabit Fiber Network Connection (rev 01)
0000:06:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
0000:07:00.0 Ethernet controller: Intel Corporation 82574L Gigabit Network Connection
您可以看到 PCI 插槽编号发生了变化。
答案1
您应该有一个文件,/etc/udev/rules.d/70-persistent-net.rules
其中包含类似于以下内容的行:-
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="04:01:07:ab:6e:01", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
对此文件进行备份(在 之外rules.d
)并将原始文件编辑为:-
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:00:03.0", NAME="eth0"
其中该KERNELS
值可以从第一列中收集lspci -D
0000:00:03.0 Ethernet controller: Red Hat, Inc Virtio network device
上面的 PCI 地址分解为Domain:Bus:Slot.Function
,因此上面的设备安装在插槽 3 上。
笔记:我无法访问我在编写本文时使用的虚拟机的控制台(我通过 SSH 连接),所以我无法检查它,因为如果出现问题我将被锁定。底线是 - 执行此操作时要小心,因为您可能会将自己锁定在远程系统之外;你在本地系统上会没问题。