DNSEXIT的DDNS自动化配置

DNSExit从2001年开始提供免费域名DNS解析和动态DNS解析, 后续又陆续推出了免费二级域名、免费企业邮箱、免费SSL安全证书等免费服务。
DNSExit提供了.work.gd、.line.pm、.linkpc.net、.run.place、.publicvm.com这几种免费二级域名供你选择注册, 同样也具有域名DNS解析及动态DNS解析功能,但不支持修改DNS服务器,也就是只能用DNSExit提供的DNS解析功能。
DNSExit免费二级域名最多开通1年,可在到期前30天免费续期。另外提醒一下,DNSExit的免费二级域名在有些省份被屏蔽使用了,个人测试还可以用一下,不要用在重要场合。查询域名是否被拦截污染可以用拨测。
DNSExit免费企业邮箱,有100M容量,可建立2个邮箱,支持邮件转发,支持POP3、IMAP、SMTP及网页收发邮件,每天限制对外发送20封邮件。DNSExit免费企业邮箱一次只能开通1年,不过可以在到期前的45天内免费续期。
DNSExit还提供了一键申请Let’s Encrypt的免费SSL安全证书,支持泛解析域名SSL证书,可无限子域名使用,免费证书有效期90天,可在到期前30天免费续期。

1、自动化本机DDNS的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash

DNSAPIKEY=[apikey]
DNSHOST=[domain]
WANIPSITE="http://ipv4.icanhazip.com"
WAN_IP=$(curl -s ${WANIPSITE})
WAN_IP_FILE=wanip.txt

# Get current and old WAN IP
if [ -f $WAN_IP_FILE ]; then
OLD_WAN_IP=$(cat $WAN_IP_FILE)
else
echo "No File, Need IP"
OLD_WAN_IP=""
fi

# If WAN IP is unchanged, exit here
if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then
echo "Local Check: IP not changed. Exiting..."
exit 0
fi

# If WAN is changed, update!
echo "Updating DNS to $WAN_IP"
RESPONSE=$(curl -s https://api.dnsexit.com/dns/ud/?apikey=$DNSAPIKEY -d host=$DNSHOST)

# Check the response code
CODE=$(echo $RESPONSE | jq -r '.code')

if [ "$CODE" -eq 0 ]; then
echo "Remote Response: DNS update successful. Exiting..."
echo $WAN_IP > $WAN_IP_FILE
echo -e "Updated successfully!"
exit 0
elif [ "$CODE" -eq 1 ]; then
echo "Remote Response: IP not changed. Exiting..."
echo $WAN_IP > $WAN_IP_FILE
else
echo "Remote Response: $RESPONSE"
exit 1
fi

2、通用方式(包括修改、增加DNS的操作)

命令的格式如下:

1
curl  -H "Content-Type: application/json" --data @/path/jason-file https://api.dnsexit.com/dns/

Json文件如下格式:

2.1、更新IPV4

1
2
3
4
5
6
7
8
9
10
{
"apikey": "API-KEY",
"domain": "example.com",
"update": {
"type": "A",
"name": "example.com",
"content": "1.1.1.1",
"ttl": 480
}
}

2.2、更新CNAME

1
2
3
4
5
6
7
8
9
10
{
"apikey": "API-KEY",
"domain":"example.com",
"update":{
"type":"CNAME",
"name":"mail", //or "name":"mail.example.com"
"content":"mail.yahoo.com", //point to mail.yahoo.com instead
"ttl":480 //ttl value is in minutes 480 = 6 hours
}
}

2.3、新增IPV4

1
2
3
4
5
6
7
8
9
10
{
"apikey": "API-KEY",
"domain":"example.com",
"add":{
"type":"A",
"name":"host1", //same as host1.example.com
"content":"1.1.2.2", //IP of the host
"ttl":480
}
}

2.4、新增CNAME

1
2
3
4
5
6
7
8
9
10
{
"apikey": "API-KEY",
"domain":"example.com",
"add":{
"type":"CNAME",
"name":"mail", //this actually setup mail.example.com points to mail.yahoo.com
"content":"mail.yahoo.com", //content is the canonical host name
"ttl":480 //ttl value is in minutes 480 = 6 hours
}
}

2.5、删除CNAME

1
2
3
4
5
6
7
8
{
"apikey": "API-KEY",
"domain":"example.com",
"delete":{
"type":"CNAME",
"name":"mail" //instead you can put mail.example.com
}
}

DNSEXIT的DDNS自动化配置

https://meloncloud.github.io/dnsexitapi/

Author

MelonCloud

Posted on

2024-11-02

Updated on

2024-11-03

Licensed under

Comments