You are trying to solve a problem which doesn't exist. Just use your internal IP, this will result in the packets never hitting your router (perhaps the switch on your router but not the router itself). It is better in every way to do it like this. Here are a few benefits:
- You will have access to any ports you like (not only those you've setup in your router).
- You won't waste router memory with NAT entries for services which you only use internally.
- You'll find it MUCH easier to remember the internal IP and it'll never change unless you tell it to.
- Each packet will make fewer hops and each hop will be on a switch so it'll go very fast.
- The packets won't hit the roadblock that your router creates while it dissects your packets. Even if it is a slow day on your network this'll be much faster for you.
- Your servers will see your PC as a distinct device; if you choose to use an external proxy to fix this then you'd always be seen as originating from that proxy.
- If your service supports it then it can use a whole palette of protocols which are not available to external devices. DHCP, WINS, real UDP Broadcasts... to name just a few.
- All of the additional security that goes along with being subneted.
I'm sure that there are more reasons because this is the way it should be done. Also, you can easily modify your hosts file or DNS server to give it a name without bothering with a Dynamic DNS type service.
Update
Some people have interpreted this question as asking how to make a laptop work the same inside a network as it does on another network. IMO, this is a completely different question and significantly broadens the scope of the question. I saw no mention of this being the same computer from both inside and outside the network (or of anything but an IP). Now we need to ask about things like, how you are connecting, how you are resolving host names, etc.. In the end, no one answer could solve every situation automatically.
If you are willing to run a tiny script after you connect to the other network then I can provide a simple answer which will be fairly robust.
First, create a small batch script:
ping -n 1 some.local.ip.addy
if errorlevel 1 goto :isremote
cp /Y %WINDIR%\System32\Drivers\etc\hosts.local %WINDIR%\System32\Drivers\etc\hosts
goto :eof
:isremote
cp /Y %WINDIR%\System32\Drivers\etc\hosts.remote %WINDIR%\System32\Drivers\etc\hosts
Change, some.local.ip.addy
to an actual IP on your local network. Make sure that it is something which is always available (your router IP would do nicely as long as it responds to a PING request).
Then create a local hosts file (%WINDIR%\System32\Drivers\etc\hosts.local
) and put this in it:
192.168.0.2 my-service.mynet.dyndns.org
192.168.0.3 my-service2.mynet.dyndns.org
Using your actual server IPs. This is simplified, I would add entries which specifically only work inside the network as well.
Then create a remote hosts file (%WINDIR%\System32\Drivers\etc\hosts.remote
). Leave it blank, we won't need it now but you may find use for it later.
Then setup a dyndns.org account called mynet.dyndns.org
and be sure to make it a wildcard. Of course, DynDNS is just one of hundreds of options for a dynamic DNS host.
Now, after you move between networks, just run the script and voila, everything works the same outside as it did inside and (as long as you are properly forwarding your ports and using the correct hostnames) you'll just need to use my-service.mynet.dyndns.org
or my-service2.mynet.dyndns.org
or mynet.dyndns.org:24829
to get your various services. If that service supports virtual hosts, then it'll know how to handle the my-service.
part. Your router will most likely just pass it on so you'll need to provide the port as well for those services that do not know how to handle the vhost part (of course most of those have a default port in the client so you'll be able to just enter mynet.dyndns.org
usually).
The same can be achieved without the script if you have a DNS server on your local network but if you do then you probably know how to do it already. If not, that definitely deserves it's own separate question.
Check to see if your router has a setting called NAT reflection. Without NAT reflection, the router isn't smart enough to loop the connection back into itself when you request its public IP from inside. Some routers have it on by default, but others have it disabled and many don't have the feature at all. – tlng05 – 2015-01-12T02:06:04.103
Related SU question: http://superuser.com/questions/37421/accessing-a-website-via-the-webservers-public-ip-from-a-pc-within-the-same-lan maybe even dupe.
– heavyd – 2015-01-12T06:16:10.117Also, to follow up on @user54791's question, which router are you using? – heavyd – 2015-01-12T06:16:40.620
@user54791 thats all i wanted to know, thanks – debuti – 2015-01-12T10:20:14.567