Table of Contents
Advertisement
General Syntax to export NFS share
The general syntax which you must use to create a NFS share using/etc/exports
will be:
/PATH/TO/DIR HOST([OPTIONS])
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 arenew to NFS serverthen I recommend you to first readOverview on NFS and difference between NFSv2 vs NFSv3 and NFSv4
1. Export NFS Share to single host
To export/dump/backups
to single client10.43.138.2
using NFS, I will add below to/etc/exports
:
# cat /etc/exports/dump/backups 10.43.138.2
To refresh the share
# exportfs -rexportfs: No options for /dump/backups 10.43.138.2: suggest 10.43.138.2(sync) 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 theOPTIONS
section to avoid this warning
So I have updated my/etc/exports
/dump/backups 10.43.138.2(sync)
Net refresh the share
Advertisement
# exportfs -r
Now we don't get any warning, verify the existing share
# exportfs -v/dump/backups 10.43.138.2(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
2. Export NFS Share to all hosts
To export a NFS share to whole world (this is adangerousterm 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 aexportfs
share to be accessed by all the hosts from a network IP range i.e.10.43.138.1/27
# cat /etc/exports/dump/backups 10.43.138.2/27(sync)
Or alternatively if you don't have a prefix value, you can provide thenetmask
value of the subnet
# cat /etc/exports/dump/backups 10.43.138.2/255.255.255.224(sync)
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/dump/backups 10.43.138.0/255.255.255.224(sync)/dump/backups 192.168.0.1/255.255.255.0(sync)/dump/backups 192.168.100.10(sync)/dump/backups 10.10.10.0/24(sync)
In this example I am exporting the same path to multiple hosts across different networks.
You can alsoadd them in single linebut to make the file content look clean I am using different entries for the same share. To add all these in the single line, thesyntaxwould be:
/PATH/TO/DIR HOST1([OPTIONS]) HOST2([OPTIONS]) HOST3([OPTIONS])
To use single line share for our last example, we can use:
/dump/backups 10.43.138.0/255.255.255.224(sync) 192.168.0.1/255.255.255.0(sync) 192.168.100.10(sync) 10.10.10.0/24(sync)
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
/dump/backups 10.43.138.0/255.255.255.224(sync)
But you only wish to restrict the share to10.43.138.2
host. In such case this can be tricky.
With NFSv3 we can use hosts.deny to restrict access to such hosts by usingrpcbind, mountd, nfsd, statd, lockd, rquotad
to define an access rule but the same is not possible withNFSv4 as it does not use these daemons any more.
Advertisement
To restrict a host with NFSv3 we will add below entry for10.43.138.2
# echo "rpcbind: 10.43.138.2" >> /etc/hosts.deny
Now if you try to access the NFS share using this hosts:
# mount -o nfsvers=3 10.43.138.1:/dump/backups /mntmount.nfs: access denied by server while mounting 10.43.138.1:/dump/backups
But if I try to access the same share using NFSv4
# mount -o nfsvers=4 10.43.138.1:/dump/backups /mnt
It works. So hosts.denywas unableto 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 10.43.138.2 -p tcp --dport nfs -j DROP# iptables -I INPUT -s 10.43.138.2 -p udp --dport nfs -j DROP
5.2 Restrict NFS shares using firewalld rich rules
# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='10.10.10.4' service name='nfs' reject"# firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='10.10.10.4' service name='mountd' reject"# firewall-cmd --reload
However with wildcards we can have more control over the hosts we wish to allow the access for NFS sharewhich 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
HINT:
Wildcards should not be used with IP addresses; however, it is possible for them to work accidentally if reverse DNS lookups fails. With wildcards you must make sure that the provided hostname is resolving to the IP address either using /etc/hosts or with DNS server.
6.1 Using ? with hostnames
We can use?
wildcard to match a single character in the hostname, for example to matchserver1
,server2
,serve
,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 matchserver12
,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 betweenserver00.example.com
toserver99.example.com
/dump/backups server[0-9][0-9].example.com(sync)
To mapserver1
toserver5
we can use
/dump/backups server[1-5](sync)
To map character with square brackets for example matchserve
tillserverE
, 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
Advertisement
/dump/backups *.example.com(sync)
So this willmatch
mail.example.comcdn.example.comhost.example.com
But this willnot match
ab.cd.example.com
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/dump/backups 10.43.138.2(ro,sync)
Refresh the shares
# exportfs -r
Verify the exported shares and the options:
# exportfs -v/dump/backups 10.43.138.2(sync,wdelay,hide,no_subtree_check,sec=sys,ro,secure,root_squash,no_all_squash)
8. Export NFS share as Read Write Mode
To export a share with read write permission use:
# cat /etc/exports/dump/backups 10.43.138.2(rw,sync)
Refresh and verify the shares and applied options:
# exportfs -r# exportfs -v/dump/backups 10.43.138.2(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,root_squash,no_all_squash)
Now if someone creates a file in these share on the client nodes:
[root@nfs-client ~]# mount -o nfsvers=4 10.43.138.1:/dump/backups /mnt
Create a new file as root user
[root@nfs-client ~]# touch /mnt/file
Verify the permission
[root@nfs-client ~]# ls -ltotal 0-rw-r----- 1nfsnobody nfsnobody0 Aug 20 13:31 file
As you see the new file is created withnobody
permission. By default when NFS share is exported withroot_squash
permission so any file access and modification from root user will be performed under anonymous account so callednobody
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----- 1deepak users0 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
Advertisement
[root@nfs-server ~]# vim /etc/nfs.conf[nfsd] vers2=nto3=nvers4=yvers4.0=yvers4.1=yvers4.2=y
Make sure you disablevers2
andto3
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.socketCreated 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 usingsystemctl status nfs-server
[root@nfs-server ~]# systemctl restart nfs-server[root@nfs-server ~]# systemctl enable nfs-server
Use thenetstat
utility to list services listening on the TCP and UDP protocols:
The following is an examplenetstat
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 nfstcp 0 0 0.0.0.0:nfs 0.0.0.0:* LISTENtcp6 0 0 [::]:nfs [::]:* LISTEN
Next you can create a share using/etc/exports
. We don't need to define any additional permission here:
/dump/backups 10.43.138.2(rw,sync)
Now this share will be accessible only over NFSv4.
HINT:
Similarly you can control the NFS share access over NFSv3 only or you can allow both NFSv3 and NFSv4 usingnfs.conf
10. Enable root access on the NFS share
As informed earlier, by defaultroot_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 useno_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/dump/backups 10.43.138.2(rw,sync,no_root_squash)
To refresh the shares
# exportfs -v/dump/backups 10.43.138.2(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
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
Conclusion
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.
FAQs
How to export NFS share in Linux? ›
On the Linux system that runs the NFS server, you export (share) one or more directories by listing them in the /etc/exports file and by running the exportfs command. In addition, you must start the NFS server. On each client system, you use the mount command to mount the directories that your server exported.
How do I get a list of NFS exports? ›NFS clients can use the showmount -e command to see a list of exports available from an ONTAP NFS server. This can help users identify the file system they want to mount. Beginning with ONTAP 9.4, ONTAP allows NFS clients to view the export list by default.
Which command will export the NFS shares? ›The exportfs command makes local directories available for Network File System (NFS) clients to mount. This command is normally invoked during system startup by the /etc/rc. nfsfile and uses information in the /etc/exports file to export one or more directories, which must be specified with full path names.
What are NFS exports used for? ›NFS is the most common protocol for sharing files between Unix systems over a network. NFS servers export directories from their local hard disks to NFS clients, which mount them so that they can be accessed like any other directory.
What is NFS export in Linux? ›NFS, the Network File System, is a common method for sharing files over a network from a Unix host. In this blog, we'll go over how to create NFS exports (i.e., shares) on a CentOS 8 host, as well as how to mount those exports from a Linux client.
How do I export a NFS file system? ›To export an NFS file system using a text editor: Open the /etc/exports file with your favorite text editor. Create an entry for each directory to be exported using the full path name of the directory. List each directory to be exported starting in the left margin.
How to list all NFS mounts in Linux? ›- # showmount --exports Export list for server1.example.com: /nfs_shares * /priv_shares 192.168.0.0/255.255.255.0 /pub_shares 10.10.10.0/255.255.255.0.
- # showmount --exports 10.10.10.2 Export list for 10.10.10.2: /nfs_shares * /priv_shares 192.168.0.0/255.255.255.0.
The /etc/xtab file lists directories that are currently exported. To display this file, enter the exportfs command without flags or arguments. To alter the file or to alter the characteristics of one of its directories, root users can edit the /etc/exports file and run the exportfs command.
How to check NFS file system in Linux? ›- AIX® operating systems: Type the following command on each computer: lssrc -g nfs The Status field for NFS processes should indicate active . ...
- HP-UX and Solaris operating systems: ...
- Linux® operating systems:
- AIX® operating systems: Type the following command on each computer: lssrc -g nfs The Status field for NFS processes should indicate active . ...
- Linux® operating systems: Type the following command on each computer: showmount -e hostname.
How to use NFS share in Linux? ›
- Installing NFS Server. ...
- Create Root NFS Directory. ...
- Define Access for NFS Clients in Export File. ...
- Make the NFS Share Available to Clients. ...
- Installing NFS Client Packages. ...
- Mounting the NFS File Share Temporarily. ...
- Mounting NFS File Shares Permanently.
NFS vs SMB performance
NFS is the better choice for transferring small and medium files over the network (for example, files of about 1 MB and less in size). Performance for both protocols is similar when transferring large files (for example, 500 MB files). NFS is faster than SMB when using encryption.
The maximum number of NFS exports supported per protocol cluster is 1000. Exporting symbolic links is not supported in CES NFS.
What is the export size of NFS? ›The default value is 8192 bytes. If set to yes, allows NFSv3 and NFSv4 COMMIT operations to be asynchronous. The default value is No.
What is NFS in Linux and how it works? ›A Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. This enables system administrators to consolidate resources onto centralized servers on the network.
What are the different types of NFS in Linux? ›There are three types of NFS mounts: predefined, explicit, and automatic. Predefined mounts are specified in the /etc/filesystems file. Each stanza (or entry) in this file defines the characteristics of a mount.
What is NFS common in Linux? ›NFS allows a system to share directories and files with others over a network. By using NFS, users and programs can access files on remote systems almost as if they were local files.
What is advantage of NFS in Linux? ›The NFS service has the following benefits: Enables multiple computers to use the same files, so everyone on the network can access the same data. Reduces storage costs by having computers share applications instead of needing local disk space for each user application.
Can you export an NFS mount? ›Exporting and mounting directories must be understood in order to administer NFS. An NFS server must export a file or directory, after which an NFS client may mount that file or directory. More details about these concepts are included in this section. Exporting a directory is done on the NFS server.
How to secure NFS exports? ›- Configure the NFS server to export file systems with the least amount of privileges necessary. ...
- Configure the NFS server to export file systems explicitly for the users who should have access to it. ...
- Exported file systems should be in their own partitions.
How is data stored in NFS? ›
In summary, an NFS datastore works by enabling shared access to files and directories over a network. The NFS server hosts the shared files, and clients connect to the server using the NFS client software.
What is the maximum number of NFS mounts? ›Set these values: Under NFS, Select NFS. MaxVolumes: Limits the number of NFS datastores which can be mounted by the vSphere ESXi host concurrently. The default value (32 in ESXi 7.0) can can be increased to a maximum value of 256 (Note: This maximum applies since ESXi 5.
How many NFS connections are there? ›There is NO limit on number of clients which can access single NFS export.
What is the size limit for NFS in Linux? ›Its data transfer size is limited to 8 KB, and it requires that NFS servers commit data written by a client to a disk or non-volatile random-access memory (NVRAM) before responding.
Where are NFS logs? ›OneFS writes log messages associated with NFS events to a set of files in /var/log.
How to check NFS mount connectivity? ›Use the showmount command to display the remote NFS server mount information. If you omit the options, the default option displays hostnames of all remote mounts from the hostname NFS server. If you omit the hostname parameter, then the local hostname is used.
How to check NFS mount issues in Linux? ›- Install the required nfs packages if not already installed on the server # rpm -qa | grep nfs-utils. # yum install nfs-util.
- Use the mount command to mount exported file systems. ...
- Update /etc/fstab to mount NFS shares at boot time.
Another way to check the NFS version is by inspecting the /proc/mounts file, which contains information about the mounted filesystems on the system. In essence, the /proc/mounts file provides a representation of the currently mounted filesystems, resembling the format of the /etc/fstab file.
Which port does NFS use? ›Network File System (NFS) is used by UNIX clients for file access. NFS uses port 2049. NFSv3 and NFSv2 use the portmapper service on TCP or UDP port 111.
Where are NFS logs in Linux? ›By default, the NFS log file is stored in /var/nfs/nfslog.
How do I check NFS share permissions? ›
- Log on as root (only root can mount an NFS export). ...
- Check the permissions by typing: ...
- Assign the appropriate owners to the files and folders by typing: ...
- Assign appropriate permissions to the files and folders by typing: ...
- Verify the new permissions by typing:
- greys@xps:~$ sudo apt install nfs-client. Once installed, showmount can be used to show NFS network shares by specifying an IP address of the NAS server.
- greys@xps:~$ showmount -e 192.168.1.70. Export list for 192.168.1.70:
- /volume1/Stuff 192.168.1.103,192.168.1.102. That's it for today!
Click the Start button, point to Programs, and then click Windows Explorer or Windows NT Explorer. From the Tools menu, click Map Network Drive. The Map Network Drive dialog box opens. In the Path text entry box, type the NFS name of the network resource to which you want to connect.
How to mount NFS file system in Linux? ›- mount [OPTIONS] NFS_SERVER:/PATH/TO/EXPORTED/DIR /MOUNT_POINT_ON_CLIENT.
- # NFS_SERVER:/PATH/TO/EXPORTED/DIR /MOUNT_POINT_ON_CLIENT TYPE_OF_FS OPTIONS DUMP PASS 10.10.0.10:/backups /var/backups nfs defaults 0 0.
- # umount /MOUNT_POINT.
- # umount NFS_SERVER:/PATH/TO/EXPORTED/DIR.
- umount.nfs4: <mount_point>: device is busy.
- sudo apt update sudo apt install nfs-common.
- sudo yum install nfs-utils.
- mount [OPTION...] ...
- sudo mkdir /var/backups.
- sudo mount -t nfs 10.10.0.10:/backups /var/backups.
- sudo mkdir /var/backups.
- sudo nano /etc/fstab.
- Install the required nfs-utils package if it was not already installed by default.
- Start the NFS services by issuing the following commands: systemctl start rpcbind systemctl start nfs-server.
- Enable the NFS services by issuing the following command: systemctl enable nfs-server.
In this tutorial, we discussed the Network File System in detail. The main benefits of using NFS are centralized data storage, increased efficiency, data security, and scalability. However, it's not a good choice for sharing sensitive data over public networks and doesn't support hierarchical storage management.
Can you export a share for both NFS and CIFS? ›You can create a file share that supports both CIFS and NFS by specifying the access control list and export policy.
What is the difference between 3 SMB share and NFS share? ›Summary: NFS versus SMB
NFS runs in Unix/Linux and Windows; SMB needs Samba to do so. NFS file locking is mandatory or advisory, but SMB locking is mandatory. NFS has no fast file find; SMB has fast find. NFS no server and printer browsing, while SMB has server and printer browsing.
Memory: 6 GB RAM. Graphics: NVIDIA GeForce GTX 750 Ti 2GB, AMD Radeon HD 7850 2GB, or equivalent DX11 compatible GPU with 2GB of memory. DirectX: Version 11. Storage: 30 GB available space.
What is the transfer rate of NFS? ›
The NFS server and client communicate over a 100 MB per second Ethernet network. When sequentially writing a small file, the throughput averages around 10 MB per second. However, when writing a very large file, the throughput average drops to well under 1 MB per second.
What are the minimum requirements for NFS server? ›To install a dedicated NFS server, you can use any operating system that provides NFS. Additionally, the NFS server must meet the following hardware requirements: 16 GB RAM, 8 CPU cores, and 100 GB free disk space.
What is MTU size in NFS? ›The MTU is the maximum amount of data that can be sent via an Ethernet frame. The default MTU is typically 1500 (1,500 bytes per frame), but this can be changed fairly easily.
How do I see current NFS exports? ›NFS clients can use the showmount -e command to see a list of exports available from an ONTAP NFS server. This can help users identify the file system they want to mount. Beginning with ONTAP 9.2, ONTAP allows NFS clients to view the export list by default.
What is the default size of NFS? ›There is no fixed default value for rsize and wsize . By default, NFS uses the largest possible value that both the server and the client support.
What is NFS in Linux interview questions? ›Network File System (NFS) is one of the oldest computer file sharing products in existence today. It is still the most popular for sharing directories of files between UNIX and Linux systems.
How to export NFS share in Linux for Windows? ›- Find out nfsnobody UID and GID using command grep nfsnobody /etc/fstab.
- Often this will be 65534.
- Now export your share with options rw,sync,no_root_squash,all_squash,anonuid=65534,anongid=65534.
- Use showmount to show NFS shares.
- Use exportfs to show NFS shares.
- Use master export file /var/lib/nfs/etab to show NFS shares.
Start a linux terminal, Using the Built-in Terminal and ShadowXafe, or ssh to get to a command prompt on your Linux box. Run showmount -e against the machine with the NFS shares. See the example: showmount -e 192.168.
How to mount NFS share in Linux client? ›- First, create a directory to serve as the mount point for the remote NFS share: sudo mkdir /var/backups. ...
- Mount the NFS share by running the following command as root or user with sudo privileges: sudo mount -t nfs 10.10.0.10:/backups /var/backups.
How do I know where NFS share is mounted? ›
You can use showmount to display information about mounted file systems exported by Server for NFS on a specified computer. If you don't specify a server, this command displays information about the computer on which the showmount command is run.
What is NFS share in Linux? ›NFS allows a system to share directories and files with others over a network. By using NFS, users and programs can access files on remote systems almost as if they were local files.
How do I know if NFS share is mounted? ›Use the showmount command to display the remote NFS server mount information. If you omit the options, the default option displays hostnames of all remote mounts from the hostname NFS server. If you omit the hostname parameter, then the local hostname is used.
Where is NFS configuration file in Linux? ›Configuring a system to share files and directories using NFS is straightforward. Every filesystem being exported to remote users via NFS, as well as the access rights relating to those filesystems, is located in the /etc/exports file.
Where is NFS log file in Linux? ›By default, the NFS log file is stored in /var/nfs/nfslog.
How to check NFS permissions in Linux? ›- Log on as root (only root can mount an NFS export). ...
- Check the permissions by typing: ...
- Assign the appropriate owners to the files and folders by typing: ...
- Assign appropriate permissions to the files and folders by typing: ...
- Verify the new permissions by typing: