2016/11/24

Enom DNS 服務的動態 dns 更新


Enom DNS 服務的動態 dns 更新

圖跟內文無關


最近因為工作關係,租了一台韓國的 aws 主機來當 vpn 服務,想說 ip 也不想固定,弄個動態 ip 更新好了。我的 dns 主機商是 enom 他在網路上有很多的自動更新的 script。

先提供一個有趣的網站,這網站可以用命令列反查所在的對外 public ip 很適合用來寫程式。
https://ifconfig.co/ 命令列及 API 版本的 myip address

另外有一個網站 https://www.ipip.net/ 可以查詢每個 ip 的所在地,是一個很好用的服務。
另外也提供 api 接入的功能,可以很方便的接程式。

官方網站提供的程式,右方有各種平台用的。
http://www.enom.com/help/faq_dynamicdns.asp 

下面是在 github 找到的,其實重點在 enom api server 提供的服務,每個程式只是包裝了一些個人化的需求。
Enom api server
ENOMURL="http://dynamic.name-services.com"

python version:
https://gist.github.com/stef-levesque/11229362

shell version:
https://gist.github.com/h0tw1r3/11405624

php version:
https://github.com/mrubinsk/phpEnomUpdate/blob/master/phpEnomUpdate.php

php 最簡單版本的 update.
https://gist.github.com/agarzon/2431219

// --------------------------------------------
# php 版本的更新程式
[root@ip-172-31-12-22 enom]# cat /root/enom/ip-update.php
#!/usr/bin/php

/* Run this script every 5 minutes (or 1 hour, is up to you) using a cron task */
// ref: https://gist.github.com/agarzon/2431219
/* Edit this data*/
$domain = "網域名稱 example.com ";  
$pass = "密碼";
$host = "A紀錄名稱"; // Optional, for additional hosts names like: ftp., mail. or any sub-domains.

// 底下三行僅供參考
//file_get_contents("http://dynamic.name-services.com/interface.asp?command=SetDNSHost&Zone=@.$domain&DomainPassword=$pass");
//file_get_contents("http://dynamic.name-services.com/interface.asp?command=SetDNSHost&Zone=www.$domain&DomainPassword=$pass");
//file_get_contents("http://dynamic.name-services.com/interface.asp?command=SetDNSHost&Zone=*.$domain&DomainPassword=$pass");
// 寫入 api service ,執行完後去查查看是否有這個 A 紀錄,或是 ip 更新了
file_get_contents("http://dynamic.name-services.com/interface.asp?command=SetDNSHost&Zone=$host.$domain&DomainPassword=$pass");
?>

寫入排程
[root@ip-172-31-12-22 enom]# crontab -l
*/30 * * * * /root/enom/ip-update.php


沒有留言: