NFS Howto

This describes how to configure NFS server in Linux

Configuration on the server:

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

Execute

rpcinfo -p

to check correctness of your NFS installation and to actually confirm that NFS server is indeed running and accepting calls on a port 2049:

# rpcinfo -p | grep nfs
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs

Check support for nfs

# cat /proc/filesystems | grep nfs
nodev nfs
nodev nfs4

When installed correctly, the NFS daemon should be now listening on both UDP and TCP 2049 port and portmap should be waiting for instructions on a port 111.

At this point you should have portmap listening on both NFS server and NFS client:

# rpcinfo -p | grep portmap
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper

Server export file defined in /etc/exports file.

/home/nfs/ 10.1.1.55(rw,sync)
/home/nfs/ 10.1.1.55(rw,sync)
/data 192.168.0.198(rw,sync)

Open your firewall

# ufw allow from [clientIP or clientSubnetIP] to any port nfs
# ufw allow from 192.168.0.198 to any port nfs
# ufw status
2049 ALLOW 192.168.0.198

Restart NFS deamon

# /etc/init.d/nfs-kernel-server restarts

If /etc/exports changed, issue the command

# exportfs -ra

Configuration on the client:

# apt-get install nfs-common
# mkdir /data_homepc
# mount 10.1.1.50:/home/nfs /home/nfs_local
# mount 192.168.0.199:/data /data_homepc

Added entry in /etc/fstab

10.1.1.50:/home/nfs /home/nfs_local/ nfs defaults 0 0
192.168.0.199:/data /data_homepc nfs defaults 0 0

Solving slow boot on client side

When the nfs server is unavailable, the client still waits slowing down the boot. So disabled the offending option.

prabu@onepc-lm:~$ systemd-analyze blame
1min 30.108s data_homepc.mount >
9.563s accounts-daemon.service >
9.533s networkd-dispatcher.service >
8.145s NetworkManager-wait-online.service >
6.606s NetworkManager.service >
6.172s ubuntu-system-adjustments.service >
5.679s udisks2.service >
4.271s dev-sda1.device >
3.849s avahi-daemon.service >
3.682s networking.service
prabu@onepc-lm:~$ sudo systemctl enable rpcbind.service
Synchronizing state of rpcbind.service with SysV service script with
/lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable rpcbind
prabu@onepc-lm:~$ sudo systemctl start rpcbind.service

The above commands did not solve the slowness. On further checking found that there is a timeout option to add in /etc/fstab. It was added

prabu@onepc-lm:~$ cat /etc/fstab
#Mounted /data directory from homepc using nfs
192.168.0.199:/data /data_homepc nfs defaults,x-systemd.mount-timeout=1s 0 0
prabu@onepc-lm:~$ systemctl cat data_homepc.mount
# /run/systemd/generator/data_homepc.mount
# Automatically generated by systemd-fstab-generator
[Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab
Before=remote-fs.target

[Mount]
Where=/data_homepc
What=192.168.0.199:/data
Type=nfs
TimeoutSec=1s
Options=defaults,x-systemd.mount-timeout=1s

Sources:


© Prabu Anand K 2020-2026