How to Set Up Network-Attached Storage (NAS) in Debian 12 Bookworm System

Learn how to set up a network-attached storage (NAS) system in Debian 12 Bookworm.

Introduction

Network-Attached Storage (NAS) is an essential component for both home and enterprise users who need centralized file storage and easy accessibility over a network. Setting up a NAS on Debian 12 “Bookworm” provides an efficient, cost-effective, and customizable storage solution. In this guide, we will go through the step-by-step process to set up a NAS using Debian 12 with Samba and NFS for seamless file sharing across different operating systems.

Prerequisites

Before proceeding with the setup, ensure you have the following:

  • A Debian 12 “Bookworm” installed on a server or dedicated machine.
  • At least one additional storage drive for shared storage.
  • A stable network connection.
  • Root or sudo privileges.
  • Basic familiarity with Linux command-line operations.

Step 1: Update and Upgrade the System

First, update your Debian system to ensure all packages are current.

sudo apt update && sudo apt upgrade -y

Reboot the system if necessary.

sudo reboot

Step 2: Install Required Packages

To set up NAS functionality, we need to install either Samba for Windows and Linux compatibility or NFS for Linux-based file sharing.

Installing Samba (For Windows and Linux Clients)

sudo apt install samba -y

Installing NFS Server (For Linux/Unix Clients)

sudo apt install nfs-kernel-server -y

Step 3: Configure Storage Drive

Identifying Storage Device

List available disks using:

lsblk

Suppose your storage drive is /dev/sdb, you need to partition and format it:

sudo parted /dev/sdb -- mklabel gpt
sudo parted /dev/sdb -- mkpart primary ext4 1MiB 100%

Format the partition:

sudo mkfs.ext4 /dev/sdb1

Mount the partition:

sudo mkdir -p /mnt/nas
sudo mount /dev/sdb1 /mnt/nas

To make this mount permanent, edit /etc/fstab:

echo '/dev/sdb1 /mnt/nas ext4 defaults 0 2' | sudo tee -a /etc/fstab

Step 4: Configure Samba for NAS

Creating a Shared Directory

sudo mkdir -p /mnt/nas/shared
sudo chmod -R 777 /mnt/nas/shared

Editing Samba Configuration

Open the Samba configuration file:

sudo nano /etc/samba/smb.conf

Add the following at the end of the file:

[Shared]
   path = /mnt/nas/shared
   browseable = yes
   writable = yes
   guest ok = no
   valid users = @smbusers

Create a Samba User

sudo groupadd smbusers
sudo usermod -aG smbusers $USER
sudo smbpasswd -a $USER

Restart Samba service:

sudo systemctl restart smbd

Step 5: Configure NFS for NAS

Edit the NFS export file:

sudo nano /etc/exports

Add the following line:

/mnt/nas/shared 192.168.1.0/24(rw,sync,no_subtree_check)

Apply the changes:

sudo exportfs -a
sudo systemctl restart nfs-kernel-server

Step 6: Configure Firewall and Network

Allow Samba and NFS through the firewall:

sudo ufw allow 445/tcp
sudo ufw allow 139/tcp
sudo ufw allow from 192.168.1.0/24 to any port nfs

Enable the firewall:

sudo ufw enable

Step 7: Access the NAS from Clients

Accessing Samba Share (Windows/Linux)

On Windows, open File Explorer and type:

\\<server-ip>\Shared

On Linux, mount the Samba share:

sudo mount -t cifs //<server-ip>/Shared /mnt -o username=$USER

Accessing NFS Share (Linux)

Install NFS client:

sudo apt install nfs-common -y

Mount the NFS share:

sudo mount <server-ip>:/mnt/nas/shared /mnt

To make it permanent, add this line to /etc/fstab:

<server-ip>:/mnt/nas/shared /mnt nfs defaults 0 0

Conclusion

Setting up a NAS on Debian 12 “Bookworm” using Samba and NFS provides a reliable storage solution for sharing files across different operating systems. This guide covered everything from installation, configuration, and network setup to accessing shared storage. By following these steps, you can efficiently deploy a NAS system tailored to your needs.