4

In one line: is the following possible: AirPort <- Mac OS X bridge -> vbox-Host-only -> VM's

On a Mac OS X, I have VirtualBox with a virtual machine. For now I have configured 2 interfaces for my virtual machine. eth0 is normal bridge for my VM to access the Internet (when AirPort is connected). eth1 is set to host-only so I can access my VM from the host when there is no Wi-Fi/AirPort is down. So basically it's like Adapter 1 when there is Wi-Fi, Adapter 2 when there is not.

I'd like to have only one configuration to make it simpler. I thought I could just keep the Host only configuration, and on the host (Mac OS X) go to Internet sharing and select "share from AirPort" to vboxnet0 (the vb virtual interface). Only to find out that vboxnet0 dosn't show up in the interfaces list on Mac OS X preferences.

I know that on a Linux host you could install something called bridge-utils and use that to bridge the two interfaces. Is there any thing like that for Mac?

0

1 Answer 1

5

This is actually quite a simple thing to achieve, but does require a certain level of technical knowledge about networking and routing.

While it should be possibble to use some form of NAT to link the host-only networking to the rest of the network, so called 'double NAT' is frowned upon. Double NAT is when Network Address Translation occurs twice in a network adding extra overhead to the packets transmitted through the network, and should be avoided whenever possible.

What you are trying to achieve can be done very well without the need for any NAT whatsoever.

Basically, the theory is, you create a separate network which is the host only network, turn on IP forwarding on the Mac, and set up a static route on the Airport.

Let's say your normal network is 192.168.1.0/24, the Airport is on 192.168.1.1, and your Mac is on 192.168.1.200. You will need a static IP address on the Mac for this to work. The Host Only networking will already have an IP range assigned to it, and for the sake of arguement, let's say it's 10.0.0.0/24 with the Mac end on 10.0.0.1 and a VM running on 10.0.0.8.

So we want to achieve:

Airport <--------------------> Mac <----------------------> VM
192.168.1.1       192.168.1.200 |10.0.0.1             10.0.0.8

Turning on IP forwarding on the Mac is a simple enough matter. If you are on 10.5 or below take a look for the /etc/hostconfig file and find the line for IP Forwarding (I forget what it is exactly off hand) and set it to YES. On all other versions of OS/X, and indeed on 10.5 or below, you can modify /etc/sysctl.conf and add:

net.inet.ip.forwarding=1

Once you have done that you can turn forwarding on without needing a reboot by typing (as root):

sysctl -w net.inet.ip.forwarding=1

Ok, so now network packets can get from the main network to the Host Only network. But how do we tell the rest of the network about this Host Only network? At the moment only the Mac knows about it.

Well, this again is a simple matter. You don't have to tell all the hosts on the network about it, only the one common point of call for all devices - the default gateway - in this case the Airport.

Now, I haven't used an Airport, so I can't tell you where to look for the settings you need to change, but the facility will be there somewhere.

You are looking for a setting where you can specify Static Routes. It may be labelled as such, or as Routing Table or something similar. When you find it you need to set up a route for the Host Only network through your Mac. This is where having a static address on your Mac is essential. The route you need to set up will be using something like the folowing settings (from the example above. Replace the numbers with your actual IP addresses and network masks):

Network: 10.0.0.0        Network address of the Host Only network
Netmask: 255.255.255.0   Netmask of the Host Only Network
Gateway: 192.168.1.200   IP address of your Mac.

Once you have set that route up, any traffic which is destined for your Host Only network will first go to the Airport, which will respond with "Actually, you don't want to talk to me, you want to talk to 192.168.1.200" and the traffic will redirect to your Mac - which in turn will pass it on to the Host Only network.

The only other thing to be sure of is that the guest operating system running in the VM has the default gateway set for its networking. This needs to be the Mac's end of the Host Only network (10.0.0.1 in the above example).

So how does this get the VM on the internet? Well, quite simple: It in effect extends your network to include the Host Only network, and the router (Airport) takes care of the rest. It deals with the NAT, and knowing which traffic is for the main network and which is for the Host Only network.

1
  • As fas as I can tell, it's not possible to configure the routing table on Airports, as least not via the Airport utility tool Sep 30, 2011 at 19:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .