When I configure the IP address of VirtualBox 4.3.2 (running on Windows 8.1) host only adapter, it changes it back to some other IP. Guest OS is CentOS 6.5.
I tried to set the IP in network connections in device manager. But I get this error after I clicked on properties of TCP/IPv4:
In order to configure tcp/ip you must install newtwork adapter.
I want to give these settings to Host only adapter:
- IP: 10.20.0.2
- Mask: 255.255.255.0
DHCP disabled.
But it automatically gets changed to something like:
- IP: 169.254.134.67 // Not fixed every time a new one
- Mask: 255.255.0.0
Here is the output of hostonlyifs
:
C:\Program Files\Oracle\VirtualBox>VBoxManage list hostonlyifs
Name: VirtualBox Host-Only Ethernet Adapter
GUID: ce2a5907-6034-4bb0-a45d-e30e90c17483
DHCP: Enabled
IPAddress: 169.254.134.67
NetworkMask: 255.255.0.0
IPV6Address: fe80:0000:0000:0000:08bf:284e:1182:8643
IPV6NetworkMaskPrefixLength: 64
HardwareAddress: 08:00:27:00:28:da
MediumType: Ethernet
Status: Up
VBoxNetworkName: HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter
As you can see above it shows DHCP enbled even though I did not enable it.
I tried doing this:
VBoxManage hostonlyif ipconfig "VirtualBox Host-Only Ethernet Adapter" --ip 10.20.0.2 --netmask 255.255.255.0
Still nothing happens.
I have disabled APIPA now the IP gets changed to 0.0.0.0
.
Best Answer
Not 100% sure what your setup is, but will explain that typically a “host-only” adapter in VirtualBox is a second network interface in addition to your main network interface.
For example, on my Mac OS X setup of VirtualBox, under “Preferences…” for VirtualBox itself —under “Network” tab/panel—I have a “host-only” adapter that is called
vboxnet0
. That is set as follows in the “Adapter” panel:Note that I have the following set in the “Adapter” panel:
192.168.56.1
255.255.255.0
[blank]
0
I also have the “DHCP Server” set to disabled. Note also that for this example, the network range for this adapter would be
192.168.56.x
. If you want this adapter to be a part of the10.20.0.x
range, then change the IPv4 address of the adapter from192.168.56.1
to10.20.0.1
.Then, in the actual “Settings” for the virtual machine you want to have this setup for, click “Settings”. Now, the main adapter—“Adapter 1”—should be set to the standard defaults as pictured here:
But then under “Adapter 2” you want to enable that adapter and set the “Attached to:” as “Host-only Adapter” and then set the “Name:”
vboxnet0
as pictured here:With that done, start up your guest OS—I am using Ubuntu, but this should work for most any Linux guest OS such as CentOS—and then type in the following to manually start up your new network connection on the second network port:
Note I have chosen the
192.168.56.10
address for the static address of this interface. You can set that to anything within the range of192.168.56.2
to192.168.56.255
. I simply chose the.10
address since it’s simple to remember; at least for me. And if you wanted to set the address to10.20.0.2
—assuming your address is in the10.20.0.x
range—then just change192.168.56.10
to10.20.0.2
.Now that
sudo ifconfig
only inits a temporary connection. If you were to reboot right now, that connection would be lost. So if you want to set this up as a permanent setting you would have to edit/etc/network/interfaces
as follows. First, open up that file using your favorite text editor; I like to usenano
:The contents of that file would look something like this:
Note how the setting for
eth0
is DHCP; leave that as is. To add the new network interface, you would add something like this to the bottom of the file:Note how
eth1
is set tostatic
and hasaddress
andnetmask
settings. Once added, just save the file. And now on reboot you machine will always know to assigneth1
and if you want to reach that guest OS from the host OS, you would just need to go to192.168.56.10
. And if you wanted to set the address to10.20.0.2
—assuming your address is in the10.20.0.x
range—then just change192.168.56.10
to10.20.0.2
.