Write Review

How to set up Network File System on Ubuntu 18 Server


Network File System allows for the sharing of directories and files with other users and programs remotely over a network. These users and programs access the shared resources as if they were locally mounted on their devices. NFS is generally implemented in file servers and has a number of benefits including:

  • Users in the network need not create different home directories as the only one can be created and shared.
  • Less disk space is needed on client devices as most of the files are stored in the centralized storage and shared over the network.
  • External storage devices are needed less as folders and files may be shared over the network. Bear in mind that external storage devices are a major contribution to the introduction and spread of malware in an organizational protocol.
  • It allows confidentiality of data is enhanced to be enforced as the central storage may be accessed using implementations such as Kerberos.


  • 2 running instances of an Ubuntu 18.04 servers or the second one be an ubuntu 18.04 client operating systems connected in a private network
  • Both instances should be having a non-root user with sudo privileges
  • Some basic knowledge of Linux and Linux commands


Update system packages on both machines

$ sudo apt update && sudo apt upgrade

On the host

This is where the NFS server will be installed. The client will mount directories from this machine, hence the server.

Install the NFS server packages

$ sudo apt install -y nfs-kernel-server


Head over to /etc/exports to configure the directories that you want to export. For my case, I am exporting the /home directory. Edit the ip address to the one you are using on your host machine.

$ sudo nano /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)

Available options include:

  • rw means read-write access, the alternative option may also be ro (read-only).
  • Sync means changes made to the host directory must be written before replying, this ensures the content shared is up to date. You can ignore by using the async option
  • no_root_squash means the client can have root privileges on the shared content located in the host machine.
  • no_subtree_check which means nfs will not go to the shared directory’s parent folders to verify its permission hence increasing reliability but reducing security. subtree_check on the other hand does the opposite

Exit editor while saving changes.

Configure firewall rules

$ sudo ufw enable 
$ sudo ufw allow from to any port nfs

On the Client

Install the nfs client package

$ sudo apt install nfs-common

Create the local mounting points

Create the directories to which your mounted directories will be placed. You can create it where you want.

$ mkdir /home/nfs

Mount the exported folder to your created directory

$ sudo mount

Special Note: The local directory to which your mounting your folder must exist, in the above instance, the /home/nfs directory exists.


That’s it, you have successfully mounted a remote directory onto another machine by use of the network file system.To unmount the shared folder, you can use the umount command on the client’s machine:

$ sudo umount /home/nfs

Check out these top 3 Linux hosting services

Was this article helpful?