Monday, August 27, 2012

Configure NFS on Ubuntu

Download: Fast, Fun, Awesome

Network File System (NFS) is useful to share space on other computers.

In this scenario we are going to configure NFS server on host and NFS client on machine.

1. Prerequisites
    Install nfs-common package on both NFS client and NFS server using following command.

     $ sudo apt-get install nfs-common

Additionally we need to install extra package on NFS server (

    $ sudo apt-get install nfs-kernel-server

This package is the actual NFS daemon listenning on both UDP and TCP 2049 ports. And portmap should be waiting for instructions on a port 111.

2. Create NFS Share on NFS Server (
Create a directory to share on NFS server(

Run following command on NFS server.

   $ mkdir /home/kailas

3. Apply Access Control Rules

In our scenario we want only to access the nfs share.

Therefore, open /etc/exports file in any text editor (such as vi, gedit, or emacs) on NFS server (

Add following line in (/etc/exports) file.

A. Read/Write Permissions


Above line specifies that export /home/kailas directory for host with IP with read, write permissions, synchronized mode.

B. Only Read Permissions

If you don't want to give write permission and only want to give read permission to client ( then instead of above line use following line.


C. Read/Write + Root privileges


Above line in "/etc/exports" file will export /home/kailas directory for host with an IP address with read, write permissions, synchronized mode and the remote root user will be treated as a root and will be able to change any file and directory.

D. Read/Write Privilege to all computers on network

 /home/kailas/     *(rw,sync)

Above line indicates, export /home/kailas directory for any host with read, write permissions and synchronized mode.

E. Read Privilege to All computers on network

   /home/kailas/     *(ro,sync)

Above line indicates, export /home/kailas directory for any host with read only permissions and synchronized mode.

3. Restart NFS daemon

Use following command on Ubuntu to restart NFS service.

$ sudo /etc/init.d/nfs-kernel-server restart 

Note: After any modification you will made  in "/etc/exports" file please restart NFS service to reflect your changes. 

4. Mount NFS directory on client ( machine

NFS client needs portmap service, simply install nfs-comman package on client (

   $ sudo apt-get install nfs-common

Make sure portmap service is running:
  $ sudo service portmap status

Sample outputs:
  portmap start/running, process 4193

If not just start it:
    $ sudo service portmap start

Create a mount directory on Client (
  $ sudo mkdir /nfs

$ sudo  mount   /nfs/

To see the content of the directory use following command.
 $ ls /nfs

5. Configure automount

To make this completely transparent to end users, you can automount the NFS file system every time a user boots a Linux system. Simply edit "/etc/fstab" to mount system automatically during a system boot. You can use your favorite editor and create new line like this within /etc/fstab:   /nfs/  nfs  defaults  0  0

 6. Appendix

If above steps doesn't work then please try to stop iptables or configure iptable rules to allow nfs communication.

# service iptables stop