views:

725

answers:

5

I know it may sound stupid but anyway. Maybe there is a trick?

I just want that the local web server receives requests from my local machine but somehow sees a different IP address? Even one single that is different from the infamous 127.0.0.1 would of a great assistance.

Are there any options available?

+4  A: 

Try 127.0.0.2 or 127.0.0.3 ... or ...

Seriously, try it!

Depending on your operating system, localhost might be reachable via the entire 127.0.0.0/8 network, so even 127.42.37.254 would reach localhost (it does on my Ubuntu machine).

Joachim Sauer
When you try it, don't forget to make sure your web server is configured to listen on that IP.
Greg
How to actually "try" it? What and where should I change?
User
Either put the 127.0.0.2 (or whatever) in the URL instead of a hostname, or edit your HOSTS file so that localhost points to the IP address you want (or even better add some additional names like localhost2, localhost3, etc.)
Michael Burr
Simplest "try it" is to ping 127.0.0.2. This should get an response.Then try to access your webserver at 127.0.0.2. If it's listening on the loopback interface, then this will work. If it isn't, then explicitely tell it to listen on that IP and try again.
Joachim Sauer
@Michael: I would definitely not reissue localhost to any IP other than 127.0.0.1 - additional hostnames should be fine. Breaking the commutativity of the localhost == 127.0.0.1 assumption is going to hurt bigtime sooner rather than later.
Mihai Limbășan
That didn't work...
User
Define "that" (i.e. what you tried) and "didn't work" (i.e. what did you observe).
Joachim Sauer
+2  A: 

Are you accessing the local web server via 127.0.0.1? If so, what if you use your machine's actual IP address? The request will still end up at your local web server, but maybe it will see that as the sender instead of 127.0.0.1.

Andy
A: 

You could use your public IP address.

RossFabricant
Doesn't work when behind NAT unless your router is correctly configured.
epochwolf
I think he means the "outward-facing" IP address. If you're behind a NAT, then your eth0 IP would be 192.168.1.55 or something — different, that is, from 127.0.0.1, and thus a way to talk to your own web server without its identifying the IP as a loopback IP.
Brandon Craig Rhodes
The linked site only gives the ip address the internet can see which when behind NAT is not the address of eth0. If the answer is corrected I'll happily delete my comments.
epochwolf
+3  A: 

Or put an entry in your HOSTS file for anything you want, pointing to localhost.

le dorfier
But wouldn't the server application still see the IP as localhost/127.0.0.1?
Herms
A: 

You can always configure webserver to listen on your network ip address and then use that ip.

On the other hand if you are looking to get requests from multiple domains like a.localhost, b.localhost, and c.localhost try editing your hosts file to redirect domains to 127.0.0.1

epochwolf