
{{ $('Map tags to IDs').item.json.title }}
How to Mount and Manage NFS Shares Across Linux Systems
The Network File System (NFS) allows you to share files and directories across multiple Linux systems efficiently. This tutorial will guide you through the process of setting up NFS shares and mounting them on client systems.
Prerequisites
- Two Linux systems: one serving as the NFS server and the other as the NFS client.
- Root or sudo privileges on both systems.
- Basic knowledge of using the terminal.
1. Installing NFS
First, ensure NFS is installed on both the server and client systems. To install NFS, run:
- For Ubuntu:
sudo apt update sudo apt install nfs-kernel-server nfs-common -y
- For CentOS/RHEL:
sudo yum install nfs-utils -y
- For Fedora:
sudo dnf install nfs-utils -y
2. Setting Up the NFS Server
Once NFS is installed on the server, you need to create a directory to share. For example:
sudo mkdir -p /srv/nfs/share
Next, change the directory ownership to allow access:
sudo chown -R nobody:nogroup /srv/nfs/share
Edit the NFS export file to configure the shared directory:
sudo nano /etc/exports
Add the following line to the file:
/srv/nfs/share client_IP(rw,sync,no_subtree_check)
Replace client_IP
with the IP address of the client system that will access the share. If you want to allow access to all clients, you can use *(rw,sync,no_subtree_check)
.
3. Applying the NFS Configuration
To apply the changes and export the shared directory, run:
sudo exportfs -a
Finally, start the NFS service:
sudo systemctl restart nfs-kernel-server
You can check the active exports by running:
sudo exportfs -v
4. Mounting NFS Shares on the Client
On the client system, create a mount point where you want to access the shared directory:
sudo mkdir -p /mnt/nfs_share
Now, mount the NFS share using:
sudo mount -t nfs server_IP:/srv/nfs/share /mnt/nfs_share
Replace server_IP
with the actual IP address of your NFS server.
5. Verifying the Mount
To verify that the NFS share is mounted successfully, run:
df -h
This command will display mounted file systems, including your NFS share.
6. Configuring Automatic Mounting
To ensure the NFS share mounts automatically at boot, edit the /etc/fstab
file on the client system:
sudo nano /etc/fstab
Add the following line to the file:
server_IP:/srv/nfs/share /mnt/nfs_share nfs defaults 0 0
Save and exit the editor. Now, the NFS share will automatically mount on reboot.
7. Troubleshooting NFS Issues
If you encounter issues while mounting the NFS share, consider the following troubleshooting steps:
- Check NFS service status:
sudo systemctl status nfs-kernel-server
- Verify firewall rules: Ensure that the firewall allows NFS traffic:
sudo ufw allow from client_IP to any port nfs
- Test connectivity: Ensure that the client can reach the server using ping:
ping server_IP
8. Conclusion
By following this guide, you have successfully set up NFS shares for file sharing between Linux systems. NFS is an efficient and flexible solution for managing shared resources across your network. Remember to monitor and manage your NFS configuration to ensure optimal performance and security.