how to Debian / Ubuntu Linux: Setup NFSv4 File Server

In Debian and Ubuntu Linux, you can set up an NFSv4 file server to share files with other systems on the network. Here are the basic steps to set up an NFSv4 file server:

  1. Install the NFS server software by running the following command:
sudo apt-get install nfs-kernel-server
  1. Create a directory that you want to share over NFS. For example:
sudo mkdir /srv/nfs
  1. Add the directory to the /etc/exports file. This file contains a list of directories that are exported by the NFS server. For example:
sudo nano /etc/exports
/srv/nfs *(rw,sync,no_subtree_check,no_root_squash)

The options in the parenthesis are:

  • rw : allows read and write access to the shared directory.
  • sync: ensures that changes made to the shared directory are immediately written to disk.
  • no_subtree_check : speeds up directory lookups
  • no_root_squash : allows the root user on the client systems to have the same level of access to the shared directory as the root user on the server.
  1. Start the NFS service:
sudo systemctl start nfs-kernel-server
  1. Enable the NFS service to start automatically at boot time:
sudo systemctl enable nfs-kernel-server
  1. On the clients, install the NFS client software:
sudo apt-get install nfs-common
  1. Mount the shared directory on the clients:
sudo mount server_ip:/srv/nfs /mnt
  1. You can check if the mount was successful by running mount command and looking for the entry of the NFS share in the output or by ls /mnt

Please note that the above steps are a basic setup for NFSv4 and for more secure and robust setup please consider setting up firewall rules, setting up authentication and authorization and also implementing a backup strategy.

Also, it’s good practice to test the NFS setup with a small set of files and users before deploying it to a production environment.

Leave a Comment