Page 1 of 1

VirtualBox, OS X Lion, Host-Only, static DHCP and NAT

Posted: 14. Feb 2012, 10:23
by Sagot
I've managed to configure static DHCP addressing and NAT for my VMs. As I've understood from the Google it's an issue and there's no universal solution of that.
The one I've found is about using ipfw, which is deprecated in Lion. After some reading (pf tutorial, man pf, man pf.config) I've managed to resolve it (for my case).

What I want:
1. I can start any number of VMs with different MAC-addresses;
2. On the host I can configure IP address for special VMs using its MAC-address (static DHCP);
3. VM can see external network via NAT;
4. Host can connect to VMs using their IPs;
5. VMs can connect to each other using their IPs.

Solution:
1. in VirtualBox disable DHCP-server;
2. for each VM set network adapter to Host-only;
3. install (via brew) dnsmasq;
4. in dnsmasq conf-file (/usr/local/etc/dnsmasq.conf) configure DHCP-settings;
* interface to listen to (vmboxnet0);
* IP-range for dynamic IP-addresses;
* static IPs for particular MAC-addresses;
5. configure dnsmasq to start as daemon;
6. enable port forwarding

Code: Select all

sudo sysctl -w net.inet.ip.forwarding=1
7. in /etc/pf.conf add line after nat-anchor "com.apple/*"

Code: Select all

nat on { en0 en1 } from 192.168.56.0/24 to any -> { (en0) (en1) }
8. save;
9. load rules into pf

Code: Select all

pfctl -F all -f /etc/pf.conf
10. enable pf with command

Code: Select all

pfctl -e
en0 - ethernet interface
en1 - WiFi interface
192.168.56.0/24 - internal virtual network for VMs
It seems the rule won't work if both en0 and en1 are active.

I home my experience will help someone to resolve his/her issues.

Also I'll be glad for any additions. I suppose my configuration is not optimal and is needed to be improved.

UPDATE: added step about enabling port forwarding.