Page 1 of 1

Host-only networking on Linux (Ubuntu): routing how-to?

Posted: 5. Jul 2009, 11:47
by schizzo
Virtualbox version 3
Host: Ubuntu 9.04
Guest: Backtrack 4 pre-final (Ubuntu based)
Goal: Make the ip of the Guest reachable to other machines on the LAN

I don't know much about network routing, maybe someone here knows more about it than me.
I'm using Host-only networking which creates the virtual interface vboxnet0 for me.

Host eth0 IP: 192.168.0.1
Host vboxnet0 IP: 192.168.1.1
Guest eth0 IP: 192.168.1.2

The IP 192.168.1.2 is pingable from the host and 192.168.0.1 is pingable from inside the guest. But I wasn't able to ping my router (192.168.0.23). I've played around with the commands "ip route" and "route", but it didn't help. I've RTFM but it seems I'm too stupid or I'm missing something.

Is it even possible? To make the host route packets from the virtual network 192.168.1.0/24 to machines in the network 192.168.0.0/24 and vice versa?

I know there are other possibilities than changing the routing, but using vboxnet0 would be most useful for sniffing etc. If it doesn't work I'll probably use port forwarding from the host to the virtual network.

Re: Host-only networking on Linux (Ubuntu): routing how-to?

Posted: 5. Jul 2009, 11:55
by baf
Host-only means just that only host! It's impossible to reach the rest of the net.
What you want is bridged.

Re: Host-only networking on Linux (Ubuntu): routing how-to?

Posted: 5. Jul 2009, 13:06
by anblasko
When dedicated server resellers forbid bridged networks they offer host only networking with multiple IP.

example:
first host IP: 77.178.54.43
second host IP: 77.178.54.89

guest IP: 192.168.0.50

routing traffic between second host ip and guest

Code: Select all

sudo iptables -t nat -I PREROUTING -d   77.178.54.89  -j DNAT --to 192.168.0.50
sudo iptables -t nat -I POSTROUTING -s 192.168.0.50 -j SNAT --to 77.178.54.89
Your host becomes available now from outside using 77.178.54.89

If you can use bridged network use bridge, if not use this approach.

Re: Host-only networking on Linux (Ubuntu): routing how-to?

Posted: 6. Jul 2009, 20:57
by schizzo
Thank you. I didn't get iptables working as supposed to. So I'm using bridged now.

Re: Host-only networking on Linux (Ubuntu): routing how-to?

Posted: 6. Jul 2009, 21:15
by Sasquatch
schizzo wrote:Thank you. I didn't get iptables working as supposed to. So I'm using bridged now.
IP tables isn't all that hard. This is all that's needed, where eth0 is the outgoing interface, aka internet.

Code: Select all

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
You probably forgot to enable IP forwarding. Commands need to be run as root.