网络运维系列:GoDaddy Shell DDNS配置

本文档介绍了如何配置Shell脚本和GoDaddy API,以便定期检查并更新GoDaddy DNS记录,以匹配家用宽带的动态公网IP地址。通过创建GoDaddy密钥、编写Shell脚本并设置定时任务,实现动态DNS服务,确保从外部可以稳定访问家中的网络设备,如NAS和远程桌面。
摘要由CSDN通过智能技术生成

1. 引言

由于IP地址的稀缺性,日常办理的家用宽带出口IP地址都是动态变化的,为了能够动态的知道家用宽带的出口IP以便能够便捷的访问到家里的网络设备,如NAS、远程桌面等,参考通用做法采用DDNS方案,由于域名是在GoDaddy申请的,整体技术方案需要通过GoDaddy申请秘钥对,然后通过开放URL地址对域名的DNS解析指向进行修改,下面是具体的流程。

2. GoDaddy密钥申请

密钥Key申请:https://developer.godaddy.com/keys ,选择Production,名字自定义即可,生成密钥对后请记得及时保存,后续无法再次查看。
在这里插入图片描述

3. Shell脚本配置

#!/bin/bash

# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
# Special thanks to mfox for his ps script
# https://github.com/markafox/GoDaddy_Powershell_DDNS
#
# First go to GoDaddy developer site to create a developer account and get your key and secret
#
# https://developer.godaddy.com/getstarted
# Be aware that there are 2 types of key and secret - one for the test server and one for the production server
# Get a key and secret for the production server
#
#Update the first 4 variables with your information

domain="your.domain.to.update"   # your domain
name="name_of_host"     # name of A record to update
key="key"     # key for godaddy developer API
secret="secret"   # secret for godaddy developer API

headers="Authorization: sso-key $key:$secret"

# echo $headers

result=$(curl -s -X GET -H "$headers" \
 "https://api.godaddy.com/v1/domains/$domain/records/A/$name")

#echo $result;

dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")
#echo "dnsIp:" $dnsIp

# Get public ip address there are several websites that can do this.
ret=$(curl -s GET "http://ipinfo.io/json")
currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")


#echo "currentIp:" $currentIp

if [ "$dnsIp" != "$currentIp" ];
 then
#	echo "Ips are not equal"
	request='[{"data":"'$currentIp'","ttl":3600}]'
#	echo " request:" $request
	nresult=$(curl -i -s -X PUT \
 -H "$headers" \
 -H "Content-Type: application/json" \
 -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
#	echo "result:" $nresult
fi

4. 定时任务配置

sudo crontab -e 
*/10 * * * * sh /config/scripts/aliddns/aliddns_erx.sh

5. 参考文档

github地址:https://github.com/markafox/GoDaddy_Powershell_DDNS

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蒲春伟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值