Setup an NFSv4 Server
·2 mins
Table of Contents
Installation #
I’m using Rocky Linux:
dnf install nfs-utils -y
Disable NFS Versions 2/3 and RPC Services #
Inside etc/nfs.conf
, look for[nfsd]
and comment/uncomment the following lines:
vers2=n
vers3=n
vers4=y
vers4.0=y
vers4.1=y
vers4.2=y
Disable RPC Services:
[root@rockylinux ~]# systemctl mask --now rpc-statd.service rpcbind.service rpcbind.socket
Created symlink /etc/systemd/system/rpc-statd.service → /dev/null.
Created symlink /etc/systemd/system/rpcbind.service → /dev/null.
Created symlink /etc/systemd/system/rpcbind.socket → /dev/null.
Start and Enable NFS #
systemctl enable --now nfs-server
Setup NFS Directory #
$ mkdir /srv/nfsdata
$ chown -R nobody:nobody /srv/nfsdata
$ echo "test -> nfs" > /srv/nfsdata/test.txt
Define NFS Shares #
With read-write enabled:
[root@rockylinux srv]# cat /etc/exports
/srv/nfsdata 192.168.100.0/24(rw)
Show exports #
All the options except rw
are enabled by default:
[root@rockylinux ~]# exportfs -v
/srv/nfsdata 192.168.100.0/24(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
Open ports #
Only rpc.mountd and nfs are required to be running for Version 4. NFSv4 runs on TCP port 2049:
[root@rockylinux ~]# firewall-cmd --add-service={nfs,mountd} --permanent
success
[root@rockylinux ~]# firewall-cmd --reload
success
Mount on Client #
On Linux:
root@debianlab:~# mount.nfs -o vers=4 192.168.100.132:/srv/nfsdata /mnt/nfstest/
root@debianlab:~#
root@debianlab:~#
root@debianlab:~# ls /mnt/nfstest/
test.txt
root@debianlab:~# cat /mnt/nfstest/test.txt
nfs is working
On macOS:
sudo mount_nfs -o resvport -o vers=4 192.168.100.132:/srv/nfsdata Downloads/nfstest
Configure Automount in fstab #
Creating an entry in /etc/fstab
:
192.168.100.132:/srv/nfsdata /mnt/nfstest nfs rw,soft 0 0
Note: You can’t mount an NFS share as read-write if it was defined as read-only on the NFS server. If you are unable to mount it, do verify your mount options.
Show NFS Mount on client #
The commands listed will only show NFS shares mounted on your system:
$ mount | grep nfs
$ nfsstats --mounts
$ cat /proc/mounts | grep nfs
With NFSv4 you’ll not be able to view an NFS server’s shares(rpcbind is required).
Unmount nfs share from client #
Run umount [host]:[nfs_share]
and modify /etc/fstab
:
umount 192.168.100.132:/srv/nfsdata