Headless home server - Setting up Dynamic DNS (FreeDNS) and IPv6 tunnel (HE.net)
Every time I install a PlugComputer I setup a Dynamic DNS service so that I can access it's shell and apps/services from the Internet easily.
My preferred Dynamic DNS service is FreeDNS which is very easy to install and setup. Plus, it's working on FreeBSD servers :-P
Setting up an account at FreeDNS is fairly simple and it is also simple to setup a subdomain in the form of an A NAME with them.
A subdomain is basically something that looks like aname.domain.com . Whatever!
So after setting up your A NAME, you need to configure the headless server so that it frequently checks your public IP address. If it has changed from the last time it checked, it then has to register the new public IP address with your A NAME.
Most Dynamic DNS services make this easy for us in the form of a URL that we can visit. And since the headless server doesn't run a proper web browser we can use WGET.
Frequent checks are configured in the form of a script that is run every, say, 5 minutes.
Here is the script:
If it has changed, it sends two WGET entries. One of them connects the A NAME with the new public IP address. The other one sets my Tunnelbroker IPv6 tunnel public IP address. My tunnel can only be setup from this public IP address (security :D).
This is how the script looks like (iproute2 commands):
My preferred Dynamic DNS service is FreeDNS which is very easy to install and setup. Plus, it's working on FreeBSD servers :-P
Setting up an account at FreeDNS is fairly simple and it is also simple to setup a subdomain in the form of an A NAME with them.
A subdomain is basically something that looks like aname.domain.com . Whatever!
So after setting up your A NAME, you need to configure the headless server so that it frequently checks your public IP address. If it has changed from the last time it checked, it then has to register the new public IP address with your A NAME.
Most Dynamic DNS services make this easy for us in the form of a URL that we can visit. And since the headless server doesn't run a proper web browser we can use WGET.
Frequent checks are configured in the form of a script that is run every, say, 5 minutes.
Here is the script:
##############################################################################And here is the crontab entry:
#
# application name: dnsactual
# other files: dnsactual.conf (keeps the last updated ip)
# dnsactual.log (register date & time of the actualization)
# Author: Ernest Danton
# Date: 01/29/2007
# Date: 22/08/2013 (minor tweaks by Rui Correia)
##############################################################################
if test -f /etc/freedns/dnsactual.conf
then
CacheIP=$(cat /etc/freedns/dnsactual.conf)
fi
#echo $CacheIP
CurreIP=$(wget http://freedns.afraid.org/dynamic/check.php -o /dev/null -O /dev/stdout | grep REMOTE_ADDR | cut -d : -f 2 | cut -d '<' -f 1 | tr -d " ")
#echo $CurreIP
if [ "$CurreIP" = "$CacheIP" ]
then
# Both IP are equal
#echo "Check. Update not required."
echo `date` "Check. Update NOT required." >> /var/log/dnsactual.log
else
# The IP has change
#echo "Check. Update required. New IP is " $CurreIP
wget http://freedns.afraid.org/dynamic/update.php?_MY_FREEDNS_API_KEY_GOES_HERE_ -o /dev/null -O /dev/stdout
wget -q --no-check-certificate "https://ipv4.tunnelbroker.net/ipv4_end.php?ipv4b=AUTO&pass=_MY_IPV6_API_PASSWORD_GOES_HERE_&user_id=_MY_IPV6_API_USERNAME_GOES_HERE_&tunnel_id=_MY_IPV6_TUNNEL_ID_GOES_HERE_" -O -
echo `date` "Update required. New IP is " $CurreIP >> /var/log/dnsactual.log
fi
rm -f /etc/freedns/dnsactual.conf
echo $CurreIP > /etc/freedns/dnsactual.conf
*/5 * * * * sleep 15 ; ./ipv4renew-freedns.shThe script checks the public IP and stores it in a file "/etc/freedns/dnsactual.conf". Every time is runs, it checks if the current IP is the same as the previous IP. If it's the same nothing is done except a log entry in "/var/log/dnsactual.log".
If it has changed, it sends two WGET entries. One of them connects the A NAME with the new public IP address. The other one sets my Tunnelbroker IPv6 tunnel public IP address. My tunnel can only be setup from this public IP address (security :D).
This is how the script looks like (iproute2 commands):
modprobe ipv6And a crontab entry for the IPv6 tunnel as well:
ip tunnel add he-ipv6 mode sit remote 216.66.84.42
ip link set he-ipv6 up
ip addr add 2001:470:1f12:73b::3/64 dev he-ipv6
ip route add ::/0 dev he-ipv6
ip -f inet6 addr
*/5 * * * * sleep 15 ; ./ipv6setup-tunnelbroker.sh
Comments
Post a Comment