How to set up NFS Server

Hello my dear Linux Yogi’s

in today’s illustration I am going to show you how to set up a basic NFS Server. NFS Server is an excellent choice for mass storage for example for virtual environments and it is very quick. This is the first part of the two part series and in the second part I will show you how to set up the NFS Client.

Open up you terminal or console and verify that our system is up2date.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
sudo apt-get autoremove

Now that our system is updated we can go ahead and install the nfs server components.

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

So after the installation is done let check quickly if it is running with the following command

ps ax |grep nfsd

and it should return some similar to the following:

1385 ?     S<     0:00 [nfsd4_callbacks]
1388 ?     S       0:00 [nfsd]
1389 ?     S       0:00 [nfsd]
1390 ?     S       0:00 [nfsd]
1391 ?     S       0:00 [nfsd]
1392 ?     S       0:00 [nfsd]
1393 ?     S       0:00 [nfsd]
1394 ?     S       0:00 [nfsd]
1395 ?     S       0:00 [nfsd]

That is great it is running already. Now let’s get a nfs share configured. First off lets create a directory for that:

sudo mkdir /srv/nfs

and for security lets change ownership to nobody and nogroup with the following command:

sudo chown nobody:nogroup /srv/nfs

Now that this is out of the way let actually create a nfs share. Use your favorite editor and open the file /etc/exports and add the following line at the end of the file.

  • /srv/nfs: This tells nfs where the designated share is on the local system
  •  This specifies who has access to this nfs share. You can use a single IP address or a entire subnet for example: or for a class B subnet.
  • rw: This specifies the permission level  rw or ro are valid
  • sync: This enforces nfs to follow protocol to wait for request to be finished before replying to them. async will allow nfs to violate this
  • no_subtree_check: This improves reliability but weakens the security a little.
  • no_root_squash: I would only use this option with diskless clients like a vmware or xenserver host.

Save the file and in order to tell nfs that there is now a newshare for it to export we need to run the following command.

sudo exportfs -a

So this concludes the nfs server set up how to. As you may remember we install a little tool which can become handy when managing nfs servers. It is called nfs watch and when you run it you should see something like the following:

nfs watch
nfs watch

In the last line on the nfs watch tool it shows you your nfs share and that also means that it is serving our new share.

That is it for part one. I hope you liked this article and I also hope you are going to read part two which is coming out tomorrow.

Thank you for reading, Namaste my friends 😉