Installing NFS on Ubuntu

The Network File System (NFS) was developed to allow machines to mount a disk partition on a remote machine as if it were a local disk. It allows for fast, seamless sharing of files across a network.

The Official HOWTO for NFS is very good you should read it.

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

To configure the directories that will be exported by this NFS server we need to add them to the /etc/exports file. The file layout is very specific when it comes to white space. See the official documentation for details. For example there is no space between the IP address and the ‘(‘ in the example, adding one changes the meaning in subtitle ways.

sudo nano /etc/exports
/data 192.168.0.0/255.255.255.0(rw,no_subtree_check,sync)
/home 192.168.0.0/24(rw,no_subtree_check,sync)

The file layout about shows two ways to specify the IP addresses or ranges which can access the shares, /data and /home.

After updating the file tell the nfs server process to use the new settings with

sudo exportfs -var

You can also see the shares that are exported with

exportfs -v

and from a remote machine you can use

showmount IP_ADDRESS or hostname

Say we have two machine server1 the server and client1, you get the idea 🙂

If we want to mount the two shares from server1 called /data and /home on the machine client1. We need a few simple steps, these are all done on client1.

Create the directory where the share will be mounted.

sudo mkdir /mnt/home /mnt/data

Mount the share from the command line

sudo mount server1:/data /mnt/data
sudo mount server1:/home /mnt/home

To unmount them,

sudo umount /mnt/data
sudo umount /mnt/home

To mount the share when the machine reboots, add the mount instructions to the /etc/fstab file.

sudo nano /etc/fstab
server1:/data /mnt/data  nfs  defaults   0 0
server1:/home /mnt/home  nfs  defaults   0 0

It is always good to test that you have that correct by using

sudo mount -a

And do that before rebooting 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *