How to Setup Shareable Drive with NFS in Linux - Complete Guide
Learn how to configure Network File System (NFS) on Linux to create shareable drives across your network. Perfect for home servers and file sharing.
Table of Contents
- What is NFS and Why Use It?
- Prerequisites and Planning
- Step 1: Setting Up the NFS Server
- Step 2: Setting Up NFS Clients
- Step 3: Advanced Configuration Options
- Step 4: Monitoring and Maintenance
- Troubleshooting Common Issues
- Integration with Home Server Setup
- Best Practices and Security Considerations
- Conclusion
Setting up a Network File System (NFS) is one of the most efficient ways to share files across Linux machines in your network. Whether you’re running a home server setup or managing multiple Linux systems, NFS provides a robust solution for centralized file storage and sharing.
In my home lab setup, I use an N100 Intel mini PC that hosts Jellyfin and handles file backups for all devices in my network. NFS has been instrumental in creating a seamless file-sharing environment that allows me to access media files, backups, and documents from any Linux machine on my network.
This comprehensive guide will walk you through setting up NFS on Linux, from basic configuration to advanced mounting options.
What is NFS and Why Use It?
Understanding NFS
Network File System (NFS) is a distributed file system protocol that enables users to access files over a computer network similar to how local storage is accessed. It’s particularly well-suited for Linux environments.
Key Benefits of NFS
- Native Linux Support: Built-in support across all major Linux distributions
- High Performance: Optimized for Unix-like systems with minimal overhead
- Scalability: Handles multiple concurrent connections efficiently
- Flexibility: Supports various mount options and security configurations
- Cost-Effective: Open-source solution with no licensing fees
NFS vs Other Protocols
Protocol | Best For | Performance | Security | Complexity |
---|---|---|---|---|
NFS | Linux-only environments | High | Moderate | Low |
SMB/CIFS | Mixed Windows/Linux | Moderate | High | Moderate |
FTP | File transfers | Low | Variable | Low |
SSH/SFTP | Secure transfers | Moderate | High | High |
Prerequisites and Planning
Before diving into the configuration, ensure you have:
- Two or more Linux machines (server and client(s))
- Root or sudo access on all machines
- Network connectivity between all devices
- Static IP addresses (recommended for stability)
- Firewall configuration knowledge
Network Architecture Overview
Step 1: Setting Up the NFS Server
Install NFS Server Package
Begin by updating your system and installing the NFS kernel server:
sudo apt update && sudo apt install nfs-kernel-server -y
For CentOS/RHEL systems:
sudo yum install nfs-utils -y
# or for newer versions
sudo dnf install nfs-utils -y
Create the Shared Directory
Establish a directory structure for your NFS shares. I recommend organizing shares by purpose:
# Create main NFS directory
sudo mkdir -p /srv/nfs
# Create specific share directories
sudo mkdir -p /srv/nfs/media
sudo mkdir -p /srv/nfs/backups
sudo mkdir -p /srv/nfs/documents
Directory Location
Using /srv/nfs
follows Linux filesystem hierarchy standards. Avoid using /media
or /mnt
for NFS exports as these are typically reserved for temporary mounts.
Configure Permissions
Set appropriate ownership and permissions for the shared directories:
# Set ownership to nobody:nogroup for security
sudo chown -R nobody:nogroup /srv/nfs
# Set permissions (755 for directories, 644 for files)
sudo chmod -R 755 /srv/nfs
Configure NFS Exports
The /etc/exports
file defines which directories are shared and with what permissions:
sudo nano /etc/exports
Add your export configurations:
# Basic configuration for local network
/srv/nfs/media 192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash)
/srv/nfs/backups 192.168.1.0/24(rw,sync,no_subtree_check,root_squash)
/srv/nfs/documents 192.168.1.101(rw,sync,no_subtree_check) 192.168.1.102(ro,sync,no_subtree_check)
Export Options Explained
Option | Description | Use Case |
---|---|---|
rw | Read-write access | Full access for trusted clients |
ro | Read-only access | Sharing read-only content |
sync | Synchronous writes | Data integrity (recommended) |
async | Asynchronous writes | Better performance, less safe |
no_subtree_check | Disable subtree checking | Improved reliability |
root_squash | Map root to anonymous user | Security (default) |
no_root_squash | Allow root access | Administrative access |
all_squash | Map all users to anonymous | Maximum security |
Apply Export Configuration
After configuring exports, apply the changes:
# Export the file systems
sudo exportfs -a
# Restart NFS services
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-server
Configure Firewall
Allow NFS traffic through the firewall:
# For UFW (Ubuntu)
sudo ufw allow from 192.168.1.0/24 to any port nfs
# For firewalld (CentOS/RHEL)
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reload
Step 2: Setting Up NFS Clients
Install NFS Client Package
On client machines, install the NFS utilities:
sudo apt update && sudo apt install nfs-common -y
Create Mount Points
Establish directories where NFS shares will be mounted:
# Create mount points
sudo mkdir -p /mnt/server-media
sudo mkdir -p /mnt/server-backups
sudo mkdir -p /mnt/server-docs
Test Manual Mounting
Before configuring automatic mounting, test the connection:
# Mount the media share
sudo mount -t nfs 192.168.1.100:/srv/nfs/media /mnt/server-media
# Verify the mount
df -h | grep nfs
ls -la /mnt/server-media
Verification
If you can see the NFS mount in the df -h
output and access files in the mounted directory, the basic setup is working correctly.
Configure Permanent Mounting
Edit the /etc/fstab
file for automatic mounting on boot:
sudo nano /etc/fstab
Add entries for your NFS shares:
# NFS mounts
192.168.1.100:/srv/nfs/media /mnt/server-media nfs defaults,_netdev 0 0
192.168.1.100:/srv/nfs/backups /mnt/server-backups nfs defaults,_netdev 0 0
192.168.1.100:/srv/nfs/documents /mnt/server-docs nfs defaults,_netdev,ro 0 0
Mount Options for fstab
Option | Description | Benefit |
---|---|---|
_netdev | Network device | Waits for network before mounting |
soft | Soft mount | Returns error if server unavailable |
hard | Hard mount | Retries indefinitely (default) |
intr | Interruptible | Allows process interruption |
rsize=8192 | Read buffer size | Optimizes read performance |
wsize=8192 | Write buffer size | Optimizes write performance |
Test the fstab configuration:
# Test mounting all fstab entries
sudo mount -a
# Verify mounts
mount | grep nfs
Step 3: Advanced Configuration Options
Using AutoFS for On-Demand Mounting
AutoFS provides automatic mounting and unmounting of NFS shares, which is particularly useful when the NFS server isn’t always available.
Install AutoFS:
sudo apt install autofs -y
Configure the master map:
sudo nano /etc/auto.master
Add this line:
/mnt/auto /etc/auto.nfs --timeout=60 --ghost
Create the AutoFS map file:
sudo nano /etc/auto.nfs
Configure your auto-mounts:
media -fstype=nfs4,rw,soft,intr 192.168.1.100:/srv/nfs/media
backups -fstype=nfs4,rw,soft,intr 192.168.1.100:/srv/nfs/backups
documents -fstype=nfs4,ro,soft,intr 192.168.1.100:/srv/nfs/documents
Start and enable AutoFS:
sudo systemctl restart autofs
sudo systemctl enable autofs
Performance Optimization
For better performance, especially with large files or high-traffic scenarios:
# Add to /etc/fstab for optimized performance
192.168.1.100:/srv/nfs/media /mnt/server-media nfs rsize=32768,wsize=32768,hard,intr,_netdev 0 0
Security Enhancements
Using NFSv4 with Kerberos
For enhanced security in production environments:
# On server: Install Kerberos
sudo apt install krb5-kdc krb5-admin-server -y
# Configure NFSv4 security
echo "Domain = your-domain.com" | sudo tee -a /etc/idmapd.conf
Restricting Access by IP Range
Modify /etc/exports
for tighter security:
# More restrictive access
/srv/nfs/media 192.168.1.100/32(rw,sync,no_subtree_check) 192.168.1.101/32(ro,sync,no_subtree_check)
Step 4: Monitoring and Maintenance
Checking NFS Status
Monitor your NFS setup with these commands:
# Check NFS server status
sudo systemctl status nfs-kernel-server
# View active exports
sudo exportfs -v
# Show NFS statistics
nfsstat -s # Server stats
nfsstat -c # Client stats
# Monitor active connections
sudo ss -tuln | grep :2049
Log Analysis
NFS logs are typically found in:
# Check NFS logs
sudo journalctl -u nfs-kernel-server
sudo tail -f /var/log/syslog | grep nfs
Performance Monitoring
Create a simple monitoring script:
#!/bin/bash
# nfs-monitor.sh
echo "=== NFS Performance Monitor ==="
echo "Date: $(date)"
echo
echo "Active NFS Mounts:"
df -h | grep nfs
echo
echo "NFS Server Statistics:"
nfsstat -s | head -10
echo
echo "Network Connections:"
sudo ss -tuln | grep :2049
Troubleshooting Common Issues
Connection Problems
Common Error: Connection Refused
This usually indicates firewall issues or NFS services not running properly.
Solution checklist:
- Verify NFS services are running:
sudo systemctl status nfs-kernel-server
- Check firewall rules: Ensure ports 2049, 111, and others are open
- Test network connectivity:
ping
between server and client - Verify exports:
sudo exportfs -v
on server
Permission Issues
# Fix ownership issues
sudo chown -R nobody:nogroup /srv/nfs
# Check export permissions
sudo exportfs -v | grep your-share
Performance Issues
For slow NFS performance:
-
Adjust buffer sizes:
# In /etc/fstab rsize=32768,wsize=32768
-
Use async for non-critical data:
# In /etc/exports /srv/nfs/temp *(rw,async,no_subtree_check)
-
Monitor network utilization:
iftop -i eth0
Integration with Home Server Setup
As mentioned in my home server articles, NFS pairs excellently with other home server technologies. Here’s how I integrate NFS in my setup:
Media Server Integration
For Jellyfin and other media servers:
# Media directory structure
/srv/nfs/media/
├── movies/
├── tv-shows/
├── music/
└── photos/
This structure allows my N100 mini PC to serve media files efficiently to all devices on the network.
Backup Strategy
Combined with the LVM setup from my previous article:
# Backup scripts can now target NFS shares
rsync -av /home/user/documents/ /mnt/server-backups/user-docs/
Container Integration
When running Docker containers:
# docker-compose.yml
version: '3'
services:
jellyfin:
image: jellyfin/jellyfin
volumes:
- /mnt/server-media:/media:ro
- ./config:/config
Best Practices and Security Considerations
Security Best Practices
- Use NFSv4 when possible for better security
- Implement proper firewall rules restricting access to trusted networks
- Regular security updates on both server and clients
- Monitor access logs for suspicious activity
- Use root_squash by default unless specifically needed
Backup Considerations
Backup Strategy
Remember that NFS shares should be included in your backup strategy. The shared data should be backed up on the server side to prevent data loss.
Network Considerations
- Use wired connections when possible for better performance
- Implement proper network monitoring as discussed in server monitoring
- Consider network segmentation for security
Conclusion
Setting up NFS in Linux provides a robust, high-performance solution for file sharing across your network. Whether you’re building a home server setup like my N100 Intel mini PC configuration or managing a small office network, NFS offers the flexibility and performance needed for modern file sharing requirements.
The key to a successful NFS implementation lies in proper planning, security configuration, and regular maintenance. Start with a basic setup and gradually implement advanced features like AutoFS and performance optimizations as your needs evolve.
For more home server and Linux tutorials, check out my other articles on best mini PCs for home servers and Docker containers for home servers.
Start Building Your NFS SetupRelated Posts

How to Secure an SSH Server in Linux
Learn essential steps to enhance the security of your SSH server on Linux systems.
Why You Need a Home Server in 2025: Your Gateway to Digital Independence
Discover the compelling reasons to set up a home server in 2025. From AI workloads to data privacy, explore benefits, uses, and whether it's worth running your own server at home.

How To Access Remote Servers with SSH ProxyJump and Jump Hosts
Learn how you can use a jump host and a ProxyJump to access remote servers not in public domain.