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
对以太网卡,加前缀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编号
将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
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; |
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); |
经过步骤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
相关文章推荐
- CentOS7网卡命名规则
- centos7网卡命名机制
- centos7网卡重命名eth0
- CentOS7网卡的命名规则
- CentOS7使用传统的网卡命名
- 关于centos7的网卡命名
- centos7网卡重命名方法以及更换网卡导致起不来网卡的解决方法
- 关于centos7的网卡命名
- centos7 网卡命名规则详解
- 为什么应该在 Linux 上使用命名管道 | Linux 中国
- 快排为什么那样快
- 数学之美番外篇:快排为什么那样快
- 快排为什么那样快
- 错误处理:vmware下克隆centos7配置静态ip地址网卡问题
- 关闭“一致性网络设备命名法” 修改centos网卡名称为 eth0
- 为什么现在改用int.TryParse了
- linux--centos7更改网卡名称eth0
- myeclipse中直接复制的(或者重命名的)项目为什么不能正常运行?
- 命名空间,输入输出流,为什么支持重载,缺省,指针与引用
- centos7安装时怎样将网卡名改为centos6的形式