Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
1  
Setup virtual box to bridge the connection, and give it a real address. –  Zoredache Apr 17 '12 at 22:58
    
@Zoredache: My LAN network doesn't allow bridge.. somehow It breaks also my host internet connection. also bridge does not provide 'port-forwarding' option –  iKid Apr 17 '12 at 23:05

1 Answer 1

up vote 1 down vote accepted

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;
    }
}
share|improve this answer
    
should I remove the port-forwarding from VB after setting this up ? –  iKid Apr 18 '12 at 6:41
    
No, if you do that the webserver won't be able to connect to your VM. For this example you should forward your VM's 80 pport to local 8080 port. –  jollyroger Apr 18 '12 at 6:47
    
Ok if I understand correctly ppl access through my ip @ port 80 ? then it forward to 8080 which will forward to VB in port 80 again ? –  iKid Apr 18 '12 at 6:51
    
This setup assumes people will access your host via example.com domain name. If you don't want to create a DNS name for yourself (somewhere on your gateway/router) change server_name line to server_name example.com default;. This will make all requests to your IP on port 80 pass to the backend. –  jollyroger Apr 18 '12 at 7:03
    
thanks, I successfully have nginx worked and I can see the access to my server through nginx access_log with correct ip. Is there anyway to do the same for error_log ? –  iKid Apr 18 '12 at 9:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.