Last active
November 29, 2022 23:59
-
-
Save hapylestat/9f639666c5db62b72d9249d180ddfcf5 to your computer and use it in GitHub Desktop.
DDNS_Namecheap
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
How to | |
======== | |
copy ddns.config /etc/default/ | |
copy ddns.{service,timer} /etc/systemd/system/ | |
echo "adjust ddns.config ..." | |
vi /etc/default/ddns.config | |
systemctl daemon-reload | |
systemctl enable ddns.timer | |
systemctl start ddns.timer |
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/bash | |
DEV="IFNAME to fetch IP, i.e. eth0" | |
KEY="NAMECHEAP DDNS KEY" | |
_DOMAIN="DOMAIN - i.e. example.com" | |
_HOST="HOST - i.e. sample -> sample.example.com" |
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
[Unit] | |
Description=DDns update job | |
; replace paths to suitable fo you | |
[Service] | |
EnvironmentFile=/usr/srv/_conf/system/ddns/.config | |
Type=oneshot | |
ExecStartPre=bash -c '[[ ! -d "/usr/srv/_conf/system/ddns/cache" ]] && mkdir -p "/usr/srv/_conf/system/ddns/cache" || true' | |
ExecStartPre=bash -c 'echo _MYIP=$(/usr/sbin/ip addr show dev ${DEV}|grep inet|head -n 1|awk \'{print $2}\'| cut -d\'/\' -f1) >/usr/srv/_conf/system/ddns/cache/.myip' | |
EnvironmentFile=-/usr/srv/_conf/system/ddns/cache/.myip | |
EnvironmentFile=-/usr/srv/_conf/system/ddns/cache/.myip.old | |
ExecStart=bash -c '[[ "x${_MYIP}" != "x${_MYIP_OLD}" ]] && curl "https://dynamicdns.park-your-domain.com/update?host=${_HOST}&domain=${_DOMAIN}&password=${KEY}&ip=${_MYIP}" || true' | |
ExecStartPost=bash -c 'echo _MYIP_OLD=${_MYIP} > /usr/srv/_conf/system/ddns/cache/.myip.old' |
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
[Unit] | |
Description=Starting DDns Service | |
[Timer] | |
OnUnitActiveSec=5m | |
OnBootSec=5m | |
[Install] | |
WantedBy=timers.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment