NAS, or network-attached storage is rapidly becoming the choice of both personal users and businesses when it comes to effective data sharing and data management solution. NAS system is simple to operate, low-cost, offer easy and centralized data backup while providing 24/7 access to important information.
If you build a NAS yourself, at some point you will have to decide which operating system to install to it. We've covered a list of the best open-source NAS software and dedicated OS, but what if you want to use an OS you're already familiar with?
This article is going to show you how you can install and set up a NAS box powered by Ubuntu.
Most of the time, a NAS box can be built out of modest hardware components. You can recycle an old PC for the purpose, or buy a ready-made, low-power ARM box like Kobol.
Here's a minimum hardware reference for a NAS serving 1-4 users if you don't really know where to start.
- Single-core CPU, >=2.0GHz clock rate
- At least 2GBs of RAM
- At least 8GB flash drive to run the OS or a SSD for better performance.
- Wired, stable connection
- A few high capacity hard drive to store the actual data in RAID mode.
- Small-sized flash drive to create a bootable Ubuntu storage device.
Although a flash drive can be used to run the operating system, you should instead use an SSD for the purpose. Flash storage devices such as SD cards and flash drives tend to wear out over time, causing minor data loss which may lead to strange errors, especially after an OS update (huge amount of disk input/output). In my case, I found that sometimes Ubuntu refuses to boot up because of GRUB errors after doing a full security update for the kernel.
As per the software, obviously we will use Ubuntu.
At the time of this writing, the latest stable version is Ubuntu 20.04.2.
The majority of user interaction will be made using web-based GUI or through SSH tunnels. The NAS should run without any supervisor as a headless server, without keyboard or monitor connected.
Therefore, Ubuntu Server is a better choice than the usual Ubuntu Desktop because it's more lightweight and doesn't ship with desktop environments and unnecessary GUI applications.
If you're installing the server OS into a flash drive, disconnect all hard drives to avoid system confusion. You can skip this step if you're installing the OS to a HDD or SSD.
When the installer asks for which optional system components to install, you have to choose SSH Server (to enable SSH access) and Samba (to enable file access).
Once you've got Ubuntu installed, shutdown the computer, reconnect all hard drives, and then switch the machine back on.
Login with your Username and Password when the login screen appears, as we move on to the next part.
Set up static IP and networking
Before setting up anything, let's ensure our system is updated with the latest software by running
sudo apt-get update sudo apt-get upgrade
The first thing we have to do is to set a static IP address to the NAS box, so we can access it from other computers in the network, and later from the internet.
A static LAN-only IP address can be set from the DHCP server (usually by editing your router configuration). Your IP will be automatically assigned by the DHCP server based on the MAC address.
If you don't have access to the DHCP server, or prefer to have all configuration details stay on the NAS box, edit
/etc/network/interfaces by running
sudo nano /etc/network/interfaces
You have to change
eth0 (or your ethernet interface) configuration to what's shown below :
Code language: CSS (css)
iface eth0 inet static address 192.168.1.100 network 192.168.1.0 netmask 255.255.255.0 broadcast 192.168.1.255 gateway 192.168.1.1 dns-nameservers 22.214.171.124 126.96.36.199
In the configuration, the static IP address is
192.168.1.100 and DNS server is set to Google DNS address
Set up RAID
RAID (Redundant Array of Independent Disks) is a storage virtualization technology that combines multiple physical disk drive components into logical units.
A NAS should have more than one hard drive and configured under a RAID array to make the most out of them. But that's not to say you have to have multiple hard drives. Skip this part if your NAS box only has one HDD.
The biggest advantages of RAID is data protection against physical errors, for example, sector read errors or disk failures.
For more information about RAID and what RAID mode should you choose, see Wikipedia.
In case you decide to use RAID, install mdadm by running the following command:
sudo apt-get --no-install-recommends install mdadm
--no-install-recommends to avoid installing
default-mta, which set up a new mail agent we don't really need.
Details about how to configure
mdadm depends on your hardware and out of the scope of this post. If you want a step-by-step guide, check out How To Create RAID Arrays with mdadm.
Mount the hard drive (optional)
If you choose not to set up RAID or you have one hard drive only, you would have to mount it to the system.
Let's suppose we have a single disk drive and want it to be available at
/mnt/hdd1, run the following commands
sudo mkdir /mnt/hdd1 sudo chown -hR $(whoami):$(whoami) /mnt/hdd1
The next thing we have to do is edit
/etc/fstab file and include the new path so that our disk drive will be recognized the next time we restart.
Run the following command and take a note of the ID number of the disk drive you want to automatically mount.
Having the correct disk ID, we now edit
sudo nano /etc/fstab
Then we add a new line to the end of
/etc/fstab so that the system knows what to mount and where.
UUID="ID From blkid" /mnt/hdd1 ext4 rw,user,auto 0 0
You would be accessing files on the NAS box through Samba or NFS protocols.
Network File Sharing (NFS) is a protocol that allows you to share directories and files with other Linux clients over a network. Shared directories are typically created on a file server with NFS server component installed. A NFS file share is mounted on a client machine, making it available just like folders the user created locally.
On Ubuntu, you would install NFS server by running:
sudo apt install nfs-kernel-server
We’ll now create the root directory of the NFS shares, this is also known as an export folder. In order to do that, need to edit
sudo nano /etc/exports
We'll be sharing the whole mounted disk at
/mnt/hdd1, so we have to add the following line to the end of
You can now make the shared directory available to clients using the
exportfs command. Restarting the NFS service after that to make the changes take effect.
sudo exportfs sudo systemctl nfs-kernel-server restart
Samba allows you to share files via the SMB network protocol. Basically this means file and print services for various Microsoft Windows clients and integration with a Microsoft Windows Server domain.
First you need to install
smbfs by running.
sudo apt-get install samba smbfs
After the installation is done, edit
/etc/samba/smb.conf to include settings for the share folders. In the example, we're sharing
/mnt/hdd1 with both read and write permission.
Code language: PHP (php)
# NAS share directory [NASShare] comment = anything_will_do path = /mnt/hdd1 read only = no guest ok = yes
Finally, restart Samba services for the changes to take effect.
sudo systemctl restart smbd
That's it, now you're able to access your NAS from both Linux and Windows, using its IP address.
Assign a nice URL to NAS IP
You can assign a nice, locally-accessible domain for your NAS IP address by adding a line into
/etc/hosts file (suppose you're accessing your NAS box from a computer running Linux)
Code language: PHP (php)
echo -e "192.168.1.100\t nas.box" | sudo tee -a /etc/hosts
\t represents tab character
tee -a appends the line above to the file.
From now on, on your client machine you can access the NAS box either by specifying its IP address or
In case you want to monitor and change the NAS box settings and configuration easier, you can install Webmin - a web-based GUI Linux manager. Cockpit is an alternative to Webmin, sponsored by Red Hat.