Share
Share
Step-by-Step Guide to Set Up an NFS Server on Linux
Step 1: Install NFS Server Packages
- Update the package repository:
sudo apt update - Install the NFS server package:
For Debian/Ubuntu-based systems:
sudo apt install nfs-kernel-server
For RHEL/CentOS-based systems:
sudo yum install nfs-utils
Step 2: Create and Configure the Shared Directory
- Create a directory to share:
sudo mkdir -p /srv/nfs/shared - Set the appropriate permissions:
sudo chown nobody:nogroup /srv/nfs/shared sudo chmod 755 /srv/nfs/shared
Step 3: Configure NFS Exports
- Edit the NFS exports file: Open the /etc/exports file in a text editor:
sudo nano /etc/exports - Add the directory to be shared: Add the following line to the file to share the directory with specific client IP addresses or subnets:
/srv/nfs/shared 192.168.1.0/24(rw,sync,no_subtree_check)- /srv/nfs/shared: The directory to be shared.
- 192.168.1.0/24: The IP address range of the clients allowed to access the share.
- rw: Read and write permissions.
- sync: Writes changes to disk before responding.
- no_subtree_check: Disables subtree checking for better performance.
Save and close the file.
Step 4: Export the Shared Directory
- Export the shared directory:
sudo exportfs -a - Restart the NFS server:
sudo systemctl restart nfs-kernel-server
Step 5: Configure Firewall (if applicable)
- Allow NFS traffic through the firewall:
For UFW (Uncomplicated Firewall) on Debian/Ubuntu:
sudo ufw allow from 192.168.1.0/24 to any port nfs
For firewalld on RHEL/CentOS:
sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --reload
Step 6: Verify NFS Server Configuration
- Check the NFS exports:
sudo exportfs -v - Verify the NFS server status:
sudo systemctl status nfs-kernel-server
Step-by-Step Guide to Set Up an NFS Client on Linux
Step 1: Install NFS Client Packages
- Update the package repository:
sudo apt update - Install the NFS client package:
For Debian/Ubuntu-based systems:
sudo apt install nfs-common
For RHEL/CentOS-based systems:
sudo yum install nfs-utils
Step 2: Create a Mount Point
- Create a directory to mount the NFS share:
sudo mkdir -p /mnt/nfs/shared
Step 3: Mount the NFS Share
- Mount the NFS share:
sudo mount -o rw 192.168.1.100:/srv/nfs/shared /mnt/nfs/shared- 192.168.1.100: The IP address of the NFS server.
- /srv/nfs/shared: The shared directory on the NFS server.
- /mnt/nfs/shared: The mount point on the client machine.
- Verify the mount:
df -h
Step 4: Make the Mount Permanent
- Edit the /etc/fstab file: Open the /etc/fstab file in a text editor:
sudo nano /etc/fstab - Add the NFS
192.168.1.100:/srv/nfs/shared /mnt/nfs/shared nfs defaults,rw 0 0