Skip to content

Instantly share code, notes, and snippets.

@vooon
Last active November 20, 2015 09:56
Show Gist options
  • Save vooon/38ce32b69a2c05487ff2 to your computer and use it in GitHub Desktop.
Save vooon/38ce32b69a2c05487ff2 to your computer and use it in GitHub Desktop.
Dynamic DNS updater script for Yandex DNS service
#!/bin/sh
#set -x
# Original:
# http://blog.marvins.ru/administrirovanie/sam-sebe-dynamic-dns.html
# About yabdex dns service:
# https://yandex.ru/support/pdd/hosting.xml
# auth token:
# https://pddimp.yandex.ru/api2/admin/get_token
# To get record_id: look for A record
# curl -H "PddToken: $token" "https://pddimp.yandex.ru/api2/admin/dns/list?domain=$domain"
# Configuration
domain="domain.com"
token="123456789ABCDEF0000000000000000000000000000000000000"
record_id="19144918"
# Получаем текущий IP адрес с yandex.ru/internet
ip=`curl -s http://yandex.ru/internet | awk '/<strong>IP-адрес<\/strong>/ {print $2}'`
# Получаем IP адрес записанный в dns ppd.yandex.ru для нашего домена
dnsip=`host "$domain" dns2.yandex.ru | awk '/has\ address/ {print $4}'`
if [ "$ip" = "$dnsip" ]; then
exit
else
curl -H "PddToken: $token" \
-d "domain=$domain" \
-d "record_id=$record_id" \
-d "subdomain=@" \
-d "ttl=14400" \
-d "content=$ip" \
'https://pddimp.yandex.ru/api2/admin/dns/edit' > /dev/null
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment