1
2
3
4
5
6
7
8
9
10
11 domain="example.com"
12 password="password"
13
14
15
16 host="subdomain"
17
18
19 ipfile="/tmp/dns_last_ip"
20
21 touch "$ipfile"
22 lastip="$(cat "$ipfile")"
23 responsefile="/tmp/dns_response"
24 greperror="/tmp/dns_greperror"
25
26 echo "$(date +"%Y-%m-%d %H:%M:%S")"
27 echo " Beginning DNS update..."
28
29
30 ip="$(dig -4 +short myip.opendns.com @resolver1.opendns.com 2> "$responsefile")"
31
32 if [ "$?" -ne 0 ] || [ -z "$ip" ]; then
33 ip="$(dig -4 +short @ns1-1.akamaitech.net ANY whoami.akamai.net 2>> "$responsefile")"
34 fi
35
36 if [ "$?" -ne 0 ] || [ -z "$ip" ]; then
37 ip="$(dig -4 +short @ns1.google.com TXT o-o.myaddr.l.google.com | tr -d \" 2>> "$responsefile")"
38 fi
39
40
41 if [ "$?" -ne 0 ] || [ -z "$ip" ]; then
42
43 echo " **IP lookup failed** OpenDNS resolver might not be responding?"
44 echo " Error recieved: '"$(cat "$responsefile" )"'"
45 echo "DNS update aborted!"
46
47
48 if [ "$(command -v sendmail)" ]; then
49 echo -e "Subject: DNS Update Script Error\nIP lookup failed. OpenDNS resolver might not be responding.\n\nIP received: '$ip'\nError received: '"$(cat "$responsefile")"'" | /usr/sbin/sendmail root
50 fi
51 elif [ "$ip" == "$lastip" ]; then
52 echo " Public IP is still $ip, no changes detected."
53 echo "DNS check complete!"
54 else
55 echo " Last IP was $lastip. Current IP is $ip. Updating DNS..."
56
57 echo " - Updating DNS for $host.$domain..."
58 echo "$(curl -s "https://dynamicdns.park-your-domain.com/update?host="$host"&domain="$domain"&password="$password"")" > "$responsefile"
59
60
61
62 grep -i "errors" "$responsefile" > /dev/null 2> "$greperror"
63 check="$?"
64 if [ "$check" -eq 0 ]; then
65
66
67 echo " **Error during IP update**"
68 echo " $(cat "$responsefile")"
69
70
71 if [ "$(command -v sendmail)" ]; then
72 echo -e "Subject: DNS Update Script Error\nError during IP update. Response received:\n\n"$(cat "$responsefile")"" | /usr/sbin/sendmail root
73 fi
74 elif [ "$check" -eq 1 ]; then
75
76 echo "$ip" > "$ipfile"
77 else
78
79 echo " **grep error during update. This should not happen!**"
80 echo " $(cat "$greperror")"
81
82
83 if [ "$(command -v sendmail)" ]; then
84 echo -e "Subject: DNS Update Script Error\nError while grepping. This should not happen! Error received:\n\n"$(cat "$greperror")"" | /usr/sbin/sendmail root
85 fi
86 fi
87 echo "DNS update complete!"
88 fi