How to configure Network File System on Linux
Setting up the Host
Install NFS
sudo dnf install nfs-utils
sudo systemctl enable --now nfs-server
sudo systemctl enable --now rpcbind
Set a shared location
On your NFS host, create a location on the filesystem to share with client computers.
sudo mkdir -p /nfs/exports/myshare
For the NFS service to know to broadcast the existence of your myshare shared location, you must add the location to the /etc/exports file, as well as the IP address you want to give access and the global access permissions.
echo "/nfs/exports/myshare <IP ADDRESS>(rw,no_root_squash,secure,anonuid=65534,anongid=65534,sync)" >> /etc/exports
- /nfs/exports/myshare: The directory being shared.
: The IP address of the client that is allowed to access the share. - The options for the NFS export:
- rw: Read and write access.
- no_root_squash: Allows the root user on the client to have root privileges on the server.
- secure: Requires requests to originate from a port less than 1024.
- anonuid=65534 and anongid=65534: Map anonymous users to the specified UID and GID (usually nobody).
- sync: Ensures changes are written to disk before the server responds.
Set ownership
Use the proper user and group. For example, if the share folder is going to be used for a MySQL database, the proper user:group is 27:27 (or mysql:mysql if it is installed in the host)
sudo chown root:staff /nfs/exports/myshare
sudo chmod 775 /nfs/exports/myshare
Apply the export file changes
sudo exportfs -r
Configure your firewall
sudo firewall-cmd --add-service nfs --permanent
sudo firewall-cmd --reload
Setting up the Client
First, create a mount point for the NFS share:
sudo mkdir /nfs/imports/myshare
And then mount the NFS volume:
sudo mount -v \
-t nfs test_hostname001.utep.edu:/nfs/exports/myshare \
/nfs/imports/myshare/
You can make this a permanent and automatic process by adding the NFS volume to the client's /etc/fstab file:
echo "test_hostname001.utep.edu:/nfs/exports/myshare /nfs/imports/myshare/ nfs rw 0 0" >> /etc/fstab
Validate the Mount is Ready
Check if the mount is showing up as part of the file system:
df