A NAS (network-attached storage) server is very useful for storing and distributing data on a local network. In this post, I am going to show you how you can create your own ubuntu NAS server.
In order to run our own NAS server we obviously first need a server. Go ahead and install the an ubuntu server on a free device. The ubuntu install instructions are very simple, you should be able to follow them and have a running server in less then an hour. I suggest using the non GUI server, at least that's what I am assuming you will have in this tutorial. It does work with the desktop server as well though.
Once that is all set up, we are going to install some packages we will need to for the NAS server. First, let's go ahead and install a better package manager called nala.
sudo apt install nala
Once that is done, we call nala
instead of apt
to install packages.
Let's go ahead and use it to install a text editor.
sudo nala install vim
You should see a much cleaner visual for the installing process.
While it would be totally fine to use apt
,
you benefit from using nala
as it not only looks
a lot better and is more readable, but it also has quite a few
features (like undoing installs and properly purging packages).
With all of this setup complete, we can finally begin to setup our NAS server. To start we will make our private IP address static. Every device in your local network has a private IP address which your internet router uses to know which data package needs to go where. These private IP addresses can change when you for example change your router. This is not a problem for most cases, but when using a NAS server we will access our server through the private IP address. So we are going to need to make the private IP address static.
First of all we will need to figure out the private IP address of our server. We do this by simply running the following command.
ip addr | grep inet
This should output something similar to this.
inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host inet 192.168.178.98/24 metric 100 brd 192.168.178.255 scope global dynamic enp3s0 inet6 fd00::226a:8aff:fe28:7bce/64 scope global dynamic mngtmpaddr noprefixroute inet6 fe80::226a:8aff:fe28:7bce/64 scope link
My server has a private IP address of
192.168.178.98
. Yours will be different
but will probably also start with something like
192.168
.
We are also going to need to know the network interface of our server. To achieve this, simply run this command.
ip link
Something like the following output should be displayed.
My network interface is enp3s0
, yours will be similar.
Note that en
stands for ethernet here, so if your server
is using that it should start with the prefix en
.
If you are using wifi (on a laptop for example), then it will start
with w
, in my case I have the interface wlp6s0b1
which is indeed a wifi port (I am using a laptop as a server).
1: lo:mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: enp3s0: mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000 link/ether 20:6a:8a:28:7b:ce brd ff:ff:ff:ff:ff:ff 3: wlp6s0b1: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 18:f4:6a:be:c4:d7 brd ff:ff:ff:ff:ff:ff
Now we can use our private IP address and turn it into a static one.
To do this, we will create the file /etc/netplan/01-network-manager-all.yaml
with the following content.
network: renderer: networkd ethernets: enp3s0: addresses: - 192.168.178.98/24 nameservers: addresses: [192.168.178.1, 8.8.8.8] routes: - to: default via: 192.168.1.98 version: 2
Here you obviously need to replace the private IP address and the network interface with your own.
Note that 8.8.8.8
is a public google domain used as a fallback.
The only thing left to do is to update the netplan.
sudo netplan apply
Next we are going to use samba to handle the actual connection of users to our server storage. We start off by installing samba.
sudo nala install samba sudo systemctl status smbd
smbd.service - Samba SMB Daemon Loaded: loaded (/lib/systemd/system/smbd.service) Active: active (running) since Sun 2023-10-22 12:46:40 UTC ...
Running this command should show you that samba is now active. I cut out the rest of it as it's not important, but if nala is inactive or there were some errors then you should check the rest of the output. You may need to reboot your server, nala will tell you in that case.
Once you made sure samba is running we are going to configure it.
Open the file /etc/samba/smb.conf
with the editor of
your choice (I am gonna use vim which we installed previously).
sudo vim /etc/samba/smb.conf
Place the following content at the end of the file. Allow me to explain what these terms mean.
[first-nas-folder] comment = My very first nas folder path = "/home/user/folder" guest ok = no browseable = yes create mask = 0777 directory mask = 0777 writable = yes read only = no
You can configure as many entries as you want.
Let's say you would like to create another entry just for movies,
then you could add the following to your smb.conf
.
Note that the mask 0777
means that everybody
that has access to the server has read and write access.
[movies] comment = Movies Only Share path = /home/user/movies-folder guest ok = no browseable = yes create mask = 0777 directory mask = 0777 writable = yes read only = no
The final step we need to do is to add samba users. This will allow users to connect to our server using the credentials we will specify now. First, create a new user.
sudo useradd my-new-user
Then we will add the user to samba. It will prompt you to create a password for this user. Note that the person who is going to use this account on their desktop OS will need this password in order to connect to the NAS server.
sudo smbpasswd -a my-new-user
Finally let's apply our changes to samba by running the following two commands.
sudo ufw allow samba sudo systemctl restart smbd
That's it! Your NAS server is all set up now. The only thing left to do is to connect to it from your desktop OS. I created a separate tutorial for that as this one is already quite long, you can read it here.