Dynamic DNS,Acronym ddns,It is different from our usual DNS resolution,But it is intended to deal with the kind of no fixed public IP address resolution server。
Typical usage is:Construction of small home broadband server,There is no fixed IP,Want online,In addition to writing scripts mail outside,The only way this can go ddns。
as far as I can tell,The most famous is probably the notoriously unstable and difficult to use the peanut shells。If there is a foreign dynu also very good。
Ali now open cloud API,So we can use Ali cloud API ddns it a self-fulfilling? Natural principle is very simple,Yourself achieve a small client,Then regularly obtain their own IP and external network through the API to modify the corresponding domain name resolution just fine!
of course,Some work has been done in this part of the client (thanks
),With python 2 achieve,so,It is cross-platform。Here we use Ubuntu 16.04 The examples do vps。
First cloned from github project to the local:
1 2 |
Ubuntu:# cd /opt Ubuntu:/opt# git clone https://github.com/rfancn/aliyun-ddns-client.git |
And then copy the configuration file to the specified location and edit:
1 2 3 |
Ubuntu:/opt# cd aliyun-ddns-client/ Ubuntu:/opt/aliyun-ddns-client# cp ddns.conf.example /etc/ddns.conf Ubuntu:/opt/aliyun-ddns-client# vi /etc/ddns.conf |
1 2 3 4 5 6 7 8 9 10 11 12 |
[DEFAULT] access_id = XUG8zYuSMNfieXYZ access_key = qdksYdEFe5ScGgIDcj9hN8KUk2RTXX interval = 600 debug = true [DomainRecord1] domain = logcg.com sub_domain = home type = A id = value = |
Here,We need to get permission Ali cloud API,Get method is to log on Ali cloud;
- Find "Access Keys" to the right of the top bar background Home;
- Click the page top right button to create a new Access Key after passing through SMS verification;
- The displayed page Access Key ID and Access Key Secret, compared with the required ID and Key。
After obtaining permission to API,We continue to modify the configuration:
Configuration interval Invalid do not control, [DomainRecord1] Is your domain name field,Can be changed to correspond to the name used to distinguish different subdomains only,If you want to do dynamic analysis of multiple subdomains,Then you can write multiple fields。
For this field, domain For your domain,Primary Domain; sub_domain To resolve the dynamic subdomains,Remember created in advance,To resolve to any IP。
For example,,To dynamic analysis home.logcg.com,Then fill in accordance with the foregoing example。
type To resolve records,For example, the A record (case records);MX records。
At last id and value Leave blank,Let the program can be completed on their own。
After editing is completed,You can perform Ubuntu:/opt/aliyun-ddns-client# python ddns.py To run,The first run will get an error [ERROR] You must specify domain record id. It's ok,This is because we id The results of field blank,Get complete program itself,Perform another try:
1 2 |
Ubuntu:~/aliyun-ddns-client# python ddns.py 2016-06-21 16:01:10 [INFO] Successfully sync done for record:DomainRecord1 |
I went backstage to see the page refresh,Resolve the address has been updated。
Auto Sync
Then,Now we use Ubuntu task management to achieve a dynamic domain name analytic:
1 |
Ubuntu:~# crontab -e |
We add an additional row at the end of the file contents,enter:
1 |
*/1 * * * * cd /opt/aliyun-ddns-client && /usr/bin/python ddns.py |
Sentence indicates every minute,Enter the program directory (we previously cloned client directory),And then perform an update program。
All right,At this point it would be our home.logcg.com domain dynamic analysis ✌️
Original article written by LogStudio:R0uter's Blog » Ali cloud management API use dynamic domain name resolution ddns
Reproduced Please keep the source and description link:https://www.logcg.com/archives/1768.html
This just fine,For linux novice is not so complicated。Once a success
Thanks。。。。
Pan-domain name can not be resolved ah
I feel this worked for me,A first mark
nailed it, Requests marked PY several packages,It will be solved ,Thank you。
haha, okay,When using python version must pay attention to and deletions package, No module named Xxx.
Encounter new problems,,,,
ubuntu @ ubuntu:/opt/aliyun-ddns-client$ python ddns.py
Failed to get valid Domain Records Info
2016-07-08 23:30:14 [ERROR] Failed to match remote domain record for http://www.wixxz.com
2016-07-08 23:30:14 [ERROR] Failed doing the first time sync for record:DomainRecord1
Looking for reasons,,,,
Should not be added http://,Write directly to the domain name,Oh, www.You should not increase it! Oh, right,I did not write this script Kazakhstan,yesrfancn
Ali cloud the return data is printed out on
My situation is the wrong time
Or try this
https://github.com/shellc/aliyun-ddns
Later, with the original software solutions,Permissions problem 3Q。
I was such a problem,I would like to ask how to solve ah? Thank you
leolindaming@hotmail.com
Git your Aliyun-DDNS-client application when this stuff in the following error,Bloggers time, then help look yo, My mailbox 3117821@qq.com
ubuntu @ ubuntu:/opt/aliyun-ddns-client$ python ddns.py
Traceback (most recent call last):
File “ddns.py”, line 21, in
from helper import DDNSHelper
File “/opt/aliyun-ddns-client/helper.py”, line 20, in
from utils import DDNSUtils
File “/opt/aliyun-ddns-client/utils.py”, line 20, in
import requests
ImportError: No module named requests
End