definitions#

NFS is one of the network filesystems available on Linux. An NFS server has the NFS service installed and enabled. It hosts the mounted filesystem that shall be made available to remote systems. This action is called export and involves these files:

  • /etc/exports: where I configure the mounted filesystems that need to be remotely available to the defined machines,
  • /var/lib/nfs/etab: is called the master export table. It is populated as soon as an entry, in a correct format, is recorded in the /etc/exports file and exportnfs -a is run. The exportnfs -a command reads the entries of /etc/exports to do its job. I am simplifying these steps with the expression create an NFS share.

create a NFS share#

user1@rhel10-vm1:~$ dnf list --installed nfs-utils
Not root, Subscription Management repositories not updated
Installed Packages
nfs-utils.x86_64               1:2.8.3-5.el10_2                @rhel-10-for-x86_64-baseos-rpms
user1@rhel10-vm1:~

I create a sample directory and give full permissions on it to everyone:

user1@localhost:~$ sudo mkdir /common
[sudo] password for user1: 
user1@localhost:~$
user1@localhost:~$ sudo chmod ugo+rwx /common
user1@localhost:~$ ls -l /common
total 0
user1@localhost:~$ ls /common
user1@localhost:~$ ls -l / | grep commo
drwxrwxrwx.   2 root root    6 Sep 20 19:09 common
user1@localhost:~$ 

I allow the NFS service through the Linux firewall:

user1@localhost:~$ sudo firewall-cmd --permanent --add-service nfs
success
user1@localhost:~$
user1@localhost:~$ sudo firewall-cmd --reload
success
user1@localhost:~$

I enable the NFS service unit now:

user1@localhost:~$ sudo systemctl enable --now nfs-server
[sudo] password for user1: 
user1@localhost:~$ 
user1@localhost:~$ man systemctl 
user1@localhost:~$ systemctl status nfs-server
● nfs-server.service - NFS server and services
     Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; preset: disabled)
     Active: active (exited) since Sun 2026-09-20 20:04:16 CEST; 50s ago
 Invocation: 9e864420f13a430ea2a4cf4e4699c71c
       Docs: man:rpc.nfsd(8)
             man:exportfs(8)
    Process: 4578 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
    Process: 4580 ExecStart=/bin/sh -c /usr/sbin/nfsdctl autostart || /usr/sbin/rpc.nfsd (cod>
    Process: 4608 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl rel>
   Main PID: 4608 (code=exited, status=0/SUCCESS)
   Mem peak: 2M
        CPU: 18ms

Sep 20 20:04:16 localhost.localdomain systemd[1]: Starting nfs-server.service - NFS server an>
Sep 20 20:04:16 localhost.localdomain systemd[1]: Finished nfs-server.service - NFS server an>
user1@localhost:~$

Since I am going to use hostnames in the /etc/exports file, I update them for my lab machines:

user1@localhost:~$ sudo vim /etc/hostname
[sudo] password for user1: 
user1@localhost:~$

I rebooted the machine to see the new hostname. I added an entry to /etc/exports:

user1@rhel10-vm1:~$ cat /etc/exports
user1@rhel10-vm1:~$ cat /common
cat: /common: Is a directory
user1@rhel10-vm1:~$ sudo vim /etc/exports
[sudo] password for user1: 
user1@rhel10-vm1:~$
user1@rhel10-vm1:~$ cat /etc/exports
/common rhel10-vm2(rw)
user1@rhel10-vm1:~$ 

I populate the NFS master table using exportfs which itself uses /etc/exports. Notice that /var/lib/nfs/etab was initially empty then got populated with values:

user1@rhel10-vm1:~$ man exportfs
user1@rhel10-vm1:~$ ls /var/lib/nfs/
etab         .etab.lock   export-lock  nfsdcld/     rpc_pipefs/  statd/       
user1@rhel10-vm1:~$ ls /var/lib/nfs/etab
/var/lib/nfs/etab
user1@rhel10-vm1:~$ cat /var/lib/nfs/etab
user1@rhel10-vm1:~$ 
user1@rhel10-vm1:~$ exportfs -av
exporting rhel10-vm2:/common
exportfs: could not open /var/lib/nfs/.etab.lock for locking: errno 13 (Permission denied)
exportfs: could not open /var/lib/nfs/.etab.lock for locking: errno 13 (Permission denied)
exportfs: can't lock /var/lib/nfs/etab for writing
user1@rhel10-vm1:~$ 
user1@rhel10-vm1:~$ sudo exportfs -av
[sudo] password for user1: 
exporting rhel10-vm2:/common
user1@rhel10-vm1:~$ 
user1@rhel10-vm1:~$ cat /var/lib/nfs/etab 
/common	rhel10-vm2(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,no_all_squash)
user1@rhel10-vm1:~$

To remove the export (unexport), I use exportfs with the -u option and give the argument in this form:

{remoteMachine_as_it_appears_in_etc_exports}:{filesystem_mount_point}

user1@rhel10-vm1:~$ sudo exportfs -uv rhel10-vm2:/common
[sudo] password for user1: 
unexporting rhel10-vm2:/common
user1@rhel10-vm1:~$ 
user1@rhel10-vm1:~$ cat /var/lib/nfs/etab
user1@rhel10-vm1:~$