Networking – VirtualBox network configuration

bridgenat;networkingvirtualboxvirtualization

I have a CentOS 6.1 virtual machine, virtualized with VirtualBox on Windows XP. This machine hosts my local development MySQL server.

I'd like to find the correct network configuration, so that:

  • my guest machine always has the same IP, and is accessible from the host
  • my guest machine can always use the host's internet access (whether wired or wireless)

I've so far tried these different solutions:

  • NAT
    • pros: provides internet access, whichever the connection
    • cons: does not provide a working connection from the host to the guest
  • Bridge
    • pros: provides bidirectionnal network connection, provides internet connection
    • cons: works only with one adapter, I have to switch the settings each time my connection parameters change
  • Host-Only Network
    • pros: provides bidirectionnal network connection
    • cons: no internet access from the guest

Any better idea to achieve my goal?

Best Answer

Consider configuring the machine with two interfaces instead of one.

On the first you can use the Host-only Adapter so that your host can always talk directly to the guest. Then configure a second interface as either NAT or Bridged Adapter depending on your specific needs for your application.

If your guest is running as a server then you'll want Bridged. For the interface that is running in Bridged mode it will act just like a regular interface, so if you want a static IP address you'll either need to configure your network's DHCP server to assign the same IP address to the MAC address of your virtual Bridged interface, or you'll have to set up that Bridged interface statically (not recommended if your network uses DHCP unless you coordinate it with your local network admins... in which case you're better off asking for the same IP address from the DHCP server).