9

I have setup a subdomain sub.example.com in the DNS-records of my domainname-provider that I linked to my external IP. I then forwarded port 80 in the router (Sitecom Broadband Router 54G) to the IP of my computer in the network. Now I can access the Apache server on my computer from outside using the subdomain.

But from inside the network, I can't access the subdomain. I guess this has to do wih the fact that I simply can't access the external IP from within the network, the router seems to block these requests.

I don't want to use the internal IP, since using the subdomain in all cases is easier to setup (I use my laptop inside and outside the network). I also don't want to change the hosts file, since this wouldn't work both inside and outside the network, I guess.

Any way to fix this, or should I get a new router?

1
  • 3
    Accessing a LAN server from inside using an external IP address requires a router that supports nat hairpinning. Not all routers support this.
    – DavidPostill
    Mar 2, 2016 at 15:52

2 Answers 2

8

Most SOHO routers don't support hairpin NAT (AKA NAT loopback), which is accessing an internal machine via the external IP, from inside the same LAN.

You need a better router. If your router supports the 3rd party DD-WRT firmware, you may want to try that. To configure hairpin NAT in DD-WRT, you can consult other SU questions such as:

DD-WRT: How to allow port forwarding to apply to requests originating from inside the LAN?

4

There already is an answer explaining why it won't work, but there are 2 solutions. The other answer only mentions one, so this answer is to provide you with an alternative.

Indeed, what you want requires NAT hairpinning, and it appears that your router does not support this.

Alternatively to replacing the router for one that supports it, you can setup a DNS server in your network. This could be on a server, but you can also download a DNS server program and run it locally. In your router, for DNS server, you configure the IP adress of the computer/server that runs this DNS server and in the DNS server you add a manual entry for your FQDN (domain) in your example, that would be sub.example.com and make it point to the internal ip address.

Everyone that uses this new DNS server will be able to access the site again, but you will not be able to detect problems with the online part. This is however how it's done in the real world with companies. They have an inhouse server running a DNS server and the domain they use for internal stuff is configured on the DNS server.

3
  • But what if the internal service runs on a different port? For example, I have a web app that is exposed externally on port 443, but internally it is on a port 4433. If I set up DNS so it automatically points requests to external domain into requests to local IPs, then the URLs won't work because of the port differences. So, I guess there's no real workaround to this issue - only changing the local port to also be 443 or to get a router with NAT loopback. Sep 12, 2019 at 14:05
  • @JustAMartin For internal urls, you must append :4433 to the url for it to work. For example: example.com:4433/mypage.html
    – LPChip
    Sep 12, 2019 at 14:12
  • Yes, that works, however that's the inconvenience I wanted to avoid - to tell the port number to the intranet users who want to access the app both externally and internally. I guess it's time for the internal network upgrade - to get a system that supports NAT hairpinning. Sep 12, 2019 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .