If you’ve got some unused external drives lying around or if you’re just looking for a convenient way to access your files from anywhere you can follow along this guide to turn your Raspberry Pi into a Network Attached Storage.

The things you need to do are outlined below:

Give your Pi a static IP-address (+DDNS) Automatically mount the drives to the Pi Install the software needed under Windows Add some extra features (drive syncronisation, …)

We are going to use SFTP (FTP over SSH) to access our files. This makes the configuration of the Pi easy, since with Raspian it already has a SSH server running on it.

So let’s start with our first step of configuration:

Give Pi a static IP (+DDNS)

We need a static IP for the Pi so we can always reach it under the same address. This is important since we’re using SSH for file access. I’ve already explained one way to give your Pi a static IP in another post. Alternatively you can also configure it in the settings of your router.

With this static IP we can always reach our Pi in the local Network. The next step is to configure some kind of “static” public IP for your router so we can access it from everywhere. The problem here is that your public IP will change in certain intervals depending on your internet provider. Therefor we need an external service that takes care of these changes. This is called DDNS (Dynamic DNS). You send your public IP regularly to the DDNS service and the DDNS service gives you a domain name with which you can access your local network.

Which DDNS service you want to use depends on which ones your router supports and your personal preferences. In this guide I’m going to explain the process to update your IP with the Pi because this method always works, regardless of the router you have.

The service we’re going to use is ddnss.de as it is completely free and seems to be quite reliable.

First you have to create useraccount on ddnss.de. If you’ve done that you can go ahead and choose the domain you want to use.

Next we need to make sure that the Pi sends the public IP of the router to ddnss.de in regular intervals. We can do that by composing an update-link with a bash script (click link to download script) which we run automatically every 6 minutes. On linux this can be achieved with an entry in the crontab (a so called cronjob). Open up the crontab file with the command crontab -e .

The cronjob should look similar to this (output can be piped into a log-file):



*/6 * * * * cd /home/user && bash ddupdate.sh > log.txt



In the logfile you can check if the cronjob works. Also don’t forget to make the bash script executable:



chmod +x home/user/ddupdate.sh



When you’re done with that you have to configure port-forwarding in your router settings so that the router knows to which port and IP-address it should redirect ssh-requests from outside.

This process highly depens on your router, so I won’t explain it in detail here. Just ask google if you need help.

Auto-mount drives to Pi

With the network configuration set up correctly, we can now go on with mounting the drives to the Pi automatically each time the Pi boots. Here it is important to use the UUID of the drives, so we can ensure that we always mount the same drive in the same directory.

To get the UUID we use the command blkid which lists all connected storage devices. Copy and Paste the UUID of the drives somewhere.

Next we have to edit the /etc/fstab file which will automatically mount our drives. Go ahead and open it with nano: nano /etc/fstab

Add the following line at the end of the file:



UUID=XXXX-XXX-XX /media/name_of_drive ntfs-3g defaults 0 0



It is important to include an empty line at the end of the file because otherwise you’ll run into errors.

Now reboot the Pi and check if the drives are mounted correctly.

Install software on Windows

To add those drives to our Windows Explorer so that we can use it like normal drives we need a special software (win-sshfs). This software again needs a set of drivers (Dokan) which we have to download in advance. Both are open-source, so go ahead and download them.

The Drivers can be downloaded here. (vers.: 0.7.3-RC)

And the software can be found here. (tested vers.: 1.5.12.8)

When you’ve installed the software you can add the drives by using the domain you’ve got from ddnss.de or with the local IP address of the Pi.

Extra feature (drive sync)

A nice additional feature for your NAS is automatic syncronisation of two drives. This way you can backup one drive in case it breaks or some files on it get broken.

To achieve this we use a linux tool called rsync and again crontab to schedule the backup processes.

Open up your crontab file with the command crontab -e .

The cronjob you add should looks similar to this one:



30 5 * * * rsync -av --delete /media/1/shares /media/2/shares/



To make your NAS ready to use you should of course change the default root- and user-password to make it more secure.

If you’ve done that your NAS is ready to use!