Remote Access To Your RPi

In my professional life I am often working away from home, one of the things I like to do is remotely access my Rapberry Pi, or even my Mac to work on personal projects.  For a while I have just been accessing the resources using some dynamic DNS hosts but I keep forgetting the URLs they provide.  This post provides details on how to configure your network and domain name to provide an easy to remember url for accessing resources in your network.

Setting Up Your Address

As with most personal users my ISP provides me with a dynamic IP address, whilst this is cheap for me it isn’t particularly convenient when trying to access devices within my network, to over come this we can use a Dynamic DNS service from one of the free providers.

In this example I have set up an address with www.dnsdynamic.org, however to receive a free account I need to use a sub-domain from a number of domains that they provide, this is where my memory fails me as I cannot remember the domain name and have to always look it up.  This isn’t much of an issue but I like my life to be easy and to access my servers using sub-domains from my own domain.

Step 1 – Create a dynamic DNS account

Create an account at www.dnsdynamic.org and follow the instructions, once your account is validated you can add your personal sub domain, choose what you like, you won’t need to remember it so it can be as random as required.

You will now have a domain name which points to your public facing IP address.

Step 2 – Keeping your IP address up to date

In order to keep your new domain name pointing at your public IP we need to use a client which will update the dynamic dns records periodically with your current IP address (as this is changed periodically by your IPS).  To do this we will install a client that will run in the background

Install Dynamic DNS Client

Log into your pi console

run:

sudo apt-get install ddclient

This will install the dynamic dns client for use from your RPi.

Once the client is installed you will be asked to enter the settings for your dynamic DNS service, we will override these so don’t worry about the settings here.

Once ddclient is installed run the following command to view the config file:

sudo nano /etc/ddclient.conf

Configuring Dynamic DNS Client

Now update the config file as per the below example


 daemon=60                               # check every 60 seconds
 syslog=yes                              # log update msgs to syslog
 mail=root                               # mail all msgs to root
 mail-failure=root                       # mail failed update msgs to root
 pid=/var/run/ddclient.pid               # record PID in file.
 ssl=yes                                 # use ssl-support.  Works with
                                         # ssl-library
 use=web, web=myip.dnsdynamic.com        # get ip from server.
 server=www.dnsdynamic.org               # default server
 login=<login>                           # default login
 password=<password>                     # default password
 server=www.dnsdynamic.org,              \
 protocol=dyndns2                        \
 <subdomain>

Press Ctrl+X to save and exit the editor.

Setting <login>, <password> and <subdomain> to your dnsdynamic account details.

Now that the service is configured we want to ensure that it runs correctly, to do this run the following command:

sudo /usr/sbin/ddclient -daemon=0 -noquiet -debug

You should see some DEBUG messages.

Running at startup

Obviously we don’t want to have to restart the service every time so we need to configure the service to start automatically, to do this run this command:

sudo update-rc.d ddclient defaults

We now have the client running on startup to maintain our dynamic DNS address.

Step 3 – Configuring Our Domain

We now have a url that will always be updated to point at our networks public IP address, but these urls aren’t always easy to remember, therefore lets use our own domain.

Log into your domain administration site and select the option to manage your Name Servers,  here we need to set up a new sub-domain and configure this to point at your dynamic dns address.

I have created the following:

Domain: rpi.mydomain.com

RecordType: A

IP Address or Fully Qualified Domain Name: <your dynamic dns address>

Once these changes have propagated, this can take a few hours you should be able to access your public IP Address using subdomain.yourdomain.com.

Step 4 – ConfiguringYour Router\Firewall

In order to allow traffic into your network you will need to perform the following activities, I will not cover this here as you need to understand what you are doing and if you get it wrong you could expose your network to unwanted traffic.  What is required is:

– open firewall ports to allow traffic access on specific ports

– Network address translation, to map ports to specific devices (each port will need to be added to your firewall)

You should now have an easy to remember address to access devices within your domain.

To set up your Raspberry Pi for remote management see an earlier blog post on accessing your RPi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.