The next quest in my homelab adventure was to make sure my domain name always points to my home network, even if my ISP changes my public IP address. See how I solved this with TransIP.
The challenge
My ISP does not provide be with a static IPv4 or IPv6 address. This means that my public IP address can change. Not handy if you want to access your home network from the outside via a domain name. This can be solved by using a DDNS (Dynamic DNS) provider. DDNS automatically updates the DNS records of your domain whenever your IP address changes. A popular DDNS provider is e.g. DuckDNS
But. Since I’m a developer I wanted to build my on tool. Because quests without adventures are just chores, right?
My domain is registered at TransIP, a well known Dutch domain provider. TransIP provides a set of APIs to manage domain settings, like DNS records. If you have an account you can go to the API settings and generate a Key Pair to be able to access the API. You’ll get to see the private key only once, so make sure to store it somewhere safe.
Coding the tool
I choose to code the tool in Go. Mainly because I really like Go, and there is a good library to work with Transip APIs available on Github: transip/gotransip.
You can find the implementation here: BowlOfSoup/dynamic-ip-syncer.
To fetch my public IP addresses I use icanhazip.com. This is a simple service that returns your IPv4 and IPv6 address in plain text. The following URLs can be used:
And as with all my Go projects, I make a fun Gopher-logo for it:
Created via gopherize.me.
Deploying the tool to a server
Ofc you should clone the repository and have Go installed on your machine before attempting to build the tool.
Also, I did not build an extensive build or install script or Docker container because of time constraints. But here are the steps I took:
→ (1) Build the tool
I myself build the tool for a Raspberry PI.
|
|
→ (2) Transfer the binary to the server
|
|
Now on the server itself, configure the tool to run as a service. I used systemd
for this.
→ (3) Create a .service
file with the following content:
|
|
→ (4) move the file to /etc/systemd/system/dynamic-ip-syncer.service
and enable the service:
|
|
→ (5) Make sure to create a config.yaml
file in /etc/dynamic-ip-syncer/
with the correct values, permissions should be root:root
.
→ (6) Make sure to create a private.key
file in /etc/dynamic-ip-syncer/
with the private key you got from TransIP, permissions should be root:root
.
→ (7) Start the service; the service will run in the background, and starts on reboot.
|
|
You can view the logs with the following command:
|
|