You are not logged in.

#1 2012-03-31 21:24:50

andrej
Member
Registered: 2012-03-31
Posts: 21

[SOLVED] NAT + Host-only network in VirtualBox

I'm building an Arch based portable web development environment in VirtualBox and I can't get NAT and Host-only network interfaces to cooperate.

My configuration is as follows:

[root@devbox ~]# cat /etc/network.d/main 
CONNECTION='ethernet'
DESCRIPTION='A basic dhcp ethernet connection using iproute'
INTERFACE='eth0'
IP='dhcp
[root@devbox ~]# cat /etc/network.d/vbox
CONNECTION='ethernet'
DESCRIPTION='VirtualBox Host-only network'
INTERFACE='eth1'
IP='static'
ADDR='10.10.0.3'
GATEWAY='10.10.0.1'
DNS=('10.10.0.1')

In VirtualBox I have 2 active network adapters:
*Adapter1 = NAT
*Adapter2 = Host-only adapter (vboxnet0: IPv4 Address: 10.10.0.1, mask: 255.255.255.0, DHCP off)

Since I use netcfg I've disabled the default network daemon in rc.conf.

So, when I start the 'main' profile, the network comes up and works flawlessly.
But when I start the 'vbox' profile, the internet isn't reachable anymore - can't ping google.com, unknown host

ifconfig shows eth0 and eth1 active, as expected.

If I stop the 'vbox' profile, eth0 works again.

The 'vbox' profile is necessary for ssh-ing into the VM from the host. When 'vbox' is active, ssh-ing into the VM works as expected but is unusable because the outside isn't reachable.

Any ideas?

Last edited by andrej (2012-04-01 09:12:12)

Offline

#2 2012-03-31 21:46:20

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [SOLVED] NAT + Host-only network in VirtualBox

Check what happens to the routing table after you've enabled both interfaces ("ip route"). Could be that you're just going to have to set up some static routes (10.10.0.0/24 over eth1, all the rest over eth0 if I understand your explanation correctly).


Burninate!

Offline

#3 2012-04-01 07:18:44

andrej
Member
Registered: 2012-03-31
Posts: 21

Re: [SOLVED] NAT + Host-only network in VirtualBox

Thanks Gcool

ip route gives me this:

[root@devbox ~]# ip route
default via 10.10.0.1 dev eth1 
default via 10.0.2.2 dev eth0  metric 202 
10.0.2.0/24 dev eth0  proto kernel  scope link  src 10.0.2.15  metric 202 
10.10.0.0/24 dev eth1  proto kernel  scope link  src 10.10.0.3

I've never messed with routing before. Could you tell me how to set this up, please?

Offline

#4 2012-04-01 08:47:34

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [SOLVED] NAT + Host-only network in VirtualBox

default via 10.10.0.1 dev eth1 

That's the culprit. You basically have 2 default gateway routes.

If you only need that eth1 interface to connect to your VM from your host, try removing the "GATEWAY='10.10.0.1'" section from /etc/network.d/vbox. That should stop the creation of the unnecessary default gateway route.


Burninate!

Offline

#5 2012-04-01 09:11:43

andrej
Member
Registered: 2012-03-31
Posts: 21

Re: [SOLVED] NAT + Host-only network in VirtualBox

Thanks man, I owe you a beer smile

Also had to remove the DNS from /etc/network.d/vbox

Offline

Board footer

Powered by FluxBB