Page 1 of 1

FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 19:00
by Predatorr
Good evening,

I currently got a VM with FreeBSD 9.0 and installed Apache on it.
This works when I use port forwarding and I can reach it on my own PC.

However, when I check the IP in the access logs and the $_SERVER['REMOTE_ADDR'] value in PHP then this says 192.168.56.1 with the Host-only adapter or 10.0.2.2 with NAT as network adapter.
Is this caused by the forwarding of the port and/or how can I fix this?

When I use the bridged mode as network adapter then I will not get an IP assigned since it's a dedicated server without a router and it has got its own static IP.
Could someone push me in the right direction?

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 19:11
by Perryg
However, when I check the IP in the access logs and the $_SERVER['REMOTE_ADDR'] value in PHP then this says 192.168.56.1 with the Host-only adapter or 10.0.2.2 with NAT as network adapter.
This is as expected. What were you looking for it to say?

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 19:16
by Predatorr
The IP of the client which is requesting the web page. 84.164.242.143 for example.

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 19:24
by Perryg
Using port forwarding the guest can only see the address of the host which is doing the forwarding. If you want to track the public addresses you need to set up the guest to use public addresses.

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 19:26
by Predatorr
So I will have to use bridged mode in that case?
And then configure DHCP on the host machine and give out a 192.168.1.* IP for example?

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 20:02
by Perryg
When I use the bridged mode as network adapter then I will not get an IP assigned since it's a dedicated server without a router and it has got its own static IP.
How do you plan to get around this?

While you can set up routing in the host the guests (web server) more than likely will see the request coming from the host.

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 21:54
by Predatorr
Perryg wrote:
When I use the bridged mode as network adapter then I will not get an IP assigned since it's a dedicated server without a router and it has got its own static IP.
How do you plan to get around this?

While you can set up routing in the host the guests (web server) more than likely will see the request coming from the host.
So I basically have to do it the other way around?
FreeBSD (the webserver) as the host and a Windows Server as guest VM?

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 22:01
by Perryg
Or get another public address from your provider.

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 3. Jun 2012, 22:23
by Predatorr
Thank you for the help so far.
My last question: If my provider has given me another address, am I supposed to use `Bridged Adapter`?

Re: FreeBSD as guest with webserver, wrong IP of client?

Posted: 4. Jun 2012, 00:38
by Perryg
That depends on how your provider assigns these addresses. You would need to talk to them and maybe even need an additional NIC in the host.