MacOS – How to set up a private virtual LAN for the laptop and its guest VMs

macosNetworkunixvirtualbox

I have two VirtualBox guest VMs running Linux under a MacOS X host.

I'm using bridged networking mode but I am not in control of the DHCP server and can not give my host+guests static IPs. Any time a DHCP lease expires, or I join a different network, I have to deal with my VM IPs changing, and consequently change all my firewall rules and /etc/hosts entries, etc. which is a pain to say the least.

So I want to set up a virtual LAN on my laptop like 10.20.30.0/24. Then make my host OS (the laptop) be .1, and the guest VMs be .2 and .3. The VMs need to be able to access the Internet through the host's connection. Sometimes that would be out the wired interface, other times out the AirPort. It would be ideal if, when the host's internet connection changes from wired to wireless, guest internet access is not interrupted.

Can I do this on OS X? What commands do I run, sysctls to set, etc.

Best Answer

I haven't tried it on an OS X host but "Host-only networking" does what you want. See: http://www.virtualbox.org/manual/ch06.html

Related Question