virtualbox +vboxnet – host only network

How to install Host-Only networking in OS X

Postby boxcarmib » 10. Sep 2010, 08:08

For the benefit of those of you like me have been banging your head against the wall trying to get Host-Only networking working on the Mac, here’s what works for a Debian guest… although I believe the insights will be helpful to anyone who’s struggling with this problem.
If like me, you’re trying to put together a development environment on a laptop and you want to be able to access your guest even when wifi or an internet connection is not available or not working, then you need to use Host-Only networking.

The following „tutorial” assumes you have already installed your guest (Debian OS) but that is is currently not running and virtualbox is not running.

STEP 1:
Launch Virtualbox

STEP 2:
Go to VirtualBox/Preferences in the menu bar. A window entitled „Virtual Box – General” will appear.
(It’s important to note that the VirtualBox/Preferences options is only available when the main Virtual Box „Oracle VM VirtualBox” window is foremost on your desktop. If you have a guest machine as the front window, then the preferences panel you’ll be selecting is for the guest OS and not the preferences for the overall program).

STEP 3:
Click on the Network icon (top far right) of the VirtualBox – General window. In the default state a single line will appear as vboxnet0 network.

STEP 4:
Click on the screwdriver icon (that’s the third icon down on the list). Either leave the value of the IPV4 address as it is, or change it to suit your needs (I changed it to 192.168.100.100). The important thing is to choose an IP address that does NOT conflict with any existing subnet you are running. If for example, your Bridged networking IP is 192.168.1.20, then you don’t want your vboxnet0 value to be anything in the range 192.168.1.x. I have chosen 100 as my x value because I have not other subnet running on my machine with 192.168.100.x values. Most of you will probably want to leave the network mask at 255.255.255.0.

STEP 5:
Click on the DHCP Server button and make sure the Enable Server button is unclicked.
(Although the DHCP Server may have its uses, I can’t think of any particularly good reason to have it. If you want the DHCP server you can always enable it later on)

STEP 5:
Click OK. This will save your changes.

STEP 6:
You can verify that you’ve accomplished what you set out to do by opening the Mac Terminal program and typing in the following:

Code: Select all   Expand view
mymac:~$ ifconfig vboxnet0

My system responds with:

Code: Select all   Expand view
boxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 192.168.100.100 netmask 0xffffff00 broadcast 192.168.1.255
ether 0a:00:27:00:00:00

This tells me that VB has actually accomplished what the documentation kinda hints that it’s supposed to do… i.e. create a virtual network adapter for you to channel OS X host data through to reach your guest OS.
NOTE: You’re NOT going to find this interface showing up in your Network System Preferences panel or anywhere else, so don’t be concerned if you don’t see it.
The IP address you select for vboxnet0 will serve as the base IP address for any guest OS Host-only network interface you intend to configure. I chose 192.168.100.100 because I want my Host-Only interface in the guest OS to be 192.168.100.101 It APPEARS that the IP interface address in the guest OS need to be consecutive and at LEAST „higher” than the IP address value you select for vboxnet0 in Step 4.

STEP 7:
From the Oracle VM VirtualBox window, select the Guest OS you wish to configure with Host-Only networking (in my case I only have a single Guest OS so it is selected by default) and click on the Settings icon at the top of the window.

STEP 8:
When the Settings window appears click on the Network icon. You will be provided with four buttons named Adapter 1 through Adapter 4 and in the default configuration Adapter 1 is already enabled and and attached to a Bridged Adapter. You can/should leave that as it is… because it will continue to allow your Guest OS to talk through your Mac OS to the Internet, which as long as you’ve got an internet connection is probably a worthwhile option.

STEP 9:
Click on Adapter 2 and click the Enable Network Adapter to enable it and select Host-only Adapter for what it is attached to. You will see that vboxnet0 is already provided and that there is not other option, and at this time you can probably safely ignore the Advanced tab. You can now click the OK to save your changes.

IMPORTANT NOTE: The vboxnet0 that is selected in the Adapter 2 settings is somewhat misleading, because it refers to the IP address that the Mac OS will be using to communicate with your Guest OS and it is NOT the address that your Guest OS interface will have. Also it’s valuable to know that vboxnet0 is not the name of your Guest OS interface either. In fact, in a Debian Guest OS, Adapter 1 has the interface name eth0, Adapter 2 the name eth1, Adapter 3, the name eth2 and Adapter 4, the name eth3. (more on this later).

STEP 10:
Start you (Debian) Guest OS and log in or sudo or whatever as root or whatever other user gives you sufficient authority to edit /etc/network/interfaces.

STEP 11:
Edit your /etc/network/interfaces file with your favorite editor.
The important lines of the /etc/network/interfaces file looks like this

Code: Select all   Expand view
auto lo
iface lo inet loopback

#The primary network interface
allow-hotplug eth0
iface eth0 dhcp

I changed my /etc/network/interfaces file to look like this (please note the comments. you don’t need to include them, but I’m trying to explain what’s going on….

Code: Select all   Expand view
#leave the local loopback interface as is
auto lo
iface lo inet loopback

#The primary network interface
allow-hotplug eth0
#As mentioned previously eth0 is Adapter 1 in the Virtual Box Guest OS configuration window
#I'm not a big fan of DHCP so I've changed the specification to a static configuration
#The important thing to keep in mind is that Adapter 1 (eth0) DOES require a gateway
#and that this address is the one that your Guest OS ultimately needs to access in order
#to access the internet
iface eth0 inet static
address 192.168.1.98
netmask 255.255.255.0
gateway 192.168.1.1

#the allow-hotplug command just tells Debian to do an "ifup" on this interface at boot time
#so you don't have to manually enable it.
allow-hotplug eth1
#once again I have select a static configuration. (If you were to enable the Virtual Box DHCP server
#then you could replace the following lines with a single "iface eth1 dhcp"
#as you can see, the IP address I have chosen for
#eth1 (Adapter 2) is one HIGHER than the value I selected for vboxnet0 in the
#VirtualBox main preferences network setting (STEPS 2-4)
#also not that you do NOT want to specify a gateway settings as this
#Host-only interface is only talking to the Mac OS or other Guest OS's you have installed.
#It doesn't need a gateway, because it's not going anywhere.
iface eth1 inet static
address 192.168.100.101
netmask 255.255.255.0

STEP 12:
Save your changes to /etc/network/interfaces

STEP 13:
restart networking, or ifdown and ifup as you like. I’m lazy. I just do a

Code: Select all   Expand view
shutdown -r now

to reboot the guest OS.

STEP 14:
REJOICE. you’re all done.
open your terminal window and ping your guest OS. If you installed openssh-server on your guestOS you can ssh to it using the IP address in your /etc/network/interfaces file and NOT the value you set for vboxnet0.
You can always edit your /etc/hosts file on the Mac and add a line to bind a name to your Guest OS address such as:

Code: Select all   Expand view
192.168.1.101    machine.dev

that allows me to SSH to my (Debian) guest by just typing:

Code: Select all   Expand view
ssh -Yl root machine.dev

etc.

Hope some of you find this post useful.

Rafath Khan

Tu powinien być pean na moją cześć, jaki to wspaniały jestem i jakimi niezwykłymi problemami się zajmuję, ale prawda jest taka, że jak każdy człowiek - mam swoje wady i może jakieś zalety. Są momenty, kiedy mam odpowiednią ilość zasobów psychoenergetycznych i mogę przenosić góry, a są niestety i takie momenty, kiedy mi się nawet z łóżka wstać nie chce... nie może tak źle nie jest, ale chętnie bym sobie pospał dłużej... Niemniej jednak, gdy uda się pokonać siebie - satysfakcja jest, ale potem przychodzą kolejne rzeczy, z którymi trzeba się zmierzyć... a na nie, niestety, energii może nie starczyć i tu właśnie wkracza tzw samodyscyplina - powinieneś usiąść i zrobić to coś, a nie siedzieć na kanapie i zajadać się słodyczami i oglądać jakiś nieciekawy serial czy film dla spalenia swojej najważniejszej waluty świata... czasu, którego nie da się odzyskać. I właśnie o tej samodyscyplinie traktować będę na tym blogu + kilka innych tematów, które są mi potrzebne do pracy

Może Ci się również spodoba