0

I'm trying to setup my host file at home in order to have access to my webserver from my outside IP.

If I go http://localhost/test I have access to my apache but If I try http://myip/test I see a 404 from my router.

The nat rule / fw is working since friends from outside can reach my server.

I tried to add the ip in my host file but that doesnt seem to work.

127.0.0.1 localhost 90.x.x.x

any clue ?

JdeBP
  • 3,970
  • 17
  • 17
Paté
  • 115
  • 1
  • 5

3 Answers3

3

You can't do that.

The hosts file is only for mapping between names and ip addresses. You cannot use it to map one ip address to another ip address. So you could do this:

127.0.0.1 www.my.computer

...and then enter http://www.my.computer/ in your web browser.

You could, in theory, give your local device the same ip address as your router's outside address, which would allow you do what you've described but really isn't a configuration I would recommend.

larsks
  • 41,276
  • 13
  • 117
  • 170
  • I'm testing a OAuthClient so google is redirecting me to my localip that's why i'm trying to do this. Maybe a local dns server ? – Paté Jun 23 '11 at 20:26
  • so the incoming request is pointed at your router's address? If so, you need to forward ports to your local address – sreimer Jun 23 '11 at 20:28
  • Or set up an alias address on your local system. But honestly, if Google is redirecting you to an ip address rather than a hostname, something else is broken -- I would suggest using the hostname that corresponds to your home ip address, and then put *that* in your local `hosts` file. – larsks Jun 23 '11 at 20:30
  • Yup, I set up a dyndns and added this to my hosts file and changed my google key for that domain and it works fine now...thx – Paté Jun 23 '11 at 20:38
0

Are you using the Apache webserver? If so, this might be a matter of fixing a directive in your httpd.conf file. I'd think that the ServerName using your IP number might be the fix.

 Servername <externipnumber>:80

 Listen <externipnumber>:80
mdpc
  • 11,698
  • 28
  • 51
  • 65
0

Your problem is not with your hosts file (though HAVING a hosts file is a problem -- There is almost always no good reason to do this!). Your problem is with your firewall, specifically something called "NAT Reflection". (Google your router/firewall and that term to see if it's possible to set up NAT reflection in your case).

A better alternative would probably be to access your internal server by a DNS hostname, and override that locally (either via a hosts file (YUCK!) or internal DNS) to point at the private IP address.

voretaq7
  • 79,345
  • 17
  • 128
  • 213