How to obtain incoming ip address from virtualbox
I setup a http server (apache) under VB and forward the port from the host using the available tool in VB. My VB network is NAT connected with the host.
However when doing this the access log of http only show the same ip address for every connection. (from 10.x.x.x which is the host ip address).
Is there anyway to see the real ip address ? I tried to setup an iptables log at the host but It does not show the data (only src,dest.ttl.. you know ..)
Your VM is behind NAT in your setup and you actually access the webserver through port forwarding, so you can't reveal clients' IPs using just virtualbox. One thing you can do is to setup somewhat lightweight webserver on your host (like nginx or lighttpd) which will listen 80 port on your network while working in reverse proxy mode to your forwarded port so your VM works like a backend in this setup. To get the client IP address this webserver should pass some additional variables like X-Real-IP
, Host
, X-Forwarded-For
(here's example virtualhost for nginx assuming your VM forwards its 80 port to local 8080):
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header X-Real-IP $remote_arrd;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
}
You can set the NAT in your VM with
vboxmanage --nataliasmode1 proxyonly
to disable aliasing and switch NAT into transparent mode.
See here for more: https://www.virtualbox.org/manual/ch09.html#nat-adv-alias