Reinventing dynamic DNS

August 18, 2018

Categories: System Tags: Linux Networking

It is so much simpler when you I am on a globally routable machine. I can run my webserver, host my own blog, share directories with ease, ssh into my machines from outside and so on. This isn't to say private networks are a bad idea. But for them to be pervasive has very little to do with shortcomings of IPv6, I suspect. Be that as it may, you do have number of strategies to circumvent the NAT when you need to.

Firstly, there is this handy technique known as reverse SSH tunneling. It's an easy solution albeit requires having another (relay) host running. I mean there are services that allow you to use their hosts (ngrok, but they are either non-free, untrusted or the connection simply isn't stable enough. The other solution is to just use dynamic DNS (assuming you are allowed to do port forwarding). But as luck would have it, my paid domain expired and the free DDNS service that I use also went down (duckdns).

But really though, all you need is someplace accessible (and writable by you) where you can store just the IP, and then update it when needed. I mean, it could be a git repo? Or you could mail yourself, or in my case I just used a pastebin service that allowed me to edit programmatically.

Next up, do we poll for change in IP with some interval? The point behind this post is to let you know that if you are using a DHCP client (more likely, who isn't?), then you can take advantage of the fact that it provides an event based hook interface that lets you run your custom script when an event triggers. I got the impression that it's used much less in the wild than it should be. The way the interface works would not be unfamiliar to you if you have experience with other daemons such as acpid or udevd. The hooks are run in the current shell context as opposed to in a new process, which means relevant information already exists in variables leading to concise hooks, and also that you can dictate the control flow of hooks down the chain from above. But anyway, this is what simply did the trick:


case "$reason" in
        sh /home/natrys/bin/

Whereas you can define your in many ways, mine looks like:


curl -s | curl -s --netrc-file /home/natrys/.netrc -F 'f:1=<-' -X PUT${IXID}
polybar-msg hook pub_ip 1

I don't think a few updates a day can be stressful to It provides a neat service, and I like that one can use classic .netrc file to authenticate. Anyway, as a bonus here is the simple polybar module:

type = custom/ipc
format-underline = #0a6cf5

hook-0 = curl 2>/dev/null || echo "No Internet"
initial = 1

click-left = polybar-msg -p %pid% hook pub_ip 1