Linux: create an NFS share and connect to it

This tutorial explains how to create a share NFS on a Linux server and how to connect a Linux client to a share NFS . A common procedure for Linux system administrators in companies, production environments or test universes.

Debian distributions, Ubuntu, CentOS Fedora, Red Hat, etc. are compatible with this manual.

This guide uses the vi text editor but you can of course use vim, emacs or other tools.

Create a share NFS server side

1. On the server workstation, which can be a simple computer, open a Terminal locally or a remote connection SSH .

2. Install the required package:

  sudo apt-get install nfs-kernel-server 

3. Create a local directory that will be shared:

  sudo mkdir /srv/share 

4. Assign access and write permissions, for example:

  sudo chmod 755 /srv/partage/  
  sudo chgrp grplocal /srv/partage/ 

5. Open the share configuration file NFS :

  sudo vi /etc/exports 

7. Declare the path of the folder to be shared and the network access permissions:

  /srv/share 192.168.0.0.0/24(rw,async,no_subtree_check) 

Here, the /srv/share folder will be accessible from the entire 192.168.0.0.0 subnetwork in read and write (rw or read write).

tutoriel nfs etc exports linux

8. Reload the server service NFS to take into account the changes.

  sudo service nfs-kernel-server reload 

9. Check the mounts offered by the server NFS :

showmount -e

Export list for server: /srv/share 192.168.0.0.0/24

If the command does not return the correct export of the list, do a “sudo service nfs-kernel-server restart”.

Connect a Linux client workstation to the sharing NFS

1. Open a Terminal or a connection SSH on the client computer.

2. Create a local folder that will be the link to the network share:

  sudo mkdir /mnt/partage  

3. Declare the network share in the fstab file :

  sudo vi /etc/fstab 

4. Add a line :

  server:/srv/share /mnt/share nfs defaults,user,auto 

tutoriel nfs etc fstab linux

5. Save and exit the fstab file.

6. Request assembly:

  sudo mount -a 

7. Go to the new share, list the content, write in it.

  cd /mnt/share   ll /mnt/share   touch test