Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My setup

I have a linux server running in my basement. I currently have my router looking to that server for DNS lookup, so I can use named to spoof a bunch of domain names to point to my local server's local address, 192.168.0.111. This works great.

I also am running Apache and PHP on this server, and have forwarded port 80 on my router to this machine, so my public IP xx.xxx.x.xx is sent to the basement server.

This is a great development set up for me, because I can develop websites in my local network and pull them up on numerous devices with a *.mylocal.net address. I can also quickly share a website on my public IP with others that are outside of my network.

I have a static IP, so that makes this even easier.

The problem

Some applications need to have an absolute URL. My spoofed DNS doesn't work outside my network, and neither does my internal IP address.

I need to be able to access the sites at the same IP that they are accessed publicly, which is my public IP: xx.xxx.x.xx


For some reason, I can't access my own public IP address from within my own network.

My router's public IP is xx.xxx.x.xx, and when I hit xx.xxx.x.xx from outside my network I see exactly what I want -- my development website. But, when I hit xx.xxx.x.xx from inside my network, the connection times out.


I assume my ISP has a firewall that blocks requests from xx.xxx.x.xx to xx.xxx.x.xx where the origin and the destination are the same IP (or maybe this is impossible on any network?)

So how can I set up my network to forward the internal request to my public IP to the local IP of my basement server?

I would like to do this within the local DNS server I set up, or in my router, so the change can be applied to all devices in my network, and not just the basement server or the windows tablet/laptop, etc individually.

share|improve this question
1  
You need a router that supports 'hairpin' routing. See here: serverfault.com/questions/55611/… –  Ƭᴇcʜιᴇ007 Jun 16 at 18:12
1  
@techie007 no he doesn't. Its a way, but given that he has a local DNS server, he can redirect the internal traffic locally without harming the outside traffic. (like it usually is setup) –  LPChip Jun 16 at 18:23
    
@LPChip The way I read it OP is asking about accessing it by his external IP address specifically, not by a host name. If he had asked about accessing a local server using an external host/domain name I would have pointed him to the 20 other questions where people have asked that. ;) –  Ƭᴇcʜιᴇ007 Jun 16 at 19:10

1 Answer 1

This is normal to happen. The problem is not a firewall at ISP level, but simply your router. When you Point to an address from inside your LAN to a public IP that is inside your lan, the following happens:

Your PC -> Your Router -> Internet -> Your Router -> Your other PC.

The problem is that when a connection to the internet is then redirected back to your router, your router gets confused because the connection already is coming from your router, and as such its not working. The only way to get this working is by making the public address point to your local network from inside your network, so it never leaves your LAN.

Given that you already have your DNS server on your linux server, add your mylocal.net domain and all subdomains there, and make it point to your local ip address, 192.168.0.111, and ensure that the actual mylocal.net account does the real DNS for the outside world.

Here is an example with what will happen:

Lets assume you have configured test.mylocal.net to point to your public IP named 12.34.56.78

Now, from outside your LAN, pinging test.mylocal.net will reply to 12.34.56.78.

On your Linux DNS server, you add test.mylocal.net and point it to 192.168.0.111.

When you are inside your network, and you enter test.mylocal.net in your browser, the following happens:

  • Browser: Is a local host set with test.mylocal.net? No.
  • Browser, forward request to the Local DNS server.
  • Local DNS server is your linux DNS server: Is test.mylocal.net set? Yes, return 192.168.0.111
  • Browser now connects to your webserver and shows the page.

From outside the network:

  • Browser: Is a local host set with test.mylocal.net? No.
  • Browser, forward request to the Local DNS server.
  • Local DNS server is someone's router or DNS server.
  • Local DNS server does not have a specific entry for test.mylocal.net, Returns No.
  • Local DNS server asks internet DNS server what the IP is.
  • Internet DNS Server has received your test.mylocal.net with an update and returns the public ip.
  • Browser does request to your public ip.
  • Browser connects to your router.
  • Router forwards request to your linux server.
  • Linux server serves the webpage.
  • Browser shows the webpage.
share|improve this answer
    
this would certainly work, but I was hoping to achieve this without a public DNS record. I don't really want to register any actual public DNS to my IP. Is it possible to use my router or my linux DNS server to forward requests to my public IP from within my network to a local IP? –  tmsimont Jun 16 at 18:59
    
You could edit your local hosts file to point to your LAN IP for anything *.mylocal.net too. That'll ensure that you can view your public website by DNS instead of IP Address. –  LPChip Jun 16 at 19:06
    
that would work, too, but my issue is that I am trying to share only my public IP with someone outside of my network (no Domain Name). I then want to use that same public IP internally... I was hoping that I could use the DNS server to forward the actual IP request, but that wouldn't make a lot of sense, as it is probably not even brough into the equation if the request is for an IP and not a domain name, right? –  tmsimont Jun 16 at 19:09
    
Yeah, that will only work if your router supports hairpin routing as suggested by techie007. Do note that this is not the way things are done in real life, and if you want to learn from it, it is better to learn the right way. IF it is only one person that you want to share the same IP with, I would suggest using VPN and use the internal IP instead. –  LPChip Jun 16 at 19:11
    
ok thanks -- ya i know this is bassackwards but I just don't want to put up a public server here. i just want to be able to share a preview of a development site with a few people in another state. good call on the vpn. i'll take a look at that hairpin routing stuff –  tmsimont Jun 16 at 19:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.