当我将新的 NIC 卡添加到我的 Ubuntu 机器时,幕后发生了什么? 哪个程序/模块负责将设备的硬件地址映射到名称 (eth0/eth1)。这个映射(HWaddress1-eth0,HWaddress2-eth1)实际存储在哪里?
最佳答案
据我所知,内核本身会根据它们连接到总线的顺序来命名 nic。此行为与 SCSI/SATA 命名非常相似。
看一下输出
lspci
你应该在那里找到相应的网卡。第一列,例如0000:00:03.0
包含以下信息:
0000 : PCI domain (each domain can contain up to 256 PCI buses)
00 : the bus number the device is attached to
03 : the device number
.0 : PCI device function
(来源:http://prefetch.net/articles/linuxpci.html)
在/sys/bus/pci(_express)/devices/下,您会找到与 lspci 输出匹配的链接。当你进入网卡的文件夹时,里面有很多文件和文件夹。
你可以做一个查找和grep
cd /sys/bus/.../devices/0000:00:03.0/
someuser@somemachine:/sys/bus/pci/devices/0000:00:03.0$ find -type f -exec grep 'ethX' /dev/null {} \; 2>/dev/null
其中 ethX 是您的设备名称,用于获取如下输出
./virtio0/net/ethX/uevent:INTERFACE=eth0
(在我的例子中是一个带有 virtio 设备的虚拟机)
由于此信息来自正在运行的内核,我敢打赌您也会在那里找到硬件地址。
Grepping 愉快!
关于linux - 硬件地址如何映射到 Linux(Ubuntu) 机器上的 eth0/eth1。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40130038/