wintermelons / homelab

Configuration of my home servers.
MIT License
0 stars 0 forks source link

Set up Dynamic DNS #1

Open wintermelons opened 1 week ago

wintermelons commented 1 week ago

ISPs can change our public IP address, and dynamic DNS can help with this. The homelab DNS record is hosted on Cloudflare and it supports dynamic DNS with its APIs. We can make use of community tools to help with setting this up easily.

wintermelons commented 1 week ago

https://github.com/timothymiller/cloudflare-ddns is a popular project that is also dockerized. It uses Cloudflare's own DNS resolver APIs to get its own public IP.

Specifically, for IPv4, it sends a GET request to https://1.1.1.1/cdn-cgi/trace, which returns a response that has an IP address. Running with curl also works:

curl -X GET "https://1.1.1.1/cdn-cgi/trace"

Or navigating to https://cloudflare.com/cdn-cgi/trace on a browser.

wintermelons commented 1 week ago

Running the docker container locally (on MacOS) following the getting started guide seems to be working. I could bring my laptop to a coffee shop to see if it'd update the DNS record.

wintermelons commented 1 week ago

Used tethering with mobile network, container worked fine and output log:

2024-09-08 15:59:42 📡 Updating record {'type': 'A', 'name': 'homelab.wintermelons.me', 'content': '<new ip>', 'proxied': False, 'ttl': 300}

and observed that the same IP is updated in the DNS records on Cloudflare.

wintermelons commented 1 week ago

And switching back to my home wifi updated the record again. Looks like the tool is WAI.

The remaining work is just to deploy it to the servers once it has docker set up.