One problem that I was having with them: the custom URL did not work inside my network, just outside. That happens because my router does not support NAT loopback, blocking any requests from the internal network to the external IP (which is what my custom domain points to).
On a computer, there is an easy fix. Let’s assume your custom domain is
foobar.duckdns.org, and the internal IP (the one that you configured the router to forward a given port to) is 22.214.171.124. Adding a line like this to
/etc/hosts (and commenting it out with
# if the computer ever leaves the house) does it:
For mobile devices, it isn’t that easy: neither Android, nor iOS expose
/etc/hosts. And those devices enter and leave the house all the time, making it impractical anyway.
The workaround: since I already have the Raspberry Pi lying around, I installed
dnsmasq (a lightweight DNS server) on it:
sudo apt-get install dnsmasq
and opened the firewall for its port, so my mobile devices can use that DNS when they are inside the network:
sudo ufw allow dns
Several online tutorials suggest config changes (such as enabling DHCP on
dnsmasq - a no-no for my otherwise working network). I just kept the default config and added this line to
/etc/dnsmasq.conf and restarting the service:
With that, the DNS server will respond with the internal IP for the custom domain:
$ dig @126.96.36.199 foobar.duckdns.org ; <<>> DiG 9.10.6 <<>> @188.8.131.52 foobar.duckdns.org ... ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10291 ;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ... ;; ANSWER SECTION: foobar.duckdns.org. 0 IN A 184.108.40.206 ...
and everything else will go to the normal DNS server for normal resolution:
$ dig @220.127.116.11 google.com ; <<>> DiG 9.10.6 <<>> @18.104.22.168 google.com ... ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55137 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ... ;; ANSWER SECTION: google.com. 171 IN A 22.214.171.124 ...
The final step was to edit the Wi-Fi connection on the devices, so they would ask
dnsmasq for names when inside the network. iOS was the easiest: you just click
Configure DNS, switch to
Manual, remove the auto-configured value(s) and add
126.96.36.199. Android requires changing the whole
IP settings to
Static (which also means you’ll need an IP assigned to your mobile phone on your router) and enter the information manually.
But that is a minor nuisance (that I only had to go through once). After that, the devices work inside and outside the house (which is great for Home Assistant, in particular if you have security things you want to check from away). The downside: if the Pi is down, the devices won’t have internet (which is why I kept the computer on the ‘/etc/hosts’ solution), but you can always switch back (or to data) if that happens. Overall, I’m happy now.