OpenWrt Forum Archive

Topic: REMOTE_ADDR equals router ip address

The content of this topic has been archived on 26 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,

I'm using OpenWrt 15.05 on a TP Link router behind a cable modem set to bridge mode. Everything is working smoothly, however there's one minor annoyance.

In a PHP script on a local web server (192.168.1.10) the variable $_SERVER['REMOTE_ADDR'] does not equal the ip address of the client (e.g. 192.168.1.200) but instead is set to 192.168.1.1 (the ip address of the OpenWrt router/gateway) if I'm accessing the web server by its public domain (port forwarding from WAN to 192.168.1.10) from my local network.

As example:
http://dev.example.com/script.php -> incorrectly yields 192.168.1.1 as REMOTE_ADDR
http://192.168.1.10/script.php -> correctly yields 192.168.1.200 as REMOTE_ADDR

If I set a static hosts entry in Windows for dev.example.com:
http://dev.example.com/script.php -> correctly yields 192.168.1.200 as REMOTE_ADDR

What am I missing? The old and simple provider based router did that "right" or rather as expected. Is it a basic networking misunderstanding on my side? Is it a solvable problem in the OpenWrt config?

The router config is pretty much untouched and standard by the way.

Thanks in advance!

(Last edited by therealone on 19 Apr 2016, 11:22)

Might it be a NAT related problem? The "solution" with the Windows hosts entry makes me think that I should tell the router that dev.example.com is located locally and the correct REMOTE_ADDR might be displayed.

The AP you say is 'untouched' and that means its DHCP server is assigning addresses to STAs. It is also NATting.

Thanks for your input. Though I'm not sure how that would help with my problem. By the way the clients all have static IPs.

therealone wrote:

By the way the clients all have static IPs.

Why?

NAT is your problem.

Of course not all clients have static IPs, but the ones that have do have it for now.

What would be your suggestion to my problem? I just want the local web server to recognize my local clients IPs when accessing it over the public domain.

Max Hopper wrote:

NAT is your problem.

Disable NAT in the AP.

If you can access a local machine using the external name, then either you are redirecting the external name to an internal IP in DNSMASQ, or you are using NAT to redirect the internal connections addressed to the external IP of the router to the internal IP of the local machine.

The main disadvantage of the second method is precisely what you are describing, so I guess you are effectively using NAT. Thus, I would try disabling NAT (except for the connections from the internal network to the internet, obviously), and adding an entry in DNSMASQ.

Thanks for your valuable explanation, eduperez. In my case it was enough to simply add an entry to /etc/hosts:

dev.example.com 192.168.1.10

The discussion might have continued from here.