Setting up NFS Share on Linux

2 minutes read

On_Server

sudo apt install nfs-kernel-server
sudo systemctl status nfs-kernel-server.service
sudo mkdir -p /nfs/share/project1
sudo vim /etc/exports
--------------------------------
# Usage
export_directory_name client1(sharing_options) client2(sharing_options_2)

# Example
/nfs/share/project1  10.10.11.213(rw,sync,no_subtree_check)
sudo exportfs -a
sudo exportfs -v
------------------------
/nfs/share/project1 10.10.11.213(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
sudo systemctl restart nfs-kernel-server

On_Client

sudo mkdir -p /nfs/mnt/project1
# Usage
sudo mount -t nfs  server_ip_addr:/nfs/share/project1  /nfs/mnt/project1

# Example
sudo mount MyCutieServer:/Data/share /sharedata

Persistent mount (Client)

The mount only persists until the system reboots. To automatically mount the directory when the system activates, add the mount point to the /etc/fstab file. The entry should consist of the export directory, the local mount point, a list of options, and two 0’s. To see all the available options for this file, run man nfs on the client.

sudo vim /etc/fstab
----------------------------
server_ip_addr:/nfs/share/project1  /nfs/mnt/project1 nfs timeo=900,intr,actimeo=1800 0 0

Configuring the Firewall (Server)

Add a rule to allow port 2049 to accept traffic from the client’s IP address. Replace client_ip_addr with the address of the client.

sudo ufw allow from client_ip_addr to any port nfs

Extras (Server)

sudo chown nobody:nogroup /nfs/share/project1