NFS file sharing server and client on Ubuntu Linux | TechyTalk


: 2

When you want to share files between Linux and Windows machines you don't have a lot of choice, you end up using Samba. This situation is very common so most Linux distributions including Ubuntu Linux make configuring Samba a breeze. But what if you want to share files between Linux PCs? Sure you can use Samba but you have more flexible and faster choice - NFS (Network File System). In this article I'll show you how to do basic NFS server and client setup on Ubuntu Linux and other Ubuntu based distributions.

NFS server

First lets install our NFS server. You can paste these commands to your terminal:

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

Second step is to add your directories to the /etc/exports file using your favorite text editor, I'll use Nano editor like this:

Inside /etc/exports file you will find some examples on how to specify directories and things like allowed clients. For detailed documentation you can consult users manual pages using man exports command. For basic sharing of your documents directory you would put something like this at the end of /etc/exports file:

/home/Documents    *(rw,sync)

Now save the file by pressing Ctrl^X and run exportfs command to apply changes. Also make sure nfs-kernel-server and portmap services are started correctly like this:

sudo exportfs -a
sudo service nfs-kernel-server restart
sudo service portmap restart

NFS client

On the client PC you must install following packages:

sudo apt-get install nfs-common portmap

Also you must make sure portmap service is started correctly:

sudo service portmap restart

To mount Documents directory shared from your NFS server you should make destination directory on your client PC like this:

Then you can use following command to mount shared Documents directory from NFS server with IP address to ServerDocuments directory on NFS client.

sudo mount -t nfs ServerDocuments

That's it. You should now be able to see contents of your Documents directory from NFS server inside your ServerDocuments directory on your NFS client.

One more thing. To browse all NFS shares for NFS server with IP address you can use showmount command like this

I wish you happy file sharing!