Network FIle System(NFS) can simultaneously run in version 2, 3, 4. NFS version 4(NFSv4) has several improvements over the NFSv2 and NFSv3. The improvements I like most are:

  • NFSv4 makes configuring firewall simple because NFSv4 uses only one port (default to 2049) while NFSv2 and NFSv3 use 4 randomly changing ports
  • NFSv4 provides strong security with the implementation of Kerberos while NFSv2 and NFSv3 don't

In my home network, all the computers are installed with Linux OS that supports NFSv4. Therefore, it is advantageous to configure NFS server to be ONLY operating in version 4 and disable NFSv2 and NFSv3.

After completing this instructable, you might be interested in learning how to use the automounter.


This instructable will show:

  • How to install NFSv4 server
  • How to enable configure NFSv4 server
  • How to disable NFSv2 and NFSv3
  • How to run NFSv4 server
  • How to test NFSv4 server

This instructable will NOT show:

My system specification

Linux rpipro 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 armv6l GNU/Linux

Step 1: Install NFS

Open terminal emulator in Raspberry Pi

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

Install NFS

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

Step 2: Share a Directory

Open terminal emulator in Raspberry Pi

Make a directory to be shared

sudo mkdir -p /srv/nfs4/share
cd /srv/nfs4/share

Create a stub file or put any file in

sudo vi hello.txt

Type the following or whatever:

Hello NFS

Save the file

Add the above directory to be shared and exported

sudo vi /etc/exports

Append the following (192.168.CCC.DDD is the ip address of the client that can read and write to the shared directory):

/srv/nfs4/share 192.168.CCC.DDD(rw,sync,no_subtree_check)

Save the file

Step 3: Modify NFS Init Scripts

The /etc/init.d/nfs-kernel-server script starts the NFS daemon in either NFSv2, NFSv3 and NFSv4 simultaneouly or without NFSv4. The script cannot make NFS operate in NFSv4 only. I modified the script to make it start the daemon in either NFSv2, NFSv3 and NFSv4 simultaneouly or without NFSv4 or NFSv4 only.

Open terminal emulator in Raspberry Pi

cd /etc/init.d

Make backup of nfs-kernel-server script and config file

sudo cp /etc/init.d/nfs-kernel-server /etc/init.d/nfs-kernel-server.pristine
sudo cp /etc/default/nfs-kernel-server /etc/default/nfs-kernel-server.pristine

Download the nfs-kernel-server.script that I uploaded

Read the script

Replace current script with downloaded one

sudo cp path/to/download/nfs-kernel-server.script /etc/init.d/nfs-kernel-server

Download the nfs-kernel-server.cfg that I uploaded

Read the config file
Replace current script with downloaded one

sudo cp path/to/download/nfs-kernel-server.cfg /etc/default/nfs-kernel-server

Make backup of nfs-common parameter file.

cd /etc/default 
sudo cp nfs-common nfs-common.pristine 
sudo vi nfs-common 

Save the file

Step 4: Run the NFSv4 Daemon

Open terminal emulator in Raspberry Pi

Start the NFS service

sudo service nfs-kernel-server start 
[ ok ] Exporting directories for NFS kernel daemon.... 
[....] Starting NFS kernel daemon: nfsdrpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused) 
rpc.nfsd: address family inet6 not supported by protocol TCP 
rpc.nfsd: unable to set any sockets for nfsd

The nfsd fail to start. This failure may not happen for some Raspberry Pi. inet6 refers to implementation ipv6 protocols. This issue can be fixed by loading ipv6 module Specify that ipv6 module is to be loaded at boot time

sudo vi /etc/modules 

Append the following:


Reboot the Raspberry Pi

Check that ipv6 module is loaded

lsmod | grep ipv6 

ipv6 351566 8

Start the NFS service one more time
sudo service nfs-kernel-server start

[ ok ] Exporting directories for NFS kernel daemon....

[....] Starting NFS kernel daemon: nfsdrpc.nfsd: Checking netconfig for visible protocols.

rpc.nfsd: Enabling inet udp.

rpc.nfsd: Enabling inet tcp.

rpc.nfsd: Enabling inet6 udp.

rpc.nfsd: Enabling inet6 tcp.

rpc.nfsd: knfsd is currently down

rpc.nfsd: Writing version string to kernel: -2 -3 +4

rpc.nfsd: Creating inet TCP socket.

