NFS (Network File Share) is a protocol that allow you to share directory with other machine via network. A machine that share the directory to other machine called NFS Server, a machine that use the remote directory is called NFS client. In this tutorial, we will show you how to install an NFS client.
You need an active NFS server before you can mount a directory to it. If you don’t have them, please read my other tutorial first to create one: How to Setup NFS Server in Ubuntu.
Prerequisite
- Ubuntu
- Active NFS Server
Sudo Privileges
Before start, we make sure that we will have no permission issue on the configuration.
sudo su
Install Dependencies
First we need to install dependecy library
apt update && apt install nfs-common
Create a Directory to Mount
This is where you create a directory which will mounted on the NFS server. For example if we want to mount the /var/www
folder, then we can create those filder
mkdir -p /var/www
Mounting to NFS Server
To mount a folder to NFS Server, first check the available NFS server parh in the NFS server. In this part, you have to know the NFS Server IP. For example, if my NFS server is on 192.168.5.50
, then we can run this command
showmount -e 192.168.5.50
This will return a list of path that the NFS server have
Export list for 192.168.5.50:
/nfs/share1 *
/nfs/share2 192.168.5.0/24
/nfs/share3 192.168.10.0/24
Now, pick the directory that suit your need and run this command to mount your directory to remote NFS Server
mount -t nfs 192.168.5.50:/nfs/share1 /var/www
Thats it! Now, If you create a file inside /var/www
directory, the file will be stored in the NFS Server.