Hi folks - using MIAB to host my personal domains and absolutely love it! One thing I needed a little help with was some dynamic DNS capabilities…
Long story short - MIAB hosts one of my domains for email & web, but I wanted to have a subdomain I could use to access my VPN & NAS servers at home.
So, I wrote a shell script that runs on my pfSense gateway at home, which updates the subdomain records on the MIAB.
For Example:
box.mydomain.com (my MIAB) / IP address 1.2.3.4 hosts:
www.mydomain.com
mail.mydomain.com
But I want vpn.mydomain.com and nas.mydomain.com to point to 5.6.7.8 (which is my home, dynamic IP).
So I run the attached shell script via cron on my pfSense gateway, and it will update the vpn.mydomain.com and nas.mydomain.com entries on the MIAB whenever my IP address changes.
Make sense?
Hope this is useful for someone – it is for me!
Thanks,
–Dennis
--------- CONTENTS OF dm-dyndns.sh below ---------
#!/bin/sh
# dm-dyndns v1.0, dmurphy@dmurphy.com
# Shell script to provide dynamic DNS to a mail-in-the-box platform.
# Requirements:
# dig installed
# curl installed
# OpenDNS myip service availability (myip.opendns.com)
# Mailinabox host (see https://mailinabox.email)
# Mailinabox admin username/password in the CFGFILE below
# one line file of the format (curl cfg file):
# user = “username:password”
# Dynamic DNS name to be set
# DYNDNSNAMELIST file contains one hostname per line that needs to be set to this IP.
MYNAME="dm-dyndns"
CURRENTIPFILE="$MYNAME.ip"
CFGFILE="$MYNAME.cfg"
DIGCMD="/usr/local/bin/dig"
CURLCMD="/usr/local/bin/curl"
CATCMD="/bin/cat"
DOMAIN="mydomain.com"
MIABHOST="box.$DOMAIN"
DYNDNSNAMELIST="$MYNAME.dynlist"
if [ ! -x $DIGCMD ]; then
echo "$MYNAME: dig command $DIGCMD not found. Check and fix please."
exit 99
fi
if [ ! -x $CURLCMD ]; then
echo "$MYNAME: curl command $CURLCMD not found. Check and fix please."
exit 99
fi
if [ ! -x $CATCMD ]; then
echo "$MYNAME: cat command $CATCMD not found. Check and fix please."
exit 99
fi
if [ ! -f $CFGFILE ]; then
echo "$MYNAME: $CFGFILE not found. Check and fix please."
exit 99
fi
if [ ! -f $DYNDNSNAMELIST ]; then
echo "$MYNAME: $DYNDNSNAMELIST not found. Check and fix please."
exit 99
fi
MYIP="`$DIGCMD +short myip.opendns.com @resolver1.opendns.com`"
if [ -z "$MYIP" ]; then
echo "$MYNAME: dig output was blank. Check myip.opendns.com services."
exit 99
fi
for DYNDNSNAME in `$CATCMD $DYNDNSNAMELIST`
do
PREVIP="`$DIGCMD +short $DYNDNSNAME @$MIABHOST`"
if [ -z "$PREVIP" ]; then
echo "$MYNAME: dig output was blank. Check $MIABHOST DNS server."
exit 99
fi
if [ "x$PREVIP" = "x$MYIP" ]; then
echo "$MYNAME: $DYNDNSNAME hasn't changed."
else
echo "$MYNAME: $DYNDNSNAME changed (previously: $PREVIP, now: $MYIP)"
STATUS="`$CURLCMD -X PUT -K $CFGFILE -s -d $MYIP https://$MIABHOST/admin/dns/custom/$DYNDNSNAME`"
case $STATUS in
"OK") echo "$MYNAME: mailinabox API returned OK, cmd succeded but no update.";;
"updated DNS: $DOMAIN") echo "$MYNAME: mailinabox API updated $DYNDNSNAME OK.";;
*) echo "$MYNAME: other status from mailinabox API. Please check.";;
esac
fi
done
exit 0