rpc.nfsd: Creating inet UDP socket.

rpc.nfsd: Creating inet6 TCP socket.

rpc.nfsd: Creating inet6 UDP socket.

[ ok td.


The message "Writing version string to kernel: -2 -3 +4" is important. The minus sign indicates that NFSv2 and NFSv3 support is dropped. And the message at the end was OK. The NFSv4-only daemon has started!

Step 5: Test With NFSv2, NFSv3 and NFSv4 Clients

Open terminal emulator in a second Raspberry Pi or any Linux system

Install NFS client software

sudo apt-get update 
sudo apt-get install nfs-common

nfs-common package provides a program called /sbin/showmount. showmount show mount information for an NFS server by sending NFSv2 and NFSv3 request.

Use showmount to send NFSv3 request to the NFSv4 server deployed in the previous steps(#192.168.XXX.YYY is the IP address of the NFSv4 server)

showmount -e 192.166.XXX.YYY

clnt_create: RPC: Port mapper failure - Unable to receive: errno 111 (Connection refused)
Explanation: The error message indicates that the NFSv4 server did not respond to any request from NFSv2 and NFSv3 clients as expected.

Make NFSv4 client send mount request to NFSv4 (#192.168.XXX.YYY is the IP address of the NFSv4 server)

sudo mount.nfs4 192.168.XXX.YYY:/ /mnt 

View the content of the hello.txt file that was created in the previous step

cat /mnt/srv/nfs4/share/hello.txt
  Hello NFS
<p>I make nfs server and client on two raspberry pi's 3 (raspbian jessie) when I made file (server side) on my shared place (/home/nfs) I can't see them on client side when I use x window file menager, but when I use terminal, go-&gt; /home/nfs then &quot;ls&quot; I can see that the flie exist. From the other side, when I made file on client /home/nfs appear immediately on server /home/nfs. I'm using VNC to connect with both rpi's. Please help me figure out what can be wrong ? there is any chance that is issue with VNC ? </p>
<p>When trying to install nfs-kernel-server on Wheezy on the RPI2 I've got an error:</p><p>The following packages have unmet dependencies:</p><p> nfs-kernel-server : Depends: libtirpc1 but it is not going to be installed</p><p> Depends: nfs-common (= 1:1.2.6-4) but it is not going to be installed</p><p>E: Unable to correct problems, you have held broken packages.</p>
<p>Hi Dmitry</p><p>I have no problem such as yours on my RPI 2.</p><p>I did the following:</p><p>sudo apt-get update</p><p>sudo apt-get upgrade</p><p>sudo apt-get dist-upgrade</p><p>sudo apt-get install nfs-common nfs-kernel-server</p><p>Maybe you can try the above.</p><p>Best Regards.</p>
<p>I did all above but still have got:</p><p>The following packages have unmet dependencies:</p><p> libtirpc1 : Breaks: nfs-kernel-server (&lt; 1:1.2.8-7) but 1:1.2.6-4 is to be installed</p><p> nfs-common : Breaks: nfs-kernel-server (&lt; 1:1.2.8-6~) but 1:1.2.6-4 is to be installed</p><p> nfs-kernel-server : Depends: nfs-common (= 1:1.2.6-4) but 1:1.2.8-9 is to be installed</p><p>E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.</p>
<p>enter this:</p><p>sudo apt-get -f install</p>
<p>I don't get any of the text output after sudo service nfs-kernel-server start. The cursor blinks for half a second and then I get the prompt back. No [ ok ] etc. Have I done something wrong?</p>
<p>Good info. Using Raspian Jessie, December 29, 2015. Found the changes to /etc/default/nfs-kernel-server had to be manually entered to make the nfs server work on start up. Neither NEED_STATD nor NEED_IDMAPD were in the new configuration file. nfs-kernel-server would start from the command line but would not start on boot up with out those changes. Thanks. </p>
<p>This issue reported here as well:</p><p>https://www.raspberrypi.org/forums/viewtopic.php?f=28&amp;t=110091&amp;p=822196</p>

About This Instructable



Bio: Systems Administrator and Software Programmer.
More by mirza irwan osman:Install Modem USB Device in Raspberry Pi Make the Volume Knob of Sound Blaster X-Fi Surround 5.1 Pro Sound Card Work in Raspberry Pi Create a Volume Control for USB Sound Card in Raspberry Pi 
Add instructable to: