Ubuntu Linux NFS Server installation and Configuration

Get real time updates directly on you device, subscribe now.

Q. How do I install and configure NFS 4 Server under Ubuntu Linux ?

A. In order to set NFS server you need to install the following packages:

=> nfs-kernel-server – Linux NFS Server

=> nfs-common – NFS Common programs

=> portmap – The RPC portmapper

Ubuntu Linux install NFS Server

Use apt-get command to install all required packages:
$ sudo apt-get install nfs-kernel-server portmap nfs-common

Sharing directory with /etc/exports

The NFS file systems being exported / shared using /etc/exports file. You need to specify directory (file system) to share with rest of the nfs client computers. The file /etc/exports serves as the access control list for file systems which may be exported to NFS clients.
$ sudo vi /etc/exports
To export /data directory to network enter the following in /etc/exports file:
To export /sales to hostname tom and jerry, enter:
/sales tom(ro,sync) jerry(ro,sync)
To export /users to in read write format, enter:
/users,sync) jerry(rw,fsid=0,insecure,no_subtree_check,async)

  • rw : Allow clients to read as well as write access
  • ro : Read only access
  • insecure : Tells the NFS server to use unpriveledged ports (ports > 1024).
  • no_subtree_check : If the entire volume (/users) is exported, disabling this check will speed up transfers.
  • async : async will speed up transfers.

Save and close the file. Just restart nfs-server:
$ sudo /etc/init.d/nfs-kernel-server restart

Now your NFS sever is sharing /sales and /data directories.

How do I access shared directories from Linux client computer?

Login to Linux desktop system and enter the following command to mount shared directories. First, create a mountpoint on your client computer:
# mkdir /mnt/data
Mount the server:
# mount nfs-server:/data /mnt/data
You can also use following syntax for NFS client version 4:
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/data /mnt/data
# mount -t nfs4 -o proto=tcp,port=2049 /mnt/data

  • : NFS Server IP address
  • proto=tcp,port=2049 : Force to use TCP protocol i.e. mount the NFS filesystem using TCP. The numeric value of the port to connect to the NFS server on. If the port number is 0 (the default) then query the remote host’s portmapper for the port number to use. If the remote host’s NFS daemon is not registered with its portmapper, the standard NFS port number 2049 is used instead.

How do I access my files?

To access shared files use regular commands or GUI file manager:
$ cd /mnt/data
$ ls
$ mkdir office
$ pwd

See Linux NFS client how to for more information.

To see mounted file system and available disk space use df command:
$ df -h

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              92G   23G   65G  26% /
varrun               1013M  128K 1013M   1% /var/run
varlock              1013M     0 1013M   0% /var/lock
udev                 1013M   84K 1013M   1% /dev
devshm               1013M     0 1013M   0% /dev/shm
/dev/sda1              98G   22G   77G  23% /media/sda1
/dev/sda5             274G   29G  245G  11% /share
/dev/sdb2             230G  4.9G  213G   3% /backup.iscsi
nfs-server:/data/     230G   31G  188G  14% /mnt/data

How do I see all shared directories from client computer?

Use showmount command to query the mount daemon (NFS Server) on a remote host for information about the state of the NFS server on that machine:
$ showmount -a

All mount points on nfs-server:

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Get real time updates directly on you device, subscribe now.