4

I have a linux server on my home network which uses Dynamic DNS provided by noip.com, and a corresponding hostname "xxxx.hopto.org". From outside of my network, say, at a coffee shop, I can use this hostname to ping or to SSH into my server. However, when I'm on my local network, I cannot ping or SSH into my server using the hostname. Running host shows that the hostname of my server resolves to its public IP, which is the same as my machine's public IP:

MacBook-Air:~ user$ host xxxx.hopto.org
xxxx.hopto.org has address 47.6.24.149
MacBook-Air:~ user$ curl ipinfo.io/ip
47.6.24.149

My background does not really include networking concepts, but I can see two potential solutions to this problem:

  1. Force the hostname to resolve to the local (static) IP address when I'm on the same network as the server.
  2. Somehow give my server it's own public IP address.

How would I do one (or both) of these? Is there another solution that would be easier/better? Thanks for your help.

1
  • I find that I can use my Dynamic DNS / Public IP from within my intranet. If it doesn't work for you, then either your ISP or your router is prohibiting loop-back (in the latter case, there may be a setting to enable it).
    – AFH
    Commented Mar 21, 2019 at 16:58

2 Answers 2

2

Firstly, as AFH mentioned in a comment, you may not need to do this at all if you simply want to access your own services using your public IP address. What you need is to enable hairpin NAT (aka NAT loopback) on your router (or get a router that supports it) so your own public IP can be reached from inside your network. This is the best solution, if your network infrastructure can handle/configure it (anything not consumer grade should be able to easily do so).

Now, if you still want to go with the DNS approach, the technical term is split-horizon DNS, where you want a different DNS response based on the source address of the request. Unfortunately, most dynamic DNS servers don't offer this, and you don't have the level of control necessary. So you end up with two possibilities:

  • Set up a custom authoritative DNS server for your domain on a publicly-reachable server (e.g. a VPS), or
  • Set up a DNS forwarder purely within your local network (much like the one built into most consumer routers)

The second approach is probably more suitable for you, but it does require you to configure your DHCP server (probably on your router) to set the DNS forwarder as the resolver.

Basically:

  1. Install dnsmasq (method depends on your server OS)
  2. Configure DHCP to point to the dnsmasq server as your resolver
  3. Configure the server that dnsmasq is installed on to resolve the address internally, e.g. /etc/hosts on the server

This approach means:

  • External clients get the public IP directly from the dynamic DNS provider
  • Internal clients hit dnsmasq
    • If they're requesting a normal public host, they get forwarded to an upstream server (e.g. ISP DNS server) as usual
    • If they're requesting one of the internal hosts you've configured, they get a local response - this only happens when the client is within your local network

Alternatively, you can use a more full-featured DNS server (like bind9) that can do split-horizon natively.

2
  • Sorry about the lack of update on this thread; I was working on implementing the solution. As it turns out, my router does not allow me to configure NAT loopback (ISP stock router) and getting a new one isn't much of an option right now. I successfully set up bind an implemented split horizon DNS. Thanks for the help!
    – amateurece
    Commented Apr 5, 2019 at 14:55
  • @EDTwardy Thanks for reporting back; I'm glad to hear it worked out! :)
    – Bob
    Commented Apr 6, 2019 at 0:52
2

You can add it to /etc/hosts file, but I would suggest a nickname so you don't mess up resolution from outside of your network. So something like the following in /etc/hosts:

#internal IP of server       #nickname
192.168.0.24                     hopto.local

Now hopto.local will resolve to the local address of the server.

For more information on /etc/hosts check out this manpage

Good luck!

You must log in to answer this question.

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