3

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).

2
  • Use bridged mode, first. May 26, 2013 at 15:18
  • Just my two cents, consider using a better virtualization technology if you want server consolidation. Xen or KVM are your friends. Apr 22, 2014 at 4:57

2 Answers 2

3

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

2

Using NAT you cannot pass-through the visitor's IP address to the webserver. All the connections to the webserver will be from the host running Virtual Box.

To be able to do that you will need on the host operating system where VirtualBox runs to setup an HAproxy instance, or nginx in order to add a custom HTTP header with the real source IP address of the visitor on each HTTP request.

Then that header is parsed on the backend web server and is used for the access/error logs and statistics of the web server.

If your backend webserver is Apache you will need the following module to be able to parse the custom HTTP header. http://stderr.net/apache/rpaf/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .