给NAT VPS添加DDNS,防止ip频繁变更导致失联

NAT VPS区别于VPS在于没有静态ip,而动态ip带来的结果就是商家频频更换ip,只用ip访问会导致你失联。

准备

1.cloudflare账号并解析域名

给NAT VPS添加DDNS,防止ip频繁变更导致失联
注册cloudflare并解析域名

2.NAT VPS一个。

解决方案

CloudFlare

1.在cloudflare解析的域名里随便添加一个二级域名,代理状态那个小云朵不要开,IPv4 地址随便写,比如8.8.8.8.

给NAT VPS添加DDNS,防止ip频繁变更导致失联

2.cloudflare---右上角人头像---我的资料---API令牌---Global API Key---查看---记录并复制

给NAT VPS添加DDNS,防止ip频繁变更导致失联
Global API Key

NAT VPS

ssh连接你的NAT VPS

安装脚本,并赋予权限

curl https://raw.githubusercontent.com/aipeach/cloudflare-api-v4-ddns/master/cf-v4-ddns.sh > /root/cf-v4-ddns.sh && chmod +x /root/cf-v4-ddns.sh

编辑CF配置文件

vi cf-v4-ddns.sh
# incorrect api-key results in E_UNAUTH error
CFKEY=cloudflare你获取的key

# Username, eg: [email protected]
CFUSER=cloudflare账户名

# Zone name, eg: example.com
CFZONE_NAME=解析的一级域名

# Hostname to update, eg: homeserver.example.com
CFRECORD_NAME=ddns所用的二级域名

启动ddns更新IP

./cf-v4-ddns.sh

正常没问题的话,可以观察cloudflare dns解析已经把ip更换过来了。

给刚才脚本添加定时任务

crontab -e

nano或者vim自己选都可以,我比较习惯vim。

crontab -e
no crontab for root - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.basic
  3. /usr/bin/vim.tiny
  4. /bin/ed

添加

*/2 * * * * /root/cf-v4-ddns.sh >/dev/null 2>&1

至此结束

文章版权归作者所有。发布者:白嫖怪,转转请注明出处:https://c7pai.com/134/

(0)
白嫖怪白嫖怪
上一篇 2022年7月31日 下午4:47
下一篇 2022年8月3日 下午5:33

相关推荐