Skip to content
Go back

Guide to NFS on Linux

Published:

output


What is NFS?

NFS (Network File System) allows Linux systems to share directories and files with others over a network. It is commonly used for centralizing storage and making files accessible to multiple machines.


NFS Architecture


Prerequisites


Setting Up NFS: Step-by-Step

1. Install NFS Packages

On Ubuntu/Debian:

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

On CentOS/Fedora/RHEL:

sudo yum install nfs-utils

2. Create a Directory to Share

sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 777 /srv/nfs/shared

3. Configure NFS Exports

Edit the exports file:

sudo nano /etc/exports

Add a line like:

/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)

4. Export the Shared Directory

sudo exportfs -ra

5. Start and Enable NFS Server

sudo systemctl enable --now nfs-server

6. Adjust Firewall (if enabled)

On Ubuntu:

sudo ufw allow from 192.168.1.0/24 to any port nfs

On CentOS/Fedora:

sudo firewall-cmd --permanent --zone=public --add-service=nfs
sudo firewall-cmd --reload

7. Check NFS Exports

showmount -e

NFS Client Configuration

1. Install NFS Client Utilities

On Ubuntu/Debian:

sudo apt install nfs-common

On CentOS/Fedora/RHEL:

sudo yum install nfs-utils

2. Mount the NFS Share

sudo mkdir -p /mnt/nfs-client
sudo mount -t nfs 192.168.1.100:/srv/nfs/shared /mnt/nfs-client

3. Make the Mount Permanent

Edit /etc/fstab:

sudo nano /etc/fstab

Add:

192.168.1.100:/srv/nfs/shared /mnt/nfs-client nfs defaults 0 0

4. Unmount the NFS Share

sudo umount /mnt/nfs-client

Export Options

NFS Versions

Security Best Practices


Troubleshooting


Example: Full Workflow

On Server:

sudo apt install nfs-kernel-server
sudo mkdir -p /srv/nfs/shared
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 777 /srv/nfs/shared
echo "/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports
sudo exportfs -ra
sudo systemctl enable --now nfs-server

On Client:

sudo apt install nfs-common
sudo mkdir -p /mnt/nfs-client
sudo mount -t nfs 192.168.1.100:/srv/nfs/shared /mnt/nfs-client

Thank You


Suggest Changes

Next Post
Guide to LVM on Ubuntu