Debian / Ubuntu - Install and configure a NFS server and a NFS client

Page 1 / 1
  • Published on : 12 March 2015 at 14:09 UTC
  • By Lionel Eppe

On Linux, you can share files using the NFS protocol. This protocol is also used by NAS and Linux-based systems (such as VMware ESXi and Citrix XenServer).

Here is the network configuration we used for this tutorial :

  • NFS server IP : 10.0.0.102
  • NFS client IP : 10.0.0.101
  1. Install a NFS server
  2. Install a NFS client
  3. Optional : Map a FTP share for non-Linux clients

1. Install a NFS server

To install a Linux NFS server, type the following command :

Code : Bash

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

At the end of the installation, a warning is displayed.
Note : This is normal, because we didn't set the folders to "export" (sharing).

Code : Plain Text

[warn] Not starting NFS kernel daemon: no exports. ... (warning)

To begin, create a folder in "/var" and give all rights to the root user. The others will have only readings and access rights.

Code : Bash

mkdir /var/shared-data
chown root:root /var/shared-data
chmod 755 /var/shared-data

To share this folder, specify one of these four options in the "/etc/exports" file :

Code : Plain Text

# This shared folder is available for read and write but only from the IP address : 10.0.0.101
/var/shared-data        10.0.0.101(rw,sync,fsid=0,crossmnt,no_subtree_check,no_root_squash)

Code : Plain Text

# This shared folder is available for read only and only accessible from the IP address : 10.0.0.101
/var/shared-data        10.0.0.101(ro,sync,fsid=0,crossmnt,no_subtree_check,no_root_squash)

Code : Plain Text

# This shared folder is available for read and write and accessible through the network : 10.0.0.0/255.0.0.0
/var/shared-data        10.0.0.0/255.0.0.0(rw,sync,fsid=0,crossmnt,no_subtree_check,no_root_squash)

Code : Plain Text

# This shared folder is read-only and accessible to everyone
/var/a-public-folder *(ro,insecure,all_squash)

For more information about the options that you can use, see the Ubuntu Documentation : NFS mount options

Finally, restart the NFS server.

Code : Bash

service nfs-kernel-server restart

 

2. Install a NFS client

Warning :
The use of this procedure under Ubuntu (Version 12.04 LTS only) causes the message "mountall disconnected from plymouth".
If you use the 14.04 version, this procedure will work correctly.

First, install the NFS client for Linux.

Code : Bash

apt-get install nfs-common

Then, create a folder for the mount point :

Code : Bash

mkdir -p /mnt/nfs/var/shared-data

Mount the NFS share on the folder you just created.

Code : Bash

mount 10.0.0.102:/var/shared-data /mnt/nfs/var/shared-data

List the file systems available on the client.

Code : Bash

df -h

This command will display something like this.
Note : In the last line, you will find the shared folder mount point.

Code : Plain Text

Filesystem                                               Size  Used Avail Use% Mounted on
rootfs                                                    19G  3,7G   15G  21% /
udev                                                      10M     0   10M   0% /dev
tmpfs                                                    405M  644K  405M   1% /run
/dev/disk/by-uuid/7504b371-b24c-42a7-aa56-1d651899eecd    19G  3,7G   15G  21% /
tmpfs                                                    5,0M     0  5,0M   0% /run/lock
tmpfs                                                    986M  372K  986M   1% /run/shm
10.0.0.102:/var/shared-data                               15G  3,4G   11G  25% /mnt/nfs/var/shared-data

Try to create a file in the "/mnt/nfs/var/shared-data" folder (the shared folder).

Code : Bash

touch /mnt/nfs/var/shared-data/fichier.txt

Then, on the server, list the contents of the "/var/shared-data/" folder.
If all goes well, a "file.txt" file is present in this folder.

Code : Bash

ls -l /var/shared-data/

Warning, if you restart the client computer, the mount point will disappear.
To mount the folder at the the computer boot, edit the "/etc/fstab" file by adding this :

Code : Plain Text

10.0.0.102:/var/shared-data  /mnt/nfs/var/shared-data   nfs      rw,sync,hard,intr  0     0

To test this configuration, remove the existing mount point.

Code : Bash

umount /mnt/nfs/var/shared-data

To test the "/etc/fstab" configuration file without having to restart the Linux machine, use this command :

Code : Bash

mount -a

If all goes well, the "/mnt/nfs/var/shared-data" folder will contain the file you created earlier.

Code : Bash

ls -l /mnt/nfs/var/shared-data  

And the mount point will be displayed by the "df -h" command :

Code : Bash

df -h

 

3. Optional : Map a FTP share for non-Linux clients

Because Windows doesn't natively support the NFS protocol, we will use the FTP protocol to access the folder shared by the NFS server.

To do this, install ProFTPD by following this tutorial : Debian / Ubuntu - Install a FTP server
Once installed and configured, create a user by specifying the desired folder as the home folder.
So, when you log in by using this user, you access the desired folder.

Code : Bash

useradd --home /var/shared-data my_ftp_user

Specify a password for this user.

Code : Bash

passwd my_ftp_user

And set this user as the owner of this folder.

Code : Bash

chown -R my_ftp_user:my_ftp_user /var/shared-data

To check the rights of this folder, use the following command :

Code : Bash

ls -l /var/shared-data

Now, you can access this folder from any OS using a simple FTP client.