How to Set Up and Configure an NFS Server on Linux
Setting up a Network File System (NFS) server on Linux can be very useful for sharing files and folders between multiple systems over a network. NFS allows multiple users to access the same files and folders simultaneously, making it an ideal solution for sharing data in larger organizations or for teams working on collaborative projects.
In this article, we will go through the steps required to set up and configure an NFS server on Linux.
Step 1: Install the NFS Server Package
The first step is to install the NFS server package on the Linux system that you want to use as a server. In most cases, the package name is NFS-utils, and you can install it with the following command:
“`
sudo apt-get install nfs-utils
“`
Step 2: Create a Directory to Export
Once you have installed the NFS server package, you need to create a directory on the server that will be used to export the files and folders to other systems on the network. You can do this by using the mkdir command:
“`
sudo mkdir /nfs
“`
Step 3: Configure the Exports File
The exports file is used to determine the directories that the NFS server will export to the other machines on the network. You need to configure the exports file to allow access to the directory that you created in Step 2.
Edit the exports file:
“`
sudo nano /etc/exports
“`
Add the following line to the file to allow access to the directory you created:
“`
/nfs *(rw,sync,no_subtree_check)
“`
The * symbol indicates that all systems on the network are allowed to access the directory.
Step 4: Restart the NFS Server
After updating the exports file, you need to restart the NFS server with the following command:
“`
sudo systemctl restart nfs-kernel-server
“`
Step 5: Allow NFS through the Firewall
If you are using a firewall on your server, you need to configure it to allow NFS traffic. You can do this by opening the NFS ports (2049, 111, and 20048) with the following command:
“`
sudo ufw allow from any to any port 2049,111,20048 proto tcp
sudo ufw allow from any to any port 2049,111,20048 proto udp
“`
Step 6: Mount the NFS Share on Client Machines
After configuring the NFS server, you can now mount the NFS share on client machines. You can do this by using the mount command, specifying the IP address or hostname of the NFS server and the directory path that you want to mount:
“`
sudo mount 192.168.1.10:/nfs /mnt
“`
The IP address (192.168.1.10) should be replaced with the IP address or hostname of the NFS server.
Conclusion
In this guide, we have explained how to set up and configure an NFS server on Linux. By following these steps, you can easily share files and folders between multiple systems on a network. There are many other settings that can be configured to further customize your NFS implementation, but this guide provides a good starting point for most users.