Network File System (NFS)

NFS - Server

Debian & Ubuntu

  • sudo apt-get update
  • sudo apt install nfs-kernel-server

CentOS & Fedora

  • yum -y install nfs-utils
  • apt-get install nfs-kernel-server

Create root NFS directory

sudo mkdir /home/marcuschiu/directory-to-be-shared

Set permissions

sudo chown nobody:nogroup /home/marcuschiu/directory-to-be-shared #no-one is owner
sudo chmod 777 /home/marcuschiu/directory-to-be-shared #everyone can modify files

Define access for NFS clients in /etc/exports file. Example file:

To enable access to a single client

/home/marcuschiu/directory-to-be-shared {clientIP}(rw,sync,no_subtree_check)

To enable access to several clients

/home/marcuschiu/directory-to-be-shared {clientIP-1}(rw,sync,no_subtree_check) {clientIP-2}(...) {clientIP-3}(...)

To enable access to an entire subnet

/home/marcuschiu/directory-to-be-shared {subnetIP}/{subnetMask}(rw,sync,no_subtree_check)

Example file /etc/exports:

/home/marcuschiu/directory-to-be-shared 192.168.111.38/255.255.255.0(rw,sync,no_subtree_check)

Set changes and restart NFS server

sudo exportfs -a #making the file share available
sudo systemctl restart nfs-kernel-server #restarting the NFS kernel

NFS - Client

Debian & Ubuntu

  • sudo apt-get update
  • sudo apt install nfs-common

CentOS & Fedora

  • sudo yum install nfs-utils

Mount the NFS directory temporarily

sudo mount -t nfs {IP of NFS server}:{folder path on server} /home/client
sudo mount -t nfs 192.168.111.10:/home/marcuschiu/directory-to-be-shared /home/client

Mount the NFS directory PERMANENTLY

In /etc/fstab file add the following line:

{IP of NFS server}:{folder path on server} /var/locally-mounted nfs defaults 0 0

# e.g.

192.168.111.10:/home/marcuschiu/directory-to-be-shared /home/client nfs defaults 0 0