Debian 7 as NFS Server

Introduction

NFS (Network File System) is a very efficient way to share files on a local network. It is basically the Linux version of Samba.

In this example, we will have the following network topology :

  • One local network 192.168.0.0/24
  • IP of the NFS server : 192.168.0.100

Server configuration

We first need to install the NFS server package. it comes in two version : kernel or user. The kernel version is faster but not as easy to debug as the user version. We will use the kernel version :

# Installation of the NFS kernel server
apt-get install nfs-kernel-server

At the end of the installation, you should see the line below. It means that the NFS server as not been started because there is nothing to share. This is our next step.

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

Now, we need to create our shared directory. Then, we will need to declare it in the NFS server export list (file /etc/exports).

# Creation of the shared folder
mkdir /srv/nfs_shared_folder
# Edit the /etc/exports file
nano /etc/exports

In the exports file, we need to add the following line :

/srv/nfs_shared_folder    192.168.0.0/24(rw,root_squash)

With this configuration, we are sharing the folder /srv/nfs_shared_folder with the entire local network. Review of the options in the parentheses :

  • rw – Allow read & write on the filesystem. You can replace it by « ro » for read only access.
  • root_squash – Map root account/group to the anonymous account/group. Useful for security.

To enable this new configuration, we need to restart the NFS server :

/etc/init.d/nfs-kernel-server restart

We are done with the server configuration !

Client configuration

With a linux client, setting up NFS is really easy, you need to install the package ‘nfs-common’ and then you can mount NFS like any other filesystem :

# Installation of the nfs-common package
apt-get install nfs-common
# Creation of the mount point
mkdir /home/yourusernamehere/nfs_mount_point
# Mounting the NFS folder to a local mount point
mount -t nfs 192.168.0.100:/srv/nfs_shared_folder /home/vdagonneau/nfs_mount_point

It is done ! Your NFS volume is now mounted on /home/yourusernamehere/nfs_mount_point.