How to install Host-Only networking in OS X

Discussions related to using VirtualBox on Mac OS X hosts.
Locked
boxcarmib
Posts: 3
Joined: 10. Sep 2010, 06:41
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Debian

How to install Host-Only networking in OS X

Post by boxcarmib »

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

mymac:~$ ifconfig vboxnet0
My system responds with:

Code: Select all

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

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

#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

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

192.168.1.101    machine.dev
that allows me to SSH to my (Debian) guest by just typing:

Code: Select all

ssh -Yl root machine.dev
etc.


Hope some of you find this post useful.
Last edited by boxcarmib on 14. Sep 2010, 23:02, edited 1 time in total.
boxcarmib
Posts: 3
Joined: 10. Sep 2010, 06:41
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Debian

Re: How to install Host-Only networking in OS X

Post by boxcarmib »

There were errors in my first post, it has now been edited.
Last edited by boxcarmib on 14. Sep 2010, 23:03, edited 1 time in total.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: How to install Host-Only networking in OS X

Post by Sasquatch »

You know, you can edit your posts. Makes it a lot better to understand things. Now you have to scroll back and forth. Please do so to avoid confusions.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
boxcarmib
Posts: 3
Joined: 10. Sep 2010, 06:41
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Debian

Re: How to install Host-Only networking in OS X

Post by boxcarmib »

You're right. apologies for being a witless nubie. :)
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: How to install Host-Only networking in OS X

Post by Sasquatch »

I had a few more things that I saw, but now that you have the proper fixes in it, I will read it again later (going to bed now, it's past 23:00 atm) and give you more feedback. Unless someone else beats me to it ;).
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
simonsez112
Posts: 3
Joined: 5. Dec 2010, 20:55
Primary OS: Mac OS X other
VBox Version: OSE Debian
Guest OSses: Ubuntu

Re: How to install Host-Only networking in OS X

Post by simonsez112 »

I just wanted to say THANK YOU - I spent the last few hours figuring out how to get this working and this worked like a charm for me!

-s
Ball
Posts: 9
Joined: 25. May 2011, 12:10
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: bt5

Re: How to install Host-Only networking in OS X

Post by Ball »

How do I get vboxnet0 to show up in System Preferences? I can do this in Desktop Parallels 5+6. This is essential for using the VM as a host in Snow Leopard (and probably all other Mac OS versions).
rollyf
Posts: 1
Joined: 27. Jul 2011, 19:27
Primary OS: Mac OS X Leopard
VBox Version: OSE other
Guest OSses: Debian

Re: How to install Host-Only networking in OS X

Post by rollyf »

Thanks, mate. I was pulling my hair in trying to make this to work and I found your article which solved my problem. You saved my hair.
karatedog
Posts: 8
Joined: 2. Apr 2009, 22:10
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Ubuntu 9.10, Windows XP, Windows 7, Debian 5 server 64-bit

Re: How to install Host-Only networking in OS X

Post by karatedog »

Thanks, I have successfully set up a working network.
Next problems to solve:

- Ubuntu 11.04 Host, but it could be OS X as well, using the wireless lan (wlan0 interface)
- Windows XP guest
- CheckPoint Endpoint VPN client in Windows XP guest (because it only works there), and soft-token authentication. The authentication works fine, company network, mail server are accessible from the Windows XP guest.

Now I'd like to somehow use that built-up VPN tunnel from the host, so I see the company network from the host.
I'm not a routing/bridging/tunneling ninja, especially not on Windows, can anyone give me a hint on how to continue? I figured out that I need to route certain traffic to the Host-only network interface in the Host, and those packets will appear on the guest side. From then on I was unable to route that traffic to the VPN tunnel in Windows.

Thanks.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: How to install Host-Only networking in OS X

Post by Sasquatch »

Karatedog, create a new topic instead. Then we can help you. See the Forum Posting Guide for where it's best suited.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
afarrell
Posts: 1
Joined: 4. Jul 2014, 06:31

Re: How to install Host-Only networking in OS X

Post by afarrell »

In /etc/network/interfaces, where did you get the value for the "address" field in eth0 to enter here?:

iface eth0 inet static
address 192.168.1.98
netmask 255.255.255.0
gateway 192.168.1.1
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: How to install Host-Only networking in OS X

Post by mpack »

This thread is ancient, and discusses issues with long obsolete VBox versions. Locking it.
Locked