Installing an NFS server
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 -y
sudo 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 /nfs
sudo 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
/nfs
directory 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-server
sudo systemctl start nfs-server
Step 6: Configure the Firewall
- Allow NFS traffic through the firewall:
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --permanent --add-service=mountd
sudo firewall-cmd --permanent --add-service=rpc-bind
sudo 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/exports
file:sudo exportfs -a
Step 9: Verify the NFS Share
- You can verify that the NFS share is active by running:
sudo exportfs -v