Setting up a DynDNS
March 14, 2025
Today my ISP decided to change my public IP yet again. This lead to both of the game servers that I’m running no longer being accessible by my friends.
Let’s back up a little and add some context. A couple of months ago, I decided to give hosting a small game server a shot. The first one I set up was a Terraria server and that worked splendidly!
There are 2 caveats to hosting a game server that usually cause people trouble. For one, you have to figure out how to open ports on your router and depending on your ISP, this may or may not turn out to be a challenge.
The second challenge is allowing users outside of your network to connect to the server. For that you’d usually want to share your public IP address with them. Being a web dev myself, this bothered me. Since I’ve gotten familiar with DNS servers for my local network recently, I knew that it’s possible to assign a neat domain name to the IP and use that instead of the wonky long number string.
So I set out and arranged a subdomain for one of my domains (purchased on Namecheap). I assigned an A Record to it pointing to terraria as a the subdomain and I assigned my public IP address to it. Thus terrara.my-domain.com was born and I could easily share it with my friends for them to connect to the game server.
A couple weeks passed and out of the blue I got a message that a friend could no longer hop into the server. I checked the logs and everything was running just fine. Eventually I found out that my public IP address had changed. Further investigation showed that this can happen rather randomly - based on caching on the side of my ISP or a regularly scheduled update, a power outage causing the router to restart and I am sure there’s a dozen more reasons this can happen.
Being as lazy as I am, I just went ahead and changed the IP I had assigned to the subdomain. I did not change the TTL and painstakingly waited about half an hour to see the change propagate. And that was that - the game was accessible again!
Then a week later - it happened again. What a bummer… There has to be a better way to solve this, I thought to my self. And so I came across this idea of a Dynamic DNS. This in essence changes the assigned IP to a DNS record much like how I did it the first time manually. However this happens automatically, so you no longer have to worry about it.
The setup was pretty straight forward. Since my domain is registered with Namecheap, I went with their suggested DDNS client ddclient. They even have a neat little documentation on how to configure it. One thing that I didn’t understand initially was that when you’re specifying subdomains, you have to spell out the full address including the root domain. So an example config would look like something like this:
use=web
web=dynamicdns.park-your-domain.com/getip
protocol=namecheap
server=dynamicdns.park-your-domain.com
login=yourdomain.com
password=your dynamic dns password
subdomain1.yourdomain.com
login=yourdomain.com
password=your dynamic dns password
subdomain2.yourdomain.com
The ddclient itself is running as a docker container. The example docker-compose file can be found in the corresponding wiki page.
Once the client was set up and the config was correctly filled out, I could see that the IP of the subdomain records automatically updated to the correct public IP within the Namecheap dashboard. Pretty magical!
Then I briefly changed the TTL from Automatic to 1 Minute - lesson learned. A minute later, I could check the IP of the subdomain by executing something like this:
$ nslookup subdomain1.example.com 1.1.1.1
Which returned the correct public IP that was automatically assigned by the ddclient. Then I changed the TTL back to Automatic. I noticed that when the dynamic assignment of the IP executed, the TTL had also changed to Automatic anyways.
And that’s it! All that’s left is to see if the client will correctly assign a new IP to the subdomains automatically whenever they change again.