您的位置:首页 > 运维架构 > Linux

centos7: 为什么要改用那样的网卡命名法

2016-10-10 16:18 316 查看
好处有几个

Stable interface names across reboots
Stable interface names even when hardware is added or removed, i.e. no re-enumeration takes place

Stable interface names when kernels or drivers are updated/changed
Stable interface names even if you have to replace broken ethernet cards by new ones

The names are automatically determined without user configuration, they just work

The interface names are fully predictable, i.e. just by looking at lspci you can figure out what the interface is going to be called

Fully stateless operation, changing the hardware configuration will not result in changes in /etc

Compatibility with read-only root
The network interface naming now follows more closely the scheme used for aliasing block device nodes and other device nodes in /dev via symlinks

Applicability to both x86 and non-x86 machines
The same on all distributions that adopted systemd/udev
It's easy to opt out of the scheme (see below)

具体来说,就是比较稳定,无论重起还是升级,网卡名都还是这几个,因为俺网卡名命名都基于硬件,所以一样

这是查看网卡信息的情况

[root@z parameters]# lspci -v

1c:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)

    Subsystem: VMware VMXNET3 Ethernet Controller

    Physical Slot: 257

    Flags: bus master, fast devsel, latency 0, IRQ 17

    Memory at fcefb000 (32-bit, non-prefetchable) [size=4K]

    Memory at fcefc000 (32-bit, non-prefetchable) [size=4K]

    Memory at fcefe000 (32-bit, non-prefetchable) [size=8K]

    I/O ports at b000 [size=16]

    [virtual] Expansion ROM at eb300000 [disabled] [size=64K]

    Capabilities: [40] Power Management version 3

    Capabilities: [48] Express Endpoint, MSI 00

    Capabilities: [84] MSI: Enable- Count=1/1 Maskable- 64bit+

    Capabilities: [9c] MSI-X: Enable+ Count=25 Masked-

    Capabilities: [100] Device Serial Number ff-56-50-00-c7-ab-bc-fe

    Kernel driver in use: vmxnet3

注意里面有个槽号slot 257

这和网卡命名ens257完全一样

ip link

8: ens257: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000

    link/ether 00:50:56:bc:ab:c7 brd ff:ff:ff:ff:ff:ff

这是kernel部分的代码【参考2】

代码的处理逻辑

1 builtin_net_id 创建内置网卡id

switch (i) {case ARPHRD_ETHER:prefix =
"en";
break;
对以太网卡,加前缀en
2 调用names_pci

/* get PCI based path names, we compose only PCI based paths */ err =
names_pci(dev, &names);

3 调用dev_pci_slot

4 在dev_pci_slot中,

查看文件/sys/bus/pci/slots,找到对应的slot编号

if (hotplug_slot >
0) {
s = names->pci_slot;l =
sizeof(names->pci_slot);
if (domain >
0)
l =
strpcpyf(&s, l, "P%d", domain);
l =
strpcpyf(&s, l, "s%d", hotplug_slot);
将s%d编号加入进去。

经过步骤1,4,出现了ens257这样的网卡名。这其中s代表slot, 257代表槽号

参考:

1 https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/
2 https://github.com/systemd/systemd/blob/master/src/udev/udev-builtin-net_id.c#L20
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: