Skip to content

Instantly share code, notes, and snippets.

@deoxykev
Created February 2, 2020 01:40
Show Gist options
  • Save deoxykev/f9b0f2eb256c69e65333c942aa8afbbf to your computer and use it in GitHub Desktop.
Save deoxykev/f9b0f2eb256c69e65333c942aa8afbbf to your computer and use it in GitHub Desktop.
DDNS client for namecheap with systemd init script
#!/bin/bash
# update namecheap ddns from unraid
# 2020-01-06
# systemd init script:
# [Unit]
# Description=Updates internal DDNS for meowth.kanto.blue
# After=network.target
#
# [Service]
# Restart=always
# RestartSec=5
# ExecStart=/path/to/update-ddns.sh
#
# [Install]
# WantedBy=default.target
HOSTNAME=<subdomain>
DOMAIN=<yourdomain.com>
PASSWORD=<namecheapDDNSkey>
INTERFACE='enp2s0'
while true; do
touch "${HOME}/.ddns"
LASTIP="$(cat "${HOME}/.ddns")"
IP="$(ip addr show $INTERFACE | grep -Po 'inet \K[\d.]+')"
if [[ "$LASTIP" != "$IP" ]]; then
if curl -s "https://dynamicdns.park-your-domain.com/update?host=$HOSTNAME&domain=$DOMAIN&password=$PASSWORD&ip=$IP" | grep '<ErrCount>0</ErrCount>'; then
echo "$IP" > "${HOME}/.ddns"
echo "[+] DDNS: $IP"
else
echo "[-] Failed to update DDNS"
fi
fi
sleep 5
done
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment