Ubuntu Linux NFS Server installation and Configuration

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:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Sebastiaan Jun 28, 2008 @ 13:05

    In the file exports, the option ‘rsync’ is not correct. It should be ‘sync’ or ‘async’.
    See: man exports
    Also check out the difference between no_subtree_check and subtree_check while you’re reading.

  • sayali May 3, 2012 @ 4:06

    I have tried command

    $ sudo apt-get install nfs-kernel-server portmap nfs-common

    But Following error msg is coming please give me solution..

    Cannot register service: RPC: Authentication error; why = Client credential too weak
    unable to register (STRINGPROGRAM, STRINGPROGRAMVERSION, udp).mmm@ubuntu:~$

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum