注意:这篇文章上次更新于1424天前,文章内容可能已经过时。
This article was last updated1424 days ago, the content may be outdated.
大概半年之前发现了家里的网络具有公网IP,于是就有了在家里部署一台服务器的想法。
最近由于学校还没有开学,只能居家“学习”,又正好之前自己淘汰了一个笔记本电脑,于是立马把笔记本重装成了 Ubuntu22,又在路由器上设置内网的固定IP,设置DMZ主机为我的笔记本电脑。这样,我在笔记本上部署的所有服务就都可以在公网访问了。
但是,由于家里的公网IP是动态的,不是固定的,每次光猫或者路由器断电,重新拨号就会导致IP变更,即使你能保证家里的路由器和光猫不重启,运营商也会每隔一段时间刷新一次的。所以为了能让域名动态的解析到家里的笔记本电脑。就需要DDNS服务了,即动态域名解析。
我的性格自然不会去买花钱的服务的😏,于是想到了利用 DNS 服务商提供的 API 去设置域名解析,在本地设置好定时任务,就可以实现动态域名解析了。
由于 Cloudflare 已经不再对 freenom 上的免费域名提供 API 支持了,所以我这里使用阿里云的 DNS API。
再设置一个企业微信的推送。就完美了✨

About half a year ago I discovered that my home network has a public IP, so I got the idea of deploying a server at home.
Recently, since school hasn’t started yet, I could only study at home. It just so happened that I had retired an old laptop, so I immediately reinstalled Ubuntu22 on it, set a fixed internal IP on the router, and set the DMZ host to my laptop. In this way, all the services deployed on my laptop can be accessed from the public network.
However, since the public IP at home is dynamic, not fixed, every time the optical modem or router loses power and redials, the IP changes. Even if you can guarantee that your router and optical modem never restart, the ISP will still refresh it every once in a while. So in order to dynamically resolve the domain name to my home laptop, I needed a DDNS service — dynamic domain name resolution.
Given my personality, I naturally wouldn’t buy a paid service 😏, so I thought of using the API provided by the DNS provider to set up domain resolution, and set up a scheduled task locally — that way I could achieve dynamic domain name resolution.
Since Cloudflare no longer provides API support for free domains on freenom, I used Alibaba Cloud’s DNS API here.
Plus a WeCom (WeChat Work) push notification. Perfect ✨

完整代码如下:
The complete code is as follows:
1 | from aliyunsdkcore.client import AcsClient |


