Apache behind NAT translation -client ip not right

Alles, was den Apache betrifft, kann hier besprochen werden.

Apache behind NAT translation -client ip not right

Postby trueman1 » 25. April 2018 07:34

My Apache server is behind a NAT translation(centOS).
The problem I'm having is that I want to see who is actually making the request instead of my private ip address.
The php command for viewing client IP shows local ip instead od client IP. why???? How to solve the issue??
trueman1
 
Posts: 3
Joined: 25. April 2018 07:11
XAMPP version: 2
Operating System: centos

Re: Apache behind NAT translation -client ip not right

Postby Nobbie » 25. April 2018 12:53

Some example PHP code?
Nobbie
 
Posts: 10545
Joined: 09. March 2008 13:04

Re: Apache behind NAT translation -client ip not right

Postby trueman1 » 26. April 2018 10:35

tested these commands
$_SERVER['REMOTE_ADDR'];$_SERVER['HTTP_CLIENT_IP']; getenv('REMOTE_ADDR'); etc
but i got local ip of LAN.
trueman1
 
Posts: 3
Joined: 25. April 2018 07:11
XAMPP version: 2
Operating System: centos

Re: Apache behind NAT translation -client ip not right

Postby Nobbie » 26. April 2018 11:12

You should explain better, its hard to follow.

Where is your client running (in which network?), which IP is the clients IP? What is your test script (please show source code)? What is the output? Can you provide a link to your server, so that i can run the test PHP from here?
Nobbie
 
Posts: 10545
Joined: 09. March 2008 13:04

Re: Apache behind NAT translation -client ip not right

Postby Altrea » 26. April 2018 12:04

But you are knowing what you are doing?
The purpose of NAT is to replace an IP address either in request, response or both headers...
So it is not possible for the HTTP protocol or any serverside running programming language to get the real request IP.
The only way i can think of are client side languages like JavaScript or Java Applets to read out the IP address and transmit it by help of form data.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9336
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Apache behind NAT translation -client ip not right

Postby trueman1 » 27. April 2018 06:45

The domain www.mynewsite.com pointed to router(public IP is 14.x.x.x) and application is running in a mechine IP is 10.10.100.7(private network.this network having a lot of mechines).
Application softwares are php,mysql,apache and centOS.
when one from any where go to www.mynewsite.com and submit a form ,i want to get the IP of the visiter to keep it in database.
But application(PHP code) gives the IP 10.10.50.3 to All visiters.What the issue??
Thanks in advance..
trueman1
 
Posts: 3
Joined: 25. April 2018 07:11
XAMPP version: 2
Operating System: centos

Re: Apache behind NAT translation -client ip not right

Postby Altrea » 27. April 2018 07:27

Read my post again. That is the nature of NAT.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9336
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64

Re: Apache behind NAT translation -client ip not right

Postby Nobbie » 27. April 2018 11:02

Altrea wrote:Read my post again. That is the nature of NAT.


No. The client IP *should* be correct and not translated. If have a NAS running as well and connected via a Dynamic DNS, when i call phpinfo() from a PC somewhere in the WWW, the REMOTE_ADDR is correctly shown up.

But application(PHP code) gives the IP 10.10.50.3 to All visiters.What the issue??


As long as i cannot run a test, I cannot say anything. Please, establish a small PHP script which only includes a call to phpinfo() and provide a valid link to your Server/NAS, which runs the Apache Server. I want to see what happens.
Nobbie
 
Posts: 10545
Joined: 09. March 2008 13:04

Re: Apache behind NAT translation -client ip not right

Postby Altrea » 27. April 2018 13:03

Sorry, you are absolutely correct :idea:
$_SERVER['REMOTE_ADDR'] should of course contain the correct client ip if you are only doing NAT and no proxyfication.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 9336
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 10 Pro x64


Return to Apache

Who is online

Users browsing this forum: No registered users and 5 guests