NAS on Debian

A few months back, I decided I should have my files and media backed up on something better than a couple flash drives. The concept of having a NAS connected to my network that all my internal network devices could connect with was very appealing. However, I had some trouble in picking out which style of NAS to go with.

Pre-Packaged Solution

Amazon/Newegg sell a variety of pre-packaged NAS solutions. However, these typically run proprietary software which I’m not a fan of. I’d also really prefer to avoid needing to talk to an outsourced tech support hotline when I eventually need to restore a RAID array. Also, they typically lacked the number of drive bays that I wanted to have.

Installable Operating System

I saw an ad TrueNAS on big Linus’ show some time before. Its web interface was appealing since I would be able to set everything up in a more guided fashion. Also, using a system that is also used by some enterprise customers made me feel like it could be more stable than a platform I made on my own, especially for managing updates.

Build Your Own

Of course, there’s always the option of making your own NAS. However, when I was getting started, I thought this option would be more work than it had benefits.

I eventually decided install the TrueNAS system on custom-built hardware. All-in-all, the hardware cost ~$1,000. I was able to set up 6 6TB drives with OpenZFS’s raidz2 pretty easily using the TrueNAS web UI. I had some trouble managing permissions but all-in-all, the install went great. My computer was backed up using rsync and I had all my files on my own hardware.

Update Failed

However, the first time I clicked the update button using TrueNAS, it destroyed its network configuration. I was unable to connect to it through SSH or the web app. The data was not lost but I would have had to re-install the ISO in order to continue use TrueNAS on the machine.

Instead of doing that, I decided to put Debian on the NAS instead and build my own solution. It ended up being a much simpler setup (although it did still take a few hours to come up with). The rest of this article is my notes from setting up a NAS on debian:

OS Install

Install Debian via ISO

Enable nomodeset flag from GRUB

Initial Setup

Install sudo and give to unprivileged user

Install htop for process monitoring

Install nload for network monitoring

Ensure system is in proper timezone (important for predictable crontab setup later)

SSH Configuration

Disable password authentication in /etc/ssh/sshd_config

Port Forward 22 (for external SSH)

ZFS Setup

Install ZFS

Mount ZFS RAID Pool

Remove TrueNAS .system Datasets

Sync Setup

Install rsync

Install Sync PC -> NAS

Install Sync NAS -> Family NAS scripts

Install cronjob tasks

# min hour  dom mon dow   command
@reboot                   sleep 15 && $HOME/scripts/update-beefslab-ip.sh >> $HOME/logs/update-beefslab-ip.log
  0   0     *   *   *     $HOME/scripts/update-beefslab-ip.sh >> $HOME/logs/update-beefslab-ip.log
  10  0     *   *   *     $HOME/scripts/update-known-hosts.sh >> $HOME/logs/update-known-hosts.log
  15  0     *   *   *     $HOME/scripts/sync-to-family.sh

Hardening

From one month of installing fail2ban, I have blocked almost 1,000 IPs of bots / scanners