当我在我的ubuntu机器上添加一个新的nic卡时,什么会隐藏起来呢?
哪个程序/模块负责将设备的硬件地址映射到名称(eth0/eth1)。这个映射(hwaddress1-eth0,hwaddress2-eth1)实际存储在哪里。?

最佳答案

据我所知,内核本身会根据网卡连接到总线的顺序来命名网卡。这种行为与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设备的虚拟机)
由于这些信息是从运行的内核中派生出来的,我敢打赌您也会在那里找到硬件地址。
快乐的格瑞平!

10-08 04:54