Mastering NFS Mounting and Sharing: A Complete Step-by-Step Guide

Mastering NFS Mounting and Sharing: A Complete Step-by-Step Guide

NFS


๐Ÿš€ Introduction

Network File System (NFS) is a time-tested protocol that allows files to be shared across Linux systems as if they were local. Whether you're in a home lab, an enterprise environment, or collaborating in an educational setup, NFS is a powerful tool for centralized file access.

In this guide, we’ll walk through:

  • Setting up an NFS server

  • Granting access to specific IPs with full permissions (read/write/delete)

  • Mounting NFS shares on client machines

  • Ensuring persistent access

  • Troubleshooting NFS issues


๐Ÿ“ฆ What is NFS?

Network File System (NFS) is a distributed file-sharing protocol developed by Sun Microsystems. It allows a computer to access files over a network as easily as if they were on its own disks.


✅ Why Use NFS?

  • ๐Ÿ”— Seamless file sharing across Linux systems

  • ๐Ÿ“ Centralized storage and easier backups

  • ๐Ÿค Ideal for collaborative projects

  • ⚡ Efficient use of system resources

  • ๐Ÿ“ก Works great on private or enterprise networks


๐Ÿ”ง NFS Setup Scenario

You're sharing a folder /srv/shared_folder/ from the server with IP 10.212.16.28. The following client IPs should have full access (read/write/delete):

  • 10.212.12.26

  • 10.212.12.30

  • 10.212.12.31


๐Ÿ–ฅ️ Step 1: Install Required Packages

On the Server (10.212.16.28):

sudo apt update
sudo apt install nfs-kernel-server -y

On the Clients:

sudo apt update
sudo apt install nfs-common -y

๐Ÿ“‚ Step 2: Create and Set Permissions for the Shared Folder

sudo mkdir -p /srv/shared_folder/
sudo chmod -R 777 /srv/shared_folder/
sudo chown nobody:nogroup /srv/shared_folder/

This gives full read/write/delete access. (Use stricter permissions for production.)


๐Ÿ“ƒ Step 3: Configure the Exports File

Edit the NFS exports file:

sudo nano /etc/exports

Add the following line to share the folder with the specified IPs:

/srv/shared_folder 10.212.12.26(rw,sync,no_subtree_check) 10.212.12.30(rw,sync,no_subtree_check) 10.212.12.31(rw,sync,no_subtree_check)

Then apply the configuration:

sudo exportfs -a

๐Ÿš€ Step 4: Start or Restart NFS Service

sudo systemctl restart nfs-kernel-server

You can verify with:

sudo exportfs -v

๐Ÿงช Step 5: Check the Exported Shares (from any client)

showmount -e 10.212.16.28

๐Ÿ“Œ Step 6: Mount the NFS Share on Clients

On each client (e.g., 10.212.12.26):

sudo mkdir -p /mnt/nfs_share
sudo mount 10.212.16.28:/srv/shared_folder /mnt/nfs_share

You should now be able to read/write/delete files from /mnt/nfs_share.


๐Ÿ”„ Step 7: Auto-Mount on Boot (Client-Side)

Edit the /etc/fstab file on each client:

sudo nano /etc/fstab

Add:

10.212.16.28:/srv/shared_folder /mnt/nfs_share nfs defaults 0 0

Then test it:

sudo mount -a

๐Ÿงน Step 8: Unmount If Needed

sudo umount /mnt/nfs_share

๐Ÿ› ️ Troubleshooting NFS Issues

๐Ÿ” 1. Missing NFS Packages?

Ensure correct packages are installed:

sudo apt install nfs-common nfs-kernel-server -y

๐ŸŒ 2. Network Connectivity

ping 10.212.16.28

๐Ÿ”ฅ 3. Firewall Rules

Allow NFS traffic (port 2049):

sudo ufw allow from 10.212.12.0/24 to any port nfs

๐Ÿ” 4. Restart NFS Services

sudo systemctl restart nfs-kernel-server

๐ŸŽฏ Conclusion

With NFS, sharing files across Linux systems becomes fast, reliable, and easy to manage. Whether you’re working in a collaborative setting or setting up centralized file access, NFS remains a go-to solution.

By following the steps above, your /srv/shared_folder/ is now securely and fully shared with selected client machines — empowering your workflow!


๐Ÿ“š Stay tuned for more Linux tutorials, system hacks, and tech insights — only on my blog!
✉️ Have questions or feedback? Reach out anytime!



Enjoyed this guide?

Get new cybersecurity, ethical hacking and Linux tutorials straight to your inbox. No spam.

Next Post Previous Post
No Comment
Add Comment
comment url