How to resolve dynamic dns domain to internal ip WITHOUT NAT Loopback OR DNS change in /etc/hosts?

2

I've set up a nextcloud server on a raspberry pi at my home which I can access from outside my wifi via a noip dyn-dns domain. From inside the network I can't use the domain though since that resolves to my external ip but not the internal ip of the raspberry.

For this I've found two approaches which both do not work in my case:

1.) The most widely advised approach would be to activate a NAT Loopback on the router. This is unfortunately not possible since my router doesn't support this and I'm not looking into buying a new one just for this use case.

2.) Changing local DNS entry. I'm running Linux and thus I could change /etc/hosts to map the domain to the internal ip. Works fine if I'm locally connected to my home network, but doesn't work if I want to connect from the outside. Perhaps there would be a way to circumvent this but then another major downside of this approach is that I'd need to edit the local DNS entries for multiple devices including Windows, iOS, and Android. So, I'd prefer to find a method which doesn't need to modify the several local clients but does it in a more centralistic way.

Is there any other way to resolve this?

onoSendai

Posted 2017-02-18T08:52:49.663

Reputation: 121

How about assigning the Raspberry Pi a static IP address on the local network to ensure it's always the same regardless, and then internally on your network you just access that resource via it's static private IP address? The dynamic and external/public IP address access method is for external access and thus internally it's not really needed so I'd go with that sort or method if you don't have internal DNS server, etc. to point the IP address back of the ability to use NAT loopback. – Pimp Juice IT – 2017-02-18T09:18:22.883

Thanks for your reply, Walmart. Unfortunately, that's not a practical solution since the nextcloud client needs to be set up with a URL and changing that every time I connect to my wlan is not very convenient. Additionally I want to have several devices connected so I'm rather looking for some solution which doesn't require manual change everytime I connect. – onoSendai – 2017-02-18T14:40:11.610

Answers

0

I solved it by setting up a DNS Server on the raspberry.

For that I did:

  1. Set up a static IP on my raspberry

  2. Installed dnsmasq and set it up according to this article: https://www.raspberrypi.org/forums/viewtopic.php?t=46154 I've used the /etc/dnsmasq.conf file provided in this article but adjusted the following:

    #the domain to be accesses from outside and inside
    domain=mydomain.ddns.net
    
    resolv-file=/etc/resolv.dnsmasq  
    min-port=4096
    
    #Google's DNS Server:
    server=8.8.8.8 
    
    # Max cache size dnsmasq can give us, and we want all of it!    
    cache-size=10000    
    
    # Below are settings for dhcp. Comment them out if you dont want    
    # dnsmasq to serve up dhcpd requests.    
    dhcp-range=192.168.0.101,192.168.0.149,255.255.255.0,1440m    
    dhcp-option=3,192.168.0.100    
    dhcp-authoritative
    

    I've uncommented the lines about the DHCP, wich made the raspberry accessable. How DHCP and DNS are related in this context I didn't quite understand, but since it's working this way I didn't research further.

  3. added to /etc/hosts on the raspberry the following line, so that my domain will internally be resolved towards the static IP of my raspberry.

    192.168.0.100   mydomain.ddns.net 
    
  4. set the static IP of my raspberry as the DNS server on the different clients in their network settings (in my case this has worked on Linux, Windows, Android and iOS).

UPDATE:

The DHCP-settings of the raspberry have interfered with the DHCP of my router, so I disabled it on the raspberry by commenting out the lines regarding DCHP in /etc/dnsmasq.conf. It works without it as well, as long as you manually add the IP of the raspberry as a DNS Server on the connected clients.

UPDATE2:

Here's an explicit walk-through with all steps detailed thouroughly regarding DNS-Server installation in context of nextcloud on raspbian: https://ownyourbits.com/2017/03/09/dnsmasq-as-dns-cache-server-for-nextcloudpi-and-raspbian/

onoSendai

Posted 2017-02-18T08:52:49.663

Reputation: 121