Setup a local bridged connection using VirtualBox

bridgeip-forwardingipfwvirtualbox

I'm trying to forward/masquarade some trafic from my guest CentOS6 (virtualbox with bridged connection). Host is OSX Lion. Here is my network layout:

  en1 - host iface
  address: 78.251.xx.yy
  alias: 10.0.2.1

  eth0 - guest iface
  address: 10.0.2.2

Now the connection between the guest and the host is working. Only if I could make the guest to talk to the internet my job would be done.

So I tried this ipfw rule (actually made the things worse – the guest can't talk to host):

ipfw add divert natd all from 10.0.2.2/32 to any via en1

I also tried to enable ip forwarding using this command:

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

Still no luck.

Best Answer

If you have a bridged connection, you do not need to forward traffic. All you need to do is configure the virtual network adapter with a valid IP address on the same subnet as the host, or let it request one via DHCP.

If you really want the host to be responsible for forwarding traffic from the guest machine and you want to configure this forwarding manually, you first need to set the virtual machine to use a "host-only" or "internal" network. Then work from there. This would be a highly unconventional approach.

The two most common options for configuring virtual machine network adapters to communicate with your LAN and/or the Internet are as follows:

  1. Workstation (virtual machine that is strictly a client): set the virtual network adapter to NAT, let the VM's operating system obtain an IP address using DHCP, and forget about it. Your VM will be able to make outbound connections to any LAN or internet IP address, but it will not accept inbound connections from other computers on your network. Note that this may be undesirable if the host has a private IP address due to "double-NAT" issues.

  2. Server or Peer (virtual machine that offers network services of any kind): bridge the virtual network adapter to a physical network card. Give the virtual machine a valid IP address on the host's subnet either via static assignment or via DHCP. Your VM will function exactly like a physical computer on the host's LAN subnet.

Of course, if a host has multiple network adapters, you also have the option of bridging the virtual adapter to a different card which could be connected to a different LAN, DMZ, etc.