ユーザ用ツール

サイト用ツール


dynamicdns

Dynamic DNS

ダイナミックDNSのIPアドレス通知スクリプト

cron設定

/etc/cron.d/update-ddns
9,19,29,39,49,59 * * * * pi /usr/local/bin/update-mydns
1 * * * * pi /usr/local/bin/update-No-ip

MyDNS.JP

update-mydns
#!/bin/sh
#
Domain=domain1.jp
MasterID=mydnsXXXXXX
Password=xxxxxxxxxxx
IfName=eth0
 
ipv4=0
ipv6=0
ip -o addr show | while read num ifname inet ipaddr other
do
  test "$ifname" != "$IfName" && continue
  echo $other | grep "scope global" > /dev/null || continue
  echo $other | grep "mngtmpaddr" > /dev/null && continue
  case $inet
  in
    inet6)
      URL="https://ipv6.mydns.jp/directip.html?MID=${MasterID}&PWD=${Password}&IPV6ADDR=${ipaddr%/*}"
      if [ ${ipv6} -eq 0 ]
      then
        curl ${URL} -o /dev/null 1> /dev/null 2>&1 && ipv6=1
        ans=`dig $Domain AAAA +short`
        logger -p user.info -t mydns "Status ifname=${ifname}, ${inet}=${ipaddr}, Ans=${ans}, Update=${ipv6}"
      fi
      ;;
    inet)
      URL="https://${MasterID}:${Password}@www.mydns.jp/login.html"
      if [ ${ipv4} -eq 0 ]
      then
        curl ${URL} -o /dev/null 1> /dev/null 2>&1 && ipv4=1
        ans=`dig $Domain A +short`
        logger -p user.info -t mydns "Status ifname=${ifname}, ${inet}=${ipaddr}, Ans=${ans}, Update=${ipv4}"
      fi
      ;;
  esac
done

No-IP

update-No-ip
#!/bin/sh
#
Domain="domain2.com"
LoginID="XXXXXXXX"
Password="xxxxxxxxxx"
IfName="eth0"
 
UA="User-Agent: ${LoginID} Update-No-ip/Raspbian GNU/Linux 10 (buster) ${Email}"
 
ipv4=0
ipv6=0
ip -o addr show | while read num ifname inet ipaddr other
do
  test "$ifname" != "$IfName" && continue
  echo $other | grep "scope global" > /dev/null || continue
  echo $other | grep "mngtmpaddr" > /dev/null && continue
  case $inet
  in
    inet6)
      url="https://${LoginID}:${Password}@dynupdate.no-ip.com/nic/update?hostname=${Domain}"
      data="myipv6=${ipaddr%%/*}"
      if [ ${ipv6} -eq 0 ]
      then
        res=`curl -s -A "${UA}" "${url}" --data-urlencode "${data}" 2>&1 | head -n 1 | tr -d '\r'` && ipv6=1
        ans=`dig $Domain AAAA +short`
        logger -p user.info -t No-ip "Status ifname=${ifname}, ${inet}=${ipaddr}, Ans=${ans}, Query=${ipv6}, Res='${res}'"
      fi
      ;;
    inet)
      url="https://${LoginID}:${Password}@dynupdate.no-ip.com/nic/update?hostname=${Domain}"
      if [ ${ipv4} -eq 0 ]
      then
        res=`curl -s -A "${UA}" "${url}" 2>&1 | head -n 1 | tr -d '\r'` && ipv4=1
        ans=`dig $Domain A +short`
        logger -p user.info -t No-ip "Status ifname=${ifname}, ${inet}=${ipaddr}, Ans=${ans}, Query=${ipv4}, Res='${res}'"
      fi
      ;;
  esac
done
dynamicdns.txt · 最終更新: 2023/06/29 12:03 by Minoru Kijima