When I go to http://www.whatismyip.com/ I get an IP address of 203.39.136.200 but if I use php/apache I get:
HTTP_CLIENT_IP = ""
HTTP_FORWARDED_FOR = ""
REMOTE_ADDR = 10.15.60.84 //IP of my machine
We are introducing geo-sensitive content into one of our sites and have the necessary lookup Web Services ready to go but as you can imagine using the local IP of the machine (10.15.60.84) produces no results so I need to work out a way to retrieve 203.39.136.200.
Cheers
Rob
If you are accessing the server from the local network then you will get the local address, even if you access the server using an address bound to an external interface. You can get around this by adding routing rules to your default gateway to route packets to the remote side of the Internet link your company uses, but this will cause extra traffic on the link since the packets will now have to go across it to get outside and then back in again.
Related
I want to make a php application and it must host in a computer and open from many branches of my schools using web.
I installed XAMPP on my pc server, and if i try to open the application in the same LAN network it works, but if i change the network it is not working.
The browser say that ip 192.168.1.22 take large time to load and not open.
how can i config that problem please
You need to set up a static IP on your machine, then set your router to forward ports so that all requests that come to your router on a particular port would be forwarded to your machine. This should do for testing purposes, but if you want to host a website for example you will need to get a permanent static IP for your router, this usually costs money from your ISP(internet service provider).
192.168.1.22 is your local IP address, you cannot access it from a different network. You can get your external IP address for example using whatismyip.com. Also, if you are behind a router, you have to open and forward the port which is used by your web server to your machine.
So this is the situation: I have a bunch of Arduinos and Raspberry Pis along with an ubuntu server on a local network. The arduinos and pis communicate with that local server routinely using PHP GET & POST requests.
Now this local server sometimes "fetches" something from a remote server in the cloud (also using PHP GETs) to respond to local requests from Arduinos and Pis.
Now here's the problem: The local server has no issues communicating with the remote server by GETs, but what if I want the server in the cloud to send a GET to the local server?
This part is kind of confusing to me as the local server is on a regular LAN and connects to the internet via a router through a local commercial ISP that issues dynamic IPs.
How can I send PHP GETs from an "online" server to a local server?
Please note that both servers are running Apache/PHP/MySQL on Ubuntu 14.04.
Thanks a ton in advance!
You will need two steps to accomplish that.
step 1 - make router forward external requests to LAN server
step 2 - make external server know the current dynamic WAN ip
step 1:
The router has to be configured to forward WAN requests to your LAN server. Assuming you use a normal home router, you typically point your browser towards the router ip and login on the router. Now you have to find where to configure forwarding (unfortunately naming of this feature varies from router to router).
While you typically can define an "exposed host" where just all external requests go to, you are better of in terms of security if you just forward specific ports to your server. As you are going to use HTTP protocol, the standard ports here would be 80 (http) and 443 (https). So assuming you use HTTPS with default port, a typical forwarding would be:
router WAN ip, port 443 --> server LAN ip, port 443
This forwards any external request to the router on port 443 to your internal server on port 443.
Now your server should be able to receive those requests, but you still would need to know your router's current dynamic WAN ip.
step 2:
As your router's WAN ip changes from time to time, you need to somehow announce that ip to your external server.
One easy way of doing is by using an external service which will provide you with a URL, which will resolve to your current ip. This is often referred to as DDNS or dynamic DNS. One quite well known DDNS provider is https://dyn.com/dns/ - but there are plenty others, and you will even find free ones. After registering with such a provider you will be given a URL which your external server can use instead of the ip.
Now you still would have to let know the DDNS provider you current dynamic WAN ip. Most easy way to do this again involves your router. Check its config for DDNS settings, typically routers do support this feature, often there are even some specific providers pre-configured. Setup your router with the credentials you got from the DDNS provider.
Now everything is set. You should be able to send requests to your internal server by using the URL you got from your DDNS provider, while your router both forwards such requests and notifies the DDNS provider about any ip changes.
A word of warning - you just exposed your local server to the internet. So you will have to treat it like any server on the internet to keep it safe, including careful configuration, installing security updates and so on.
You have to open a port on your router, and specify where the router should lead the request to. Lets assume your external ip is: 80.82.71.24, going to this ip address (fx: http://80.82.71.24) will lead to your router. Then the router decides what to do with this request, normally the request would timeoutted / refused. But on the router, if you specify that this certain request (could be: tcp/udp) (to a specified port) should point to a certain internal ip (the local server ip), then it's possible to do what you want.
But to do this, you need to read up on your router - first of all, see if you can login into it. Could you specify what router you use and if your internet connection is yours or shared (fx. campus, school, etc)?
By the way, it would not be a good idea to open up the port for the whole world, so maybe you should consider to only allow your cloud server ip to gain access to that specific port.
I have setup a PPTP VPN server on AWS and everything works perfectly. When connected to my VPN e.g. www.getip.com shows the IP address of the VPN server.
So far so good...
On the same server I installed an Apache server where I run a PHP script to get me my own IP address:
$ip = isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
Regardless if I am connected to VPN this code shows my local IP. I am not using varnish or any similar caching.
Any idea why this is the case?
- Are the $_SERVER variables saved in the PHP session?
Your help is very much appreciated.
[UPDATE]
The problem is definitely linked to the fact that the VPN server and the PHP script are on the same server. If I put the script on a different server everything works as desired. If connected to the VPN I expect to see the public IP of the server (which is the VPN server at the same time).
If you are using a VPC, then there is a problem in that the local IP will be used for all communication inside the VPC. The Public IP (EIP I assume) does not exist inside the VPC, it is assigned to the network interface and only translated in the IGW going in or out.
This means that when you check with www.getip.com you get the EIP just as expected since you pass the IGW, but inside the local net you will only see the local IP. Also, PPTP VPN works as it also passes the IGW.
Amazon suggests that you use the FDQN, even if you are on the inside and look up the external FDQN, you will get the local IP.
I do not know how this is in the Classic EC2, but I can only guess its similar.
If you absolutely need to have the public IP, you find it by using the Amazon service for this:
curl http://169.254.169.254/latest/meta-data/public-ipv4
or
curl http://169.254.169.254/latest/meta-data/local-ipv4
(See here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html)
I am wondering about a certain server setup.
Lets say I have a web server running on my local network, which is accessible using an url such as www.example.com from within and also outside the network.
I would like my PHP website to be able to determine if a request comes from within the internal LAN or from the outside. I doubt that this will be possible using the IP address as the request will look as if it is coming from a public IP address, and not the internal one 192.168.x.x. Also the public IP might change from time to time.
Would this be possible, and how could i achieve this in PHP?
If your requests comes from inside the lan then the $_SERVER['REMOTE_ADDR'] will be from a private ip address group, if if comes from outside the lan it will not.
Unless you have a poorly configured internal network, but this will probably not be the case.
look here for the correct address groups
http://en.wikipedia.org/wiki/Private_network
If your internal dns server resolves example.com to the public ip then the requests will appear to come from the public ip as well, so if this is the case you also know that the request came from inside.
As long as you know what the external NAT IP range is for your office, you should be able to do this easily be accessing the $_SERVER['REMOTE_ADDR'] value.
i have php files on my computer and i can very well access those from IIS using eighter localhost or loop-back address . But now if i want to access the same file of php from another computer not in the LAN but in a different computer on the internet what should i do? i was thinking of IP address(static) as an option but then i was not successful in finding a way to do the same .
thanks in advance....
I don't completely understand your question. Is your problem
1) You don't have a static IP? Then:
There are services as "No-IP" where you can create redirects. At their site, you can create a free domain name (which is a static IP as well) such as yourdomain.no-ip.com. Then on your server computer you can run their tool. This tool updates the IP all the time so it will be always correct.
2) You don't know how to access the server from out of the LAN because the IP of your network is the same for all computers (if you're looking from the outside)? Then:
Check your router settings, normally at: http://192.168.1.1. There you will be able to define rules how to redirect requests from the outside. For http, you should redirect requests to port 80 to the IP of the server computer (note: you can even use an other port on the server computer)!