2

I run this script every 15 minutes to record the IP of four dynamic hosts I have setup at duckdns.org.

DUCKDNS=( "sub1.duckdns.org"
        "sub2.duckdns.org"
        "sub3.duckdns.org"
        "sub4.duckdns.org" )

function resolveIP () {
    CURRENT_IP=$(dig +short $1)
    echo $CURRENT_IP
}

for HOST in "${DUCKDNS[@]}"
do
    IP=$(resolveIP $HOST)
    echo -e "$HOST ... $IP"
done

When I run the script from the shell, I receive an IP value every time. When I run the script via cron, the script returns null values sporadically.

I believe the issue is related to a 2(SERVFAIL) error I noticed when running host (not dig). This is the response from host:

host sub1.duckdns.org
sub1.duckdns.org has address 66.66.66.66 (NOTE: This value is correct)
Host sub1.duckdns.org not found: 2(SERVFAIL)
sub1.duckdns.org mail is handled by 50 sub1.duckdns.org.

Though an error is returned, the IP address is correct and the script returns it. What is troubling is sometimes is it's not consistent. The script extracts the value when run from the shell every time and most of the time when run via cron.

After setting up my subdomains with DuckDNS.org, I've read that it may not have been a wise choice. Perhaps it's just an issue with the DuckDNS service? If so, any recommendations for other dynamic DNS providers?

I feel like I'm living a bash version of the double slit experiment. Any thoughts on what could be causing this null IP behavior?

  • 2
    I think the difference between `dig`, `host` and the run environment is a just coincidence. In all these cases, your DNS server seems to fail to resolve the duckdns.org address, returning a SERVFAIL. This is a catch-all error and can indicate all sorts of issues, typically a timeout error (e.g. one of the authoritative duckdns.org servers fails to respond within the timeout limit of your DNS server). This is fairly common. If you want to know who fails, run `dig` with `+trace` periodically and log the results--this will give you iterative DNS queries and an insight into the above. – PeterK Nov 30 '15 at 06:38
  • Aha! Perfect! Thank you! I believe I came across some frustration about duckdns timing out in my research. Is there a way to extend the timeout in order to give duckdns more time? – Brian Shoff Nov 30 '15 at 07:43
  • 1
    You can probably change the timeout in your DNS server configuration, or use `dig` with a custom timeout through the `+time` param (speaking of which, it also has `+tries` and `+retry` parameters, which may come handy with timeouts). The important thing is, when you do recursive queries using your own DNS server, timeout depends on _both_ the DNS server and `dig`. If the DNS server times out first, you get SERVFAIL. When `dig` does, you get whatever `dig` does on a timeout. Iterative queries (`+trace`), however, only depend on `dig` timeout, because it gets to control the whole process. – PeterK Nov 30 '15 at 08:15
  • Thank you!! This is exactly what I needed to move forward! – Brian Shoff Nov 30 '15 at 09:28

0 Answers0