11

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.

2
  • What is the guest OS? Typically you need to set the network settings within the world of the guest OS to do what you are attempting to do. Feb 3, 2015 at 21:32
  • 1
    Guest is CentOS 6.5 Feb 3, 2015 at 21:48

1 Answer 1

12

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:

enter image description here

Note that I have the following set in the “Adapter” panel:

  • IPv4 Address: 192.168.56.1
  • IPv4 Network Mask: 255.255.255.0
  • IPv6 Address: [blank]
  • IPv6 Network Mask: 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 the 10.20.0.x range, then change the IPv4 address of the adapter from 192.168.56.1 to 10.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:

enter image description 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:

enter image description 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:

sudo ifconfig eth1 192.168.56.10 netmask 255.255.255.0 up

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 of 192.168.56.2 to 192.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 to 10.20.0.2—assuming your address is in the 10.20.0.x range—then just change 192.168.56.10 to 10.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 use nano:

sudo nano /etc/network/interfaces

The contents of that file would look something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

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:

# The local hostmachine access interface.
auto eth1
iface eth1 inet static
address 192.168.56.10
netmask 255.255.255.0

Note how eth1 is set to static and has address and netmask settings. Once added, just save the file. And now on reboot you machine will always know to assign eth1 and if you want to reach that guest OS from the host OS, you would just need to go to 192.168.56.10. And if you wanted to set the address to 10.20.0.2—assuming your address is in the 10.20.0.x range—then just change 192.168.56.10 to 10.20.0.2.

7

Not the answer you're looking for? Browse other questions tagged or ask your own question.