Raspberry Pi as NAS + Media Server + VPN server

I have an old Raspberry Pi ( the first generation of Raspberry Pi model B), which has been used as my home media center for years. I installed and run libreelec which is a ” ‘Just enough OS’ Linux distribution for running the ultimate entertainment center application Kodi.” I also use Kodi remote control mobile app to control my TV. So far I have been very satisfied with this little single board computer 🙂

Comparing the sizes of my Pi Model B and a card deck

Kodi on TV

Recently I was thinking of having a home NAS to conveniently access all my medias and other files from any place, at home or not. At first I was looking at home NAS products from vendors like Asustor, QNAP and Synology like those mentioned in https://www.pcmag.com/picks/the-best-nas-network-attached-storage-devices. They all support hardware raid and also offer features like media streaming, easy to use user interface, pluggable applications and even running docker images. But thinking more about it, I don’t really want them:

  • I don’t really need RAID at home. what’s more important is backup not hot redundancy
  • Although they allow running other applications there are many restrictions.
  • They are not cheap, but hardware specs especially CPU/memory are low comparing to the prices.

Since I spend more time staying at home now ( because of covid-19) , I decided to build my own… and this is what I have come up:

Hardware:

  • 4G RAM version of the new Raspberry Pi4 , which is much more powerful than my old Pi but still has about the same price and size.
  • Some old external hard drives, and a new internal Seagate NAS harddrive plugged into a USB docking station.
My shiny Rapberry Pi4 NAS

Software:

  • OS: Rasbian. I could have just installed some NAS OS like freeNAS or Open Media Vault, but they have the same flexibility issue like the NAS devices.
  • File Services: Samba and NFS 4. Samba/SMB is actually used the most across my home network.
  • Home cloud: NextCloud. Instead of syncing my files to 3rd party providers like google I host my “own cloud” that provides dropbox-like file sync service totally under my control. client side they have web, desktop and mobile apps for both Android and iOS.
  • Media Server/Streaming: Jellyfin. it’s less polish than some other popular options like Plex but I still like the open source Jellyfin better. It also has some nice mobile apps that support casting to DLNA devices like KODI
  • .
  • VPN: Zerotier. In the past I used ssh tunnel and Shadowsocks to connect to home network when I traveled. Now it’s good time to build some real VPN with Raspberry Pi. Initially I set up WireGuard , it worked well, but it needs port forwarding on my firewall, as well as dynamic DNS ( I use https://www.spdyn.de/ which is really free unlike others), but I really don’t like opening ports on my firewall so i looked at things like STUN/TURN/UDP hole punching etc to traverse my firewall without port forwarding, until I found ZeroTier. ZeroTier allows end users to create and manage virtual software defined networks and provide tools to make enrypted peer to peer connections. ” STUN and hole punching are used to establish direct connections between peers behind NAT, direct connection route discovery is made with the help of a global network of root servers via a mechanism similar to ICE in WebRTC“. This sounds perfect as I don’t have to create my own TURN/STUN server. So I set it up and it turned out to be working very well.
  • NAS Back up: cron + the good old rsync 🙂 just a simple nightly cron job to rsync the entire NAS drive’s content over to a backup drive.
  • Other Stuff running: Nginx, MaribaDB, docker. Pi4’s hardware is powerful enough to be used as a minimal web server. not hosting anything yet but maybe some of my pet projects in the future 🙂

Now I don’t have ports opened on my firewall, and wherever I go I can still browse and play my media files through Jellyfin or have my newly taken pictures on my cell phone automatically backed up to my home NAS via NextCloud as long as there is internet connection. This entire set up costs about $200 (Rasberry Pi 4 + case + accessory + hard drive).

Cheers!

About: mmpower

Software Architect & Soccer Fan 黑超白袜 = IT 民工 + 摇滚大叔


5 thoughts on “Raspberry Pi as NAS + Media Server + VPN server”

  1. looks great!
    I have been trying to the same.this is helpful. thanks a lot

  2. you are actually a good webmaster. The website loading velocity is amazing. It seems that you are doing any distinctive trick. In addition, The contents are masterpiece. you’ve done a excellent process on this subject

  3. I was just looking for this info for a while. After 6 hours of continuous Googleing, finally I got it in your web site. I wonder what’s the lack of Google strategy that do not rank this type of informative websites in top of the list. Generally the top web sites are full of garbage.

  4. After the recent Western Digital MyBookLive hack which erased SOME of my NAS files {nothing critical fortunately} I am looking for something just like this with a VPN/NAS that I have more direct control over access. I know this article is a little old but is there anything you would change?

    Thanks

Leave a Reply

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