It’s gonna be a quick birthday post today. I have
previously posted
on this blog about my self-hosted OpenBSD server that powers
this site. One feature I have come to really love is the
daily(8) system, by which I can
write shell script that runs each day, with the output being
mailed to my inbox.
One issue I have with my server is my dyanmic IP. It is
quite uncommon, but every 6–8 months my IP address changes,
and my site goes down until I reconfigure my domain with my
domain registrar. This can be quite annoying, not because
it is difficult, but because I don’t actually know
when my IP has changed until I try to access my site some
day and see it’s down. Luckily with the power of
/etc/daily.local, this is easy to solve:
#!/bin/sh
# …
next_part "IP changed:"
readonly ADDR=132.136.178.174
addr="$(dig +short myip.opendns.com @resolver1.opendns.com)"
[ "$addr" != "$ADDR" ] && cat <<-EOF
$ADDR (old)
$addr (new)
EOFWith this simple script in place, I now get an email in my inbox whenever the public IP address of my server changes. Maybe there are better, automated ways of doing this, but like all sysadmins, I’m lazy as fuck.