Skip to content

Instantly share code, notes, and snippets.

@msvamp
Created May 16, 2021 08:30
Show Gist options
  • Save msvamp/324794c18890fdacad7349d0b220b9c1 to your computer and use it in GitHub Desktop.
Save msvamp/324794c18890fdacad7349d0b220b9c1 to your computer and use it in GitHub Desktop.
No-IP DDNS Updater (Hotplug)

No-IP DDNS Update script for OpenWrt

You can use this script to update your no-ip domain name in your OpenWrt-based router, if you don't want to use the bulky ddns-scripts package (documented here) provided.

  1. Edit the values of the variables in the script

    T_DEV : The actual (NOT logical) interface name of your WAN interface
    T_USER : Your No-IP username or email
    T_PASS : Your NO-IP password
    T_DOMS : Your domain name(s) to be updated (separate multiple domains with a , in the string)

  2. Copy the script to your router

    scp noip-ddns-hotplug root@<router-ip>:/etc/hotplug.d/iface/99-ddns
    

The No-IP API documentation for updating your domain name is here.

To-do (pending work)

  • Set the user-agent string
  • Interpret the response
  • Add IPv6 support
  • Set domain offline status when interface is down
#!/bin/sh
[ "$ACTION" = ifup -o "$ACTION" = ifupdate ] || exit
T_DEV='pppoe-wan'
T_LOCK="/tmp/tmp/ddns_$T_DEV.lock"
[ "$DEVICE" != "$T_DEV" -o -e "$T_LOCK" ] && exit
touch "$T_LOCK"
T_USER='username'
T_PASS='password'
T_DOMS='mytest1.example.com,mytest2.example.com'
n=0; until [ $n -ge 5 ]; do
sleep 3
T_IP="`ip addr show "$T_DEV" | grep 'inet ' | awk -F' ' '{print $2}'`" 2>/dev/null
[ -z "$T_IP" ] || break
n=$((n+1))
done
[ $n -ge 5 ] && {
logger -t ddns -p err "DDNS update ($T_DEV) fail: Couldn't get address of $T_DEV"
rm -f "$T_LOCK"
exit
}
n=0; until [ $n -ge 3 ]; do
T_RS="`uclient-fetch -qO- -T9 --user="$T_USER" --password="$T_PASS" "https://dynupdate.no-ip.com/nic/update?hostname=$T_DOMS&myip=$T_IP"`" 2>/dev/null
T_EX="$?"
[ "$T_EX" -eq 0 ] && break
logger -t ddns -p warn "DDNS update ($T_DEV) fail: Request failed with exit code $T_EX"
n=$((n+1))
sleep 3
done
[ $n -ge 3 ] && {
logger -t ddns -p err "DDNS update ($T_DEV) fail: Giving up after $n tries"
rm -f "$T_LOCK"
exit
}
logger -t ddns -p notice "DDNS update ($T_DEV) success: $T_RS"
rm -f "$T_LOCK"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment