Last active
March 24, 2018 14:45
-
-
Save KonradAdamczyk/fe731b698dba57ad8012565cc61155cf to your computer and use it in GitHub Desktop.
OpenWrt/LEDE openDNS dynamic ip updater, handles no Internet access state, and !yours openDNS IP conflict, and configures IP filtering as fast as possible, other methods implies few minutes without filtering after reconnecting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Place me in /etc/hotplug.d/iface/99-opendns-update-ip | |
#configuration start | |
user="[email protected]" #email used while registering to opendns | |
password="pass" #password to opendns , as special chars use _ - (underscore or minus), other specials must be escaped | |
hostname="home" #label of opendns network | |
targetInterface="wan" #interface which has access to Internet, and dynamic ip | |
#configuration end | |
[ "$ACTION" = "ifup" ] && [ "$INTERFACE" = $targetInterface ] && { | |
logger -s -t opendnsIpChange "$targetInterface is up, updating ip" | |
while true; | |
do | |
result=$(wget -q -O - --no-check-certificate --timeout=10 --user="$user" --password="$password" https://updates.opendns.com/nic/update?hostname=$hostname) | |
exit_code=$? | |
echo "exit_code = $exit_code" | |
echo "result = $result" | |
[ "${result/good}" != "$result" ]&& { | |
logger -s -t opendnsIpChange "successfully updated IP $result" | |
exit 0 | |
} | |
[ "${result/yours}" != "$result" ]&& { | |
logger -s -t opendnsIpChange "IP conflict response: $result" | |
logger -s -t opendnsIpChange "restarting wan to change IP" | |
ifdown wan | |
sleep 1 | |
ifup wan | |
exit 0 | |
} | |
[ $exit_code = 4 ] && { | |
echo "no internet connection" | |
continue | |
} | |
logger -s -t opendnsIpChange "not supported response: $result" | |
logger -s -t opendnsIpChange "wget exit code: $exit_code" | |
logger -s -t opendnsIpChange "retry after 1 minute" | |
sleep 61 #minute to do not abuse opendns server in case of wrong result | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment