Setting up an NFS (Network File System) server involves several steps. Below is a guide to help you set up an NFS server on a Linux system (e.g., Ubuntu).
Step 1: Install NFS Server
First, you need to install the NFS server package. On Ubuntu, you can do this using the following command:
sudo apt update
sudo apt install nfs-kernel-server
Step 2: Create a Directory for NFS Sharing
Create a directory that you want to share over NFS. For example:
sudo mkdir -p /srv/nfs/share
Step 3: Set Permissions
Set the appropriate permissions for the directory. You can adjust the ownership and permissions as needed. For example:
sudo chown nobody:nogroup /srv/nfs/share
sudo chmod 777 /srv/nfs/share
Step 4: Configure NFS Exports
Edit the NFS exports file to specify which directories to share and with whom. Open the file with a text editor:
sudo nano /etc/exports
Add the following line to share the directory with specific clients (replace client-ip with the IP address of the client that will access the NFS share):
/srv/nfs/share client-ip(rw,sync,no_subtree_check)
To allow access from any client, you can use:
/srv/nfs/share *(rw,sync,no_subtree_check)
Step 5: Export the Shared Directory
After editing the exports file, run the following command to apply the changes:
sudo exportfs -a
Step 6: Start and Enable NFS Server
Start the NFS server and enable it to start on boot:
sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server
Step 7: Configure Firewall (if applicable)
If you have a firewall running, you may need to allow NFS traffic. For example, on UFW, you can run:
sudo ufw allow from client-ip to any port nfs
Step 8: Verify NFS Server
You can verify that the NFS server is running and the shared directory is available by using the following command:
showmount -e
This command will list the exported directories.
Step 9: Mount NFS Share on Client
On the client machine, you can mount the NFS share using the following command:
sudo mount -t nfs server-ip:/srv/nfs/share /mnt
Replace server-ip with the IP address of your NFS server and /mnt with the desired mount point on the client.
Summary
By following these steps, you can successfully set up an NFS server on a Linux system. Make sure to adjust the configurations based on your specific requirements and security considerations.
