If you have an old PC, mini PC, or spare laptop sitting around, one of the most useful ways to reuse it is to turn it into a storage NAS. With Ubuntu, the cleanest setup is to split the job into 2 layers:
- Samba for local network sharing
- WebDAV for remote or public file access
That is much safer than trying to expose SMB directly to the Internet. Samba is great on a LAN, but it is not something you should open to the public Internet.
When is this setup worth using?
This model works well if you need:
- a shared place for desktops, laptops, and phones
- media or backup storage at home
- somewhere to keep ISOs, archived projects, camera data, or photos
- a controlled way to access files from outside
It is especially useful for:
- old PCs that still work fine but are not ideal for heavy virtualization
- machines with a few spare HDDs
- a simple family or homelab file server
Quick conclusion first
If you only want the short version:
- install Ubuntu Server
- mount the storage disk properly
- enable Samba for LAN access
- do not expose Samba to the Internet
- use WebDAV over HTTPS for remote access
- separate internal folders from public folders
That structure is easier to maintain and much harder to misconfigure dangerously.
Recommended architecture
Instead of using one protocol for everything, split the roles:
Samba/SMB: for devices on your local networkWebDAV: for remote access or controlled public sharing
A practical layout:
/srv/storage/family-share-> shared over Samba on the LAN/srv/storage/media-> shared over Samba for TVs, desktops, laptops/srv/storage/public-dav-> exposed through WebDAV
The key point is:
- do not expose SMB port
445 - only expose WebDAV through HTTPS
Step 1: Install Ubuntu and prepare the storage disk
For a DIY NAS, Ubuntu Server is usually a better fit than Ubuntu Desktop because it is lighter and cleaner.
After installation, list your disks:
lsblk
Assume your data disk is /dev/sdb.
Create a partition and format it:
sudo parted /dev/sdb --script mklabel gpt
sudo parted /dev/sdb --script mkpart primary ext4 0% 100%
sudo mkfs.ext4 /dev/sdb1
Create the mount path:
sudo mkdir -p /srv/storage
Get the UUID:
sudo blkid /dev/sdb1
Example output:
/dev/sdb1: UUID="xxxx-xxxx" TYPE="ext4"
Add it to /etc/fstab:
UUID=xxxx-xxxx /srv/storage ext4 defaults,nofail 0 2
Remount:
sudo mount -a
df -h
Step 2: Create folders and baseline permissions
Create your folders:
sudo mkdir -p /srv/storage/family-share
sudo mkdir -p /srv/storage/media
sudo mkdir -p /srv/storage/public-dav
Create a shared group:
sudo groupadd nas-share
sudo usermod -aG nas-share $USER
Set permissions:
sudo chown -R root:nas-share /srv/storage/family-share /srv/storage/media
sudo chmod -R 2775 /srv/storage/family-share /srv/storage/media
sudo chown -R www-data:www-data /srv/storage/public-dav
sudo chmod -R 755 /srv/storage/public-dav
This keeps things cleaner:
- Samba folders belong to an internal sharing group
- WebDAV folders belong to the web server
That separation helps avoid permission chaos later.
Step 3: Install Samba for LAN sharing
Install Samba:
sudo apt update
sudo apt install samba -y
Back up the default config:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
Append this to /etc/samba/smb.conf:
[family-share]
path = /srv/storage/family-share
browseable = yes
read only = no
guest ok = no
valid users = @nas-share
force group = nas-share
create mask = 0664
directory mask = 2775
[media]
path = /srv/storage/media
browseable = yes
read only = no
guest ok = no
valid users = @nas-share
force group = nas-share
create mask = 0664
directory mask = 2775
Create a Samba user:
sudo smbpasswd -a your-username
Validate the config:
testparm
Restart Samba:
sudo systemctl restart smbd
sudo systemctl enable smbd
Step 4: Access Samba inside the LAN
On Windows
Open Explorer and connect to:
\\NAS_IP\family-share
Example:
\\192.168.1.20\family-share
On Linux
sudo mount -t cifs //192.168.1.20/family-share /mnt/family-share \
-o username=your-username,uid=1000,gid=1000
On macOS
Go to Finder -> Go -> Connect to Server:
smb://192.168.1.20/family-share
Step 5: Keep Samba inside the LAN only
This is where many people get it wrong.
Samba should stay on the local network. If you use ufw, allow only your LAN subnet:
sudo ufw allow from 192.168.1.0/24 to any app Samba
Or at minimum:
sudo ufw allow from 192.168.1.0/24 to any port 445 proto tcp
sudo ufw allow from 192.168.1.0/24 to any port 139 proto tcp
Do not:
- forward port
445on your router - expose SMB to your public IP
- use Samba as your remote Internet-facing file service
If you need remote access, WebDAV or VPN is the better fit.
Step 6: Install WebDAV for remote access
A clean Ubuntu-friendly option is Apache + WebDAV.
Install the packages:
sudo apt install apache2 apache2-utils -y
Enable the needed modules:
sudo a2enmod dav
sudo a2enmod dav_fs
sudo a2enmod auth_digest
Create the password file:
sudo htdigest -c /etc/apache2/webdav.password "webdav" your-username
Create the site config:
sudo nano /etc/apache2/sites-available/webdav.conf
Content:
Alias /dav /srv/storage/public-dav
<Directory /srv/storage/public-dav>
DAV On
Options Indexes
AuthType Digest
AuthName "webdav"
AuthUserFile /etc/apache2/webdav.password
Require valid-user
DirectoryIndex disabled
</Directory>
Enable the site:
sudo a2ensite webdav.conf
sudo apache2ctl configtest
sudo systemctl reload apache2
At this point you can test inside the LAN:
curl -i http://YOUR_NAS_IP/dav
Step 7: Expose WebDAV over HTTPS
If WebDAV is going outside your home, start with HTTPS from day one.
There are 2 common approaches:
- expose it directly with a domain + reverse proxy + SSL
- use Cloudflare Tunnel if you cannot open router ports
If you can forward ports
Forward:
80443
DNS:
dav.example.com -> your home public IP
Then create a proper Apache or Nginx vhost and issue SSL with Let's Encrypt.
Example with Certbot:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d dav.example.com
Your final remote URL becomes:
https://dav.example.com/dav
If you cannot forward ports
If your connection is behind CGNAT or your router does not allow port forwarding, Cloudflare Tunnel is often the easier option:
- Apache still runs locally
- Cloudflare Tunnel exposes
http://localhost - outside users connect through Cloudflare HTTPS
Step 8: Connect from other devices
On Windows
You can map it as a network location or use a client that handles WebDAV well.
URL:
https://dav.example.com/dav
On mobile
Apps that usually work well:
- FolderSync
- Solid Explorer
- FE File Explorer
- Documents
On Linux
You can mount it with davfs2:
sudo apt install davfs2 -y
sudo mkdir -p /mnt/webdav
sudo mount -t davfs https://dav.example.com/dav /mnt/webdav
The most common mistakes
1. Using one folder for both Samba and public WebDAV
That usually turns into a permission mess. Keeping LAN and public data separate is much easier to manage.
2. Exposing Samba directly
This is a common and risky mistake. If you need remote access, use:
- WebDAV
- or VPN
but do not open 445 to the Internet.
3. Running WebDAV over plain HTTP
If credentials go over raw HTTP, you are creating an unnecessary risk. Public WebDAV should almost always be behind HTTPS.
4. Forwarding router ports but forgetting the local firewall
Many people open the router correctly, but ufw or Apache still blocks the service inside the machine.
5. Mounting disks manually and losing them after reboot
If you skip fstab, your mount may disappear or come back at a different path after restart.
When should you not use this approach?
This may not be the best option if you need:
- polished RAID, snapshots, and a UI like Synology
- a setup that non-technical family members can manage easily
- photo sync, mobile apps, and more advanced permissions out of the box
In that case, Synology or OpenMediaVault may be the easier path.
Conclusion
An old PC can absolutely work as a solid NAS if you keep the role split simple:
- Samba for the LAN
- WebDAV for public access
The key is not just installing services, but assigning each one the right job:
- internal stays internal
- public goes through HTTPS
- public folders stay separate from LAN folders
If you keep that structure clean, even an old PC can become a very usable family or homelab file server.