How to get VirtualBox NAT working with actual client IP's?

I'm using Virtualbox 4.0.10 on a Debian Squeeze box. I have a Windows 7 VM that I use to host a game server. After setting up NAT and port redirection, clients can connect to the VM, but the game server shows it's getting connections from the NAT gateway IP (10.0.2.2). I need that the game server gets connections from the actual public internet client IP's, so I can set up an IP whitelist in the game server.

This Debian machine is directly connected to the internet. What can I do to make this work? Guess it's not VirtualBox problem and can solve that with a virtual network interface or so, but no idea how to do it. Guess it's not Virtualbox probmem and I can make it work with a bridge interface or so.


Solution 1:

Set the network adapter into bridged mode.

in VirtualBox go to the Windows 7 settings, select network then you should see that the Adaptor is set to NAT. Change this to Bridged adapter.

Solution 2:

This is possible without bridge mode! For some strange reason, the default NAT mode in VirtualBox rewrites original source.

What you want is to switch NAT to transparent mode with

VBoxManage modifyvm <your-vm name> --nataliasmode1 proxyonly

More info here

  • http://www.virtualbox.org/manual/ch09.html#nat-adv-alias
  • http://www.virtualbox.org/manual/ch08.html#idp18407536
  • https://www.virtualbox.org/ticket/6524
  • https://www.virtualbox.org/ticket/7608

Solution 3:

There may not be a way to change that behavior in VirtualBox.

Any one of the following could resolve your issue:

  1. Easiest and best approach: Just set up your whitelist using iptables on the Debian box instead of managing your whitelist on the VM.
  2. Use a different hypervisor that has more options to configure virtual networking and NAT behavior.
  3. Put the Debian box behind a physical firewall or router, configure your NAT rules there, and bridge the VM to your physical network adapter.
  4. Get a second public IP address from your ISP. Assign that IP address to the virtual machine and bridge it to your physical network adapter.