In my previous post, I talked a little bit about options for being able to SSH into your home machine from anywhere. In this post, we’ll get into the details of my specific configuration, using the free ddclient tool for Linux, and a subdomain of a paid domain name with Namecheap.
On our paid domain, which we will call “mydomain.net”, we’re going to add a subdomain that will point to our Linux box. That way, we can just SSH to “dynamic.mydomain.net” to reach our Linux box from outside our home network.
You could make “mydomain.net” itself be your dynamic DNS URL if you really wanted to, but the point here is to re-use a domain you’re already paying for to host a website, as opposed to relying on free services.
Go into Namecheap (or whatever you’re using), and drill down into the settings for mydomain.net. Go to Show All Records, and add an A record for 127.0.0.1. Yes, that’s localhost. It’s just a placeholder for now—when we’re all done it’ll be continuously updated to our home machine’s real IP.
Next, apt-get install ddclient. ddclient is a simple command-line tool that will update the subdomain you just set up every so often, with your home machine’s current IP address. That way, the subdomain will always point to the right place. It was originally written for the popular DynDNS service I mentioned before, but now works with anything, including Namecheap.
We’ll need to configure ddclient now, so edit its config file:
sudo nano /etc/ddclient.conf
My /etc/ddclient.conf looks like this:
# Configuration file for ddclient generated by debconf
The use= line tells ddclient to first find out your public IP from a what-is-my-IP service run by DynDNS. It’s kind of curious that they still have that on and available to the public, while they discontinued their free dynamic DNS service. Also, you’d think you’d be able to figure out your public IP WITHOUT contacting an external website to do so, but I looked into it and it’s more trouble than it’s worth. If it bothers you that much, maybe look into whether or not your router has dynamic DNS updating built in.
Use the following command to test out your ddclient config, otherwise it will just fail silently and not give you error messages:
sudo ddclient --debug --verbose
If you try to ping dynamic.mydomain.net, and the response comes from localhost, it means ddclient never updated your IP, and your configuration is probably wrong somehow.
In my case, the ddclient service seems to be already running automatically on startup. You can check if it’s running or not with:
service ddclient status
If all goes well, you should be able to ping dynamic.mydomain.net and get the IP of your home machine! Just make sure you’re doing it from OUTSIDE your local network when you try it. I find a good way to do this is to take my phone off of my home wifi, and try to SSH in over LTE.