如何获得以无头模式运行的VirtualBox虚拟机的桥接IP地址?

我在服务器上设置了VirtualBox。 它被设置为一个桥接虚拟机,并有一个IP地址。 它现在运行在无头模式下,从“VBoxHeadless -s PuppetMaster”开始。

如何找出VM使用VBoxManage的IP?

我可以通过以下命令的组合来find我的无头VB:

# Update arp table for i in {1..254}; do ping -c 1 192.168.178.$i & done # Find vm name VBoxManage list runningvms # Find MAC: subsitute vmname with your vm's name VBoxManage showvminfo vmname # Find IP: substitute vname-mac-addr with your vm's mac address in ':' notation arp -a | grep vmname-mac-addr 

但更简单:在linux中,你可以连接到VB:

 # Default VirtualBox Listening Port: 3389 rdesktop -N hostingserver:3389 

这个命令将会打开一个shell窗口,你可以直接访问Headless VB,在这里你可以获取你的无头VB IP:ip addr

安装客人添加和(假设Linux是客人),您可以运行以下:

 VBoxManage --nologo guestcontrol yourVirtualMachineName execute --image "/sbin/ifconfig" --username yourUser --password yourPassword --wait-exit --wait-stdout -- -a 
 VBoxManage guestproperty enumerate {`VBoxManage list runningvms | awk -F"{" '{print $2}'` | grep IP | awk -F"," '{print $2}' | awk '{print $2}' 

不知道VBoxManage是否可以直接提供这些信息。 你可以做的是运行以下命令来查看网卡configuration。

 VBoxManage showvminfo PuppetMaster | egrep ^NIC 

如果没有其他的东西会给你提供MAC地址,那么你可以通过其他方式find实际的IP地址。

您可以使用以下命令直接获取它:

 VBoxManage list bridgedifs 

从virtualbox.org论坛 –

VBoxManage guestproperty get <vm-name> "/VirtualBox/GuestInfo/Net/0/V4/IP" | cut -f2 -d " "