How to setup an NFS share in Linux

The Network File System (NFS) is a popular way to share files and folders across multiple computers running Linux and other operating systems. Setting up an NFS share is relatively straightforward, and can be done in just a few steps.

  • First, make sure that the NFS server is installed on the computer that will be sharing its files. On most Linux distributions, this can be done by running the following command:
sudo apt-get install nfs-kernel-server
  • Next, create the directory that you want to share. This can be any directory on the server computer, and can be named anything you like. For example:
sudo mkdir /srv/nfs-share
  • Now you need to tell the NFS server which files and folders to share. This is done using the /etc/exports configuration file. Open this file using your favorite text editor, and add a line that specifies the directory you just created, along with the options for the share. For example:
/srv/nfs-share *(rw,sync,no_subtree_check)
  • Save the /etc/exports file, and then restart the NFS server to apply the changes. This can be done using the following command:
sudo systemctl restart nfs-kernel-server
  • At this point, the NFS share is set up and ready to use. To access the share from a client computer, you need to mount the directory on the client. This can be done using the mount command, along with the IP address of the server and the name of the shared directory. For example:
sudo mount /mnt/nfs-share
  • You should now be able to access the files and folders in the shared directory from the client computer. If you want to make the mount permanent, you can add an entry to the /etc/fstab file on the client. This will cause the directory to be automatically mounted at boot time.

In summary, setting up an NFS share in Linux is a simple process that involves installing the NFS server, creating the directory to be shared, configuring the /etc/exports file, and mounting the share on the client. With a little bit of effort, you can easily share files and folders across multiple Linux computers.

Leave a Reply

Your email address will not be published. Required fields are marked *