我从一个 ova 上构建了 300 多个 ubuntu VM。VM 上有 5 个网络适配器。我需要从 VM 内部根据 VMware ESX 顺序重命名它们。
例如不同场景下的命名:
- 第一个 = eth1,第二个 = eth2,第三个 = em0,等等
- 第一 = em0,第二 = em9,第三 = br0,等等
- 第一个 = phys1,第二个 = phys2,第三个 = eth0,等等。
我的问题是 lspci|grep“以太网控制器”没有按顺序显示它们:
04:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
0b:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
0c:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
13:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
1b:00.0 Ethernet controller: VMware VMXNET3 Ethernet Controller (rev 01)
04:00.0应该是 eth1,但是实际上是 eth4-- 我通过 Mac 进行了比较
它确实是命令:/etc/udev/rules.d/70-persistent-net.rules
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:0b:00.0", ATTR{dev_id}=="0x0", NAME="eth1"
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:13:00.0", ATTR{dev_id}=="0x0", NAME="eth2"
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:1b:00.0", ATTR{dev_id}=="0x0", NAME="eth3"
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:04:00.0", ATTR{dev_id}=="0x0", NAME="eth4"
SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:0c:00.0", ATTR{dev_id}=="0x0", NAME="eth5"
这是来自 ESXi 上的 ubuntu vm 的信息:
cat ubuntu.vmx|grep eth|more
ethernet0.present = "TRUE"
ethernet0.virtualDev = "vmxnet3"
ethernet0.wakeOnPcktRcv = "FALSE"
ethernet0.networkName = "_clients_network_1"
ethernet0.addressType = "vpx"
ethernet1.present = "TRUE"
ethernet1.virtualDev = "vmxnet3"
ethernet1.wakeOnPcktRcv = "FALSE"
ethernet1.networkName = "_servers_network_1"
ethernet1.addressType = "vpx"
ethernet2.present = "TRUE"
ethernet2.virtualDev = "vmxnet3"
ethernet2.wakeOnPcktRcv = "FALSE"
ethernet2.networkName = "_clients_network_1"
ethernet2.addressType = "vpx"
ethernet3.present = "TRUE"
ethernet3.virtualDev = "vmxnet3"
ethernet3.wakeOnPcktRcv = "FALSE"
ethernet3.networkName = "_servers_network_1"
ethernet3.addressType = "vpx"
ethernet4.present = "TRUE"
ethernet4.virtualDev = "vmxnet3"
ethernet4.wakeOnPcktRcv = "FALSE"
ethernet4.networkName = "VM Network"
ethernet4.addressType = "vpx"
ethernet0.generatedAddress = "00:50:56:a8:66:24"
ethernet0.pciSlotNumber = "192"
ethernet1.generatedAddress = "00:50:56:a8:32:78"
ethernet1.pciSlotNumber = "224"
ethernet2.generatedAddress = "00:50:56:a8:7e:2c"
ethernet2.pciSlotNumber = "256"
ethernet3.generatedAddress = "00:50:56:a8:56:91"
ethernet3.pciSlotNumber = "1184"
ethernet4.generatedAddress = "00:50:56:a8:67:ad"
ethernet4.pciSlotNumber = "1216"
ethernet0.generatedAddressOffset = "0"
ethernet1.generatedAddressOffset = "10"
ethernet2.generatedAddressOffset = "20"
ethernet3.generatedAddressOffset = "30"
ethernet4.generatedAddressOffset = "40"
答案1
想法 1
VM 应该与其主机完全隔离,因此设计就是为了让这种超级推测变得困难。
但是,您可以使用 guest-info 功能来执行此操作。您需要编写主机端脚本,以填充客户机硬件拓扑信息(PowerShell 等)的映射。然后使用 vmtools 从客户机内部获取该信息(在此过程中使用 udev 黑客攻击)。
http://www.virtuallyghetto.com/2011/01/how-to-extract-host-information-from.html
我认为为了使其正常工作,您可能需要先为 VM 启用某些功能,但我不确定是什么。
以下命令会得到什么结果?我得到了错误,但是上面的链接表明您应该能够获取从虚拟机外部设置的信息。
# vmtoolsd -l –cmd "info-get"
[Apr 22 22:30:34.545] [ warning] [vmsvc] Error in the RPC receive loop: RpcIn: Unable to send.
[Apr 22 22:30:35.546] [ warning] [vmsvc] Error in the RPC receive loop: RpcIn: Unable to send.
...
想法 2
您可以使用它ethtool --driver IFNAME
来获取公交信息。也许这样最简单。以下是 e1000 的示例
# ethtool --driver eth0
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version:
bus-info: 0000:02:00.0
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no
对于 vmxnet3
# ethtool --driver eth0
driver: vmxnet3
version: 1.1.30.0-k-NAPI
firmware-version:
bus-info: 0000:0b:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no
我想知道寄存器转储是否有用...看起来不像,但是十六进制没有多大意义。