0

I have my development environment on my local system with XAMPP(Windows 7). During dev. work I use my system's IP address (i.e 192.168.XX.XXX of Internal Network) when I am inside the network, it works fine to access the localhost by http://192.168.XX.XXX But when I am outside of the network and try to access my localhost using the same IP it doesn't work. As the urls along with the IP have been stored in DB, I want to access using same IP but that should point to localhost even if I am outside of the internal network.

How can it be possible ? Thanks in Advance ?

Subharanjan
  • 59
  • 2
  • 2
  • 8
  • It depends on what you are trying to access on that IP. If it is ssh then you can reassign the default port from 22 to something like 4560 and do port forwarding on the router. Or ultimate solution would be to use VPN. – Danila Ladner Apr 25 '13 at 19:06
  • Get a global IPv4 address, or better yet IPv6. – Michael Hampton Apr 25 '13 at 19:10
  • let me clarify... I have apche running on localhost. So I can get the root by typing http://localhost OR http://127.0.0.1 OR http://192.168.11.74 Now, to be accessible by others inside the network, I setup WordPress projects with http://192.168.11.74/wpproject/ , But when I come to home(outside network) with the laptop I can't access the same root with http://192.168.11.74/ . Why I need it is, I can search and replace the urls inside DB each time I come outside of network and work. – Subharanjan Apr 25 '13 at 19:23
  • Can we achieve this by Hosts file change or Virtual Hosts etc ?? Just curious – Subharanjan Apr 25 '13 at 19:26
  • If your database has your IP addresses in it then you are doing something broken. Setup DNS or a hosts file. Create a name that points the IP. – Zoredache Apr 25 '13 at 19:26
  • Is there any particular reason you can't just use the http://localhost while you're at home? – David V Apr 25 '13 at 19:28
  • I have my project running on this machine that is horribly dependent on the IP address (it's scattered among several config files and mostly in databases too) If IP address changes then the software won't work anymore. To make it work I have to search and replace the IP with localhost or 127.0.0.1 in all config files and DB which is cumbersome. Need a easy work around. – Subharanjan Apr 25 '13 at 19:34
  • I want to do something similar to adding an entry to the hosts file, except I want to map an IP to another IP. Is there any way to do this? For example, in the hosts file, localhost is mapped to 127.0.0.1... I need to map something like 192.168.11.74 to 127.0.0.1 – Subharanjan Apr 25 '13 at 19:36
  • 1
    No, you can't do that. – woodsbw Apr 25 '13 at 21:19
  • I think third party services like https://ngrok.com/ are just for that – cancerbero Sep 26 '17 at 22:25

2 Answers2

1

Set up your router's NAT (the router where your webserver is) to forward your HTTP port to the local IP 192.168.11.74. Then, when you're at home, open a browser, type in your WAN IP and the corresponding port number (ex. 74.232.100.4:80) and you should be able to access your intranet.

Brandon
  • 61
  • 1
  • 10
  • I want to do something similar to adding an entry to the hosts file, except I want to map an IP to another IP. Is there any way to do this? For example, in the hosts file, localhost is mapped to 127.0.0.1... I need to map something like 192.168.11.74 to 127.0.0.1 – Subharanjan Apr 25 '13 at 19:37
  • That's doable, but you must realize that the hosts file will only affect the address translation on that computer alone. If you want to access your webserver on a local IP externally, the most efficient method is adding a NAT rule to your router. – Brandon Apr 25 '13 at 20:06
  • " NAT rule to your router " Is this something I can do on my local system alone ? Note: I run my Apache server(XAMPP) on local sytem. – Subharanjan Apr 26 '13 at 04:59
  • Yes. You can do this on your local router behind which your Apache server sits. Open a command prompt and type in "ipconfig" without quotes. You should see a corresponding address to your default gateway. That is most likely your router. The rest of the setup completely relies on the make and model of your router, but assuming you have your standard retail router with a web-based user interface, you should be able to enter that number (starting with 192.168.11.) into your browser's address bar and you should be able to log right in.From here you should be able to find a NAT table you can edit. – Brandon May 08 '13 at 14:35
0

The short answer: No, you cannot do that. At least, there isn't an "easy workaround" (other than the app being written correctly in the first place.)

Long answer: You are using an IP address, that IP address is assigned based on the NETWORK that you are on....it isn't something that comes from, or is assigned by, your machine. The hosts file won't work, as it only works with NAMES, not IP to IP mappings.

You COULD make this work, but it would require a virtual router on the machine, and virtual network interface on your machine, and a bunch of static routes. Then, all of this would have to be torn out while you are at work. Trust me, swapping out config files with a script on the application level will be easier.

woodsbw
  • 569
  • 2
  • 7
  • 18