This guide provides instructions on how to install and configure an NFS server on Rocky Linux 9, including package installation, configuration for sharing the /nfs folder
Step 1: Install Required Packages
- Update your system and install the necessary NFS packages:
sudo dnf update -ysudo dnf install -y nfs-utils policycoreutils-python-utils
Step 2: Create the NFS Share Directory
- Create the directory you want to share via NFS:
sudo mkdir -p /nfs
Step 3: Set Permissions
- Set the appropriate permissions for the NFS share directory:
sudo chown -R nobody:nogroup /nfssudo chmod 777 /nfs
Step 4: Configure NFS Exports
- Edit the NFS exports file to define which directories to share and with whom:
sudo vi /etc/exports
- Add the following line to share the
/nfsdirectory with all clients (or specify a particular IP address or range):/nfs *(rw,sync,no_root_squash)
Step 5: Enable and Start NFS Services
- Enable and start the NFS server and related services:
sudo systemctl enable nfs-serversudo systemctl start nfs-server
Step 6: Configure the Firewall
- Allow NFS traffic through the firewall:
sudo firewall-cmd --permanent --add-service=nfssudo firewall-cmd --permanent --add-service=mountdsudo firewall-cmd --permanent --add-service=rpc-bindsudo firewall-cmd --reload
Step 7: Allow NFS on SELinux on /nfs directory
1. Set the appropriate SELinux file context:
sudo semanage fcontext -a -t nfs_t "/nfs(/.*)?"
2. Apply the file context:
sudo restorecon -Rv /nfs
3. Set SELinux boolean for NFS:
sudo setsebool -P nfs_export_all_rw on
Step 8: Export NFS Shares
- Finally, export the shares defined in the
/etc/exportsfile:sudo exportfs -a
Step 9: Verify the NFS Share
- You can verify that the NFS share is active by running:
sudo exportfs -v