Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How To Set Up and Configure NFS on Ubuntu 16.04
Network File System (NFS) is a distributed filesystem protocol that allows you to access shared folders from remote systems over a network. NFS enables you to mount remote directories as if they were local, providing a seamless way to share storage space between multiple clients across different locations.
To complete this setup, you will need two Ubuntu 16.04 systems with sudo privileges connected via a private network ? one acting as the NFS server and another as the NFS client.
Installing NFS Server Package
On the server machine, install the nfs-kernel-server package which enables directory sharing capabilities.
sudo apt update sudo apt install nfs-kernel-server
This command installs the NFS kernel server along with required dependencies including nfs-common, rpcbind, and various Python libraries.
Installing NFS Client Package
On the client machine, install the nfs-common package which provides tools to access NFS shares.
sudo apt update sudo apt install nfs-common
Creating and Configuring Shared Directories
We will create two types of NFS shares to demonstrate different permission configurations.
General Purpose Share
Create a shared directory accessible to all users with write permissions.
sudo mkdir /usr/nfs/common -p sudo chown nobody:nogroup /usr/nfs/common
The nobody:nogroup ownership ensures that any user can read and write to this directory.
Home Directory Share
The existing /home directory will be shared to allow clients access to user home directories stored on the server.
Configuring NFS Exports
Edit the /etc/exports file to define which directories to share and their access permissions.
sudo vi /etc/exports
Add the following export configurations:
/usr/nfs/common 192.168.1.100(rw,sync,no_subtree_check) /home 192.168.1.100(rw,sync,no_root_squash,no_subtree_check)
Export Options Explained
| Option | Description |
|---|---|
rw |
Allows read and write access to the share |
sync |
Ensures data is written to disk before responding to requests |
no_subtree_check |
Prevents subtree checking to avoid issues with open files |
no_root_squash |
Allows root user on client to access files as root on server |
Restart the NFS service to apply the configuration changes:
sudo systemctl restart nfs-kernel-server
Mounting NFS Shares on Client
Create mount points on the client machine and mount the NFS shares.
sudo mkdir /mnt/common sudo mkdir /mnt/home sudo mount 192.168.1.100:/usr/nfs/common /mnt/common sudo mount 192.168.1.100:/home /mnt/home
Verify that the shares are mounted correctly:
df -h
Filesystem Size Used Avail Use% Mounted on ... 192.168.1.100:/home 124G 11G 119G 9% /mnt/home 192.168.1.100:/usr/nfs/common 124G 11G 119G 9% /mnt/common
Automatic Mounting at Boot
To automatically mount NFS shares at system startup, add entries to the /etc/fstab file.
sudo vi /etc/fstab
Add the following lines at the end of the file:
192.168.1.100:/usr/nfs/common /mnt/common nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0 192.168.1.100:/home /mnt/home nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
Unmounting NFS Shares
When you no longer need access to the NFS shares, unmount them using:
sudo umount /mnt/common sudo umount /mnt/home
Conclusion
This setup demonstrates how to configure NFS on Ubuntu 16.04 with two different sharing scenarios ? a general-purpose share accessible to all users and a home directory share with restricted access. NFS provides an efficient way to share storage resources across network-connected systems while maintaining security through proper permission configuration.
