Linux – Configure VirtualBox webserver to see visitors IP address

centoslinuxnat;PHPvirtualbox

I finally managed to move my server to VirtualBox virtual machine.

VM is running in NAT mode. I have forwarded necessary ports, including the port 80 which I first fowarded with iptables to port 8888, and then forwarded via VirtualBox to port 80 on guest OS.

-A PREROUTING -i p10p1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8888

Everything works great! Except… I can't see website visitor IP addresses from PHPs $_SERVER['REMOTE_ADDR']. I only see 1 IP address, which is the host's NAT address, I assume.

How do I configure my system (host OS and VirtualBox) to be able to run webserver and see visitor's IP addresses?

My host is directly connected to Internet via 1 fixed IP address. Getting another IP for guest's bridged connection is not an option (it's already a pretty expensive internet connection).

Best Answer

Please try a solution I've found in virtualbox forum, it works for me!!!

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 details can be found from here:

https://forums.virtualbox.org/viewtopic.php?f=7&t=43500#p260181