How to Configure NFS (Network File System) on Ubuntu

Network File System (NFS) is a distributed file system protocol. which allowing a user on a client computer to access files over a network in a manner similar to how local storage is accessed.

This article will help you to install and configure NFS on Ubuntu systems and export an directory and mount it on client system.

Network Details:

We have running two Ubuntu 12.04 LTS Systems in same network 192.168.1.0/24, Below given ips are configured on server and client, which we will use in this tutorial.

Server: 192.168.1.100
Client: 192.168.1.110

Step 1: Set Up NFS Server on Ubuntu

In this step we will describe you to what packages you need to install and how to install them. Also describes who to export and directory using NFS server.

1.1 – Install Pacakges

Use following command to install required packages to configure NFS server.

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

1.2 – Export Directory

After completing package installation, we need to configure nfs to export directory. For this tutorial we are creating a new directory, you may use any existing directory also.

$ sudo mkdir /var/www/share
$ sudo chown nobody:nogroup /var/www/share

Configure NFS to export above created directory and home directory. So that this directory can be accessible over network using NFS.

$ sudo vim /etc/exports

/home             192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)
/var/www/share    192.168.1.110(rw,sync,no_subtree_check)

After configuring /etc/exports execute following command to export.

$ sudo exportfs -a

1.3 – Verify Exported Directory

To confirm and view exported directory use following command and you will get output like below

$ sudo exportfs -v

[Samput Output]
/home           192.168.1.0/24(rw,wdelay,no_root_squash,no_subtree_check)
/var/www/share  192.168.1.110(rw,wdelay,no_root_squash,no_subtree_check)

Step 2: Set Up NFS Client

After completing set up on server side, login to clients system where we need to configure nfs client and mount exported directory by nfs server.

2.1 – Install Packages

Install following packages on NFS client system, which is required to mount remote directory using nfs.

$ sudo apt-get install nfs-common portmap

2.2 – Mount Remote Exported Directory

Now we need to create mount points for mounting remote nfs exported directories.

$ sudo mkdir /mnt/share
$ sudo mkdir /mnt/home

After creating mount point, mount remote NFS exported directory using following command.

$ sudo mount 192.168.1.100:/var/www/share /mnt/share
$ sudo mount 192.168.1.100:/home /mnt/home

2.3 – Verify Mounted Directory

Check mounted file system using below commands. As per below output both nfs mounted directories are listed at end of result.

$ sudo df -h

[Sample Output]
Filesystem                    Size  Used Avail Use% Mounted on
/dev/sda1                      20G  2.8G   16G  16% /
udev                          371M  4.0K  371M   1% /dev
tmpfs                         152M  812K  151M   1% /run
none                          5.0M     0  5.0M   0% /run/lock
none                          378M  8.0K  378M   1% /run/shm
/dev/sr0                       32M   32M     0 100% /media/CDROM
/dev/sr1                      702M  702M     0 100% /media/Ubuntu 12.04 LTS i386
192.168.1.100:/var/www/share   20G  2.8G   16G  16% /mnt/share
192.168.1.100:/home            20G  2.8G   16G  16% /mnt/home

2.4 Set Up Auto Mount

Add the following lines in /etc/fstab to mount NFS directories automatically after system reboot. This will mount directories on start up after the server reboots.

192.168.1.100:/home  /mnt/home   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0
192.168.1.100:/var/www/share  /mnt/share   nfs     auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

2.5 – Unmount NFS Mount Point

If you want to remove mounted file system, You can simply unmounted it using umount command. Also you need to remove entries from /etc/fstab (if added)

# sudo umount /mnt/share
# sudo umount /mnt/home
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s