10 practical examples to export NFS shares in Linux

Deepak Prasad


General Syntax to export NFS share

The general syntax which you must use to create a NFS share using /etc/exports will be:


Each line in the file specifies one remote mount point. The first field contains the mount-point directory path, followed optionally by a list of options and/or a list of specific hosts separated by white space. If no specific hosts are specified, the mount point is exported to all hosts.

If you are new to NFS server then I recommend you to first read Overview on NFS and difference between NFSv2 vs NFSv3 and NFSv4


1. Export NFS Share to single host

To export /dump/backups to single client using NFS, I will add below to /etc/exports:

# cat /etc/exports

To refresh the share

# exportfs -r
exportfs: No options for /dump/backups suggest to avoid warning

Since we have not provided any OPTIONS to the NFS share we get this warning. It will work but it is recommended to add atleast "sync" in the OPTIONS section to avoid this warning

So I have updated my /etc/exports


Net refresh the share

# exportfs -r

Now we don't get any warning, verify the existing share

# exportfs -v


2. Export NFS Share to all hosts

To export a NFS share to whole world (this is a dangerous term in production but actually that is what this means). We will use "*" to enable NFS access to the share to all the networks out there which has access to your NFS server

# cat /etc/exports
/dump/backups *(sync)

So here we have added no restriction in the exports file for the NFS Share for any of the hosts


3. Export NFS Share to IP Range

Now instead of single host, we will create a exportfs share to be accessed by all the hosts from a network IP range i.e.

# cat /etc/exports

Or alternatively if you don't have a prefix value, you can provide the netmask value of the subnet

# cat /etc/exports


4. Export NFS share to multiple hosts

To export a share to multiple hosts across different network range you must create individual entry of respective hosts.

# cat /etc/exports

In this example I am exporting the same path to multiple hosts across different networks.

You can also add them in single line but to make the file content look clean I am using different entries for the same share. To add all these in the single line, the syntax would be:


To use single line share for our last example, we can use:



5. Restrict a NFS share for specified hosts

We can restrict a share in /etc/exports itself by providing only those list of hosts who should be allowed to access the share. But sometimes when you have provided an entire network in the allow list of /etc/exports for example


But you only wish to restrict the share to host. In such case this can be tricky.

With NFSv3 we can use hosts.deny to restrict access to such hosts by using rpcbind, mountd, nfsd, statd, lockd, rquotad to define an access rule but the same is not possible with NFSv4 as it does not use these daemons any more.

To restrict a host with NFSv3 we will add below entry for

# echo "rpcbind:" >> /etc/hosts.deny

Now if you try to access the NFS share using this hosts:

# mount -o nfsvers=3 /mnt
mount.nfs: access denied by server while mounting

But if I try to access the same share using NFSv4

# mount -o nfsvers=4 /mnt

It works. So hosts.deny was unable to block this request.
To overcome this you may rely on firewall to block the respective host from accessing your NFS server


5.1 Restrict NFS shares using iptables

# iptables -I INPUT -s -p tcp --dport nfs -j DROP
# iptables -I INPUT -s -p udp --dport nfs -j DROP


iptables rule to restrict NFS
iptables rule to restrict NFS


5.2 Restrict NFS shares using firewalld rich rules

# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='' service name='nfs'  reject"
# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='' service name='mountd'  reject"
# firewall-cmd --reload


firewalld rule to restrict NFS
List firewalld rule

However with wildcards we can have more control over the hosts we wish to allow the access for NFS share which we will learn next.


6. How to use wildcard with NFS exports

Machine names may contain the wildcard characters * and ?, or may contain character class lists within [square brackets]. This can be used to make the exports file more compact


6.1 Using ? with hostnames

We can use ? wildcard to match a single character in the hostname, for example to match server1, server2, serverA, serverX we can use:

/dump/backups server?(sync)

If you wish to match for more than one character then you can use ? more than one times. For example to match server12, server23, serverAB, serverXY we can use:

/dump/backups server??(sync)


6.2 Using square brackets with hostnames

You can use square brackets to define a range of numbers or characters. Below example will match all machines with hostname between server00.example.com to server99.example.com

/dump/backups server[0-9][0-9].example.com(sync)

To map server1 to server5 we can use

/dump/backups server[1-5](sync)

To map character with square brackets for example match serverA till serverE, in such case use:

/dump/backups server[A-E](sync)


6.3 Using * with hostnames

As you can assume, * means match everything. So assuming you have multiple subdomains under example.com then you can simply use *.example.com to match for all the sub-domains

/dump/backups *.example.com(sync)

So this will match


But this will not match


So to match this you must use:

/dump/backups *.*.example.com(sync)

So I hope you got the idea.


7. Export NFS Share as Read Only Mode

To assign a share with read only permission:

# cat /etc/exports

Refresh the shares

# exportfs -r

Verify the exported shares and the options:

# exportfs -v


8. Export NFS share as Read Write Mode

To export a share with read write permission use:

# cat /etc/exports

Refresh and verify the shares and applied options:

# exportfs -r
# exportfs -v

Now if someone creates a file in these share on the client nodes:

[root@nfs-client ~]# mount -o nfsvers=4 /mnt

Create a new file as root user

[root@nfs-client ~]# touch /mnt/file

Verify the permission

[root@nfs-client ~]# ls -l
total 0
-rw-r----- 1 nfsnobody nfsnobody 0 Aug 20 13:31 file

As you see the new file is created with nobody permission. By default when NFS share is exported with root_squash permission so any file access and modification from root user will be performed under anonymous account so called nobody user.

Although if you create a file using normal user then the same will be reflected as user and owner of the file:

[deepak@nfs-client ~]$ ls -l /mnt/
total 0
-rw-r----- 1 nfsnobody nfsnobody 0 Aug 20 13:31 file
-rw-r----- 1 deepak    users     0 Aug 20 13:36 file1


9. Export a share with NFSv4 only

If you wish create a share which can be accessed over NFSv4 only then you ust modify /etc/nfs.conf

[root@nfs-server ~]# vim /etc/nfs.conf

Make sure you disable vers2 and vers3 to only allow connection over NFSv4

Optionally, disable listening for the RPCBIND, MOUNT, and NSM protocol calls, which are not necessary in the NFSv4-only case. Disable related services:

[root@nfs-server ~]# 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.

After you configure NFS server, restart the NFS server to activate the changes and enable it start automatically post reboot. You can also check nfs status using systemctl status nfs-server

[root@nfs-server ~]# systemctl restart nfs-server
[root@nfs-server ~]# systemctl enable nfs-server

Use the netstat utility to list services listening on the TCP and UDP protocols:

The following is an example netstat output on an NFSv4-only server; listening for RPCBIND, MOUNT, and NSM is also disabled. Here, nfs is the only listening NFS service:

[root@nfs-server ~]#  netstat --listening --tcp --udp | grep nfs
tcp        0      0   *               LISTEN
tcp6       0      0 [::]:nfs                [::]:*                  LISTEN

Next you can create a share using /etc/exports. We don't need to define any additional permission here:


Now this share will be accessible only over NFSv4.


10. Enable root access on the NFS share

As informed earlier, by default root_squash permission is added to the NFS share which means this permission prevents remote root users from having superuser (root) privileges on remote NFS-mounted volumes. Here, squash literally means to squash the power of the remote root user

So to enable root access we will use no_root_squash which allows root user on the NFS client host to access the NFS-mounted directory with the same rights and privileges that the superuser would normally have.

To disable root squash we use:

# cat /etc/exports

To refresh the shares

# exportfs -v


Recommended Read

To learn more about different supported NFS exports options for NFS server and client I would recommend you to read:
Beginners guide to different NFS mount and exports options with examples



In this tutorial I shared multiple examples with different scenarios to export NFS share with and without restrictions. It is important that with NFS we also consider the security of these shares so that it is not accessed by unauthorized users over the network so you must assign the NFS options properly.

Lastly I hope the steps from the article to configure NFS exports share on Linux was helpful. So, let me know your suggestions and feedback using the comment section.

Views: 956

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can reach out to him on his LinkedIn profile or join on Facebook page.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment

GoLinuxCloud Logo

We try to offer easy-to-follow guides and tips on various topics such as Linux, Cloud Computing, Programming Languages, Ethical Hacking and much more.

Programming Languages