How to set up a NFS server share on Linux

Published on Aug. 22, 2023, 12:14 p.m.

NFS (Network File System) is available for Linux systems and makes the job extremely easy. Since NFS is built directly into the Linux kernel, it is both powerful and available on every Linux distro.

How to configure an NFS server share on Linux.

How to Set up NFS server

The first thing that we need to do is install the NFS server package.

$ sudo apt install nfs-kernel-server

Or:

$ sudo dnf install nfs-utils

Next, ensure that the NFS service is running and will start automatically.

$ sudo systemctl enable --now nfs-server

we’ll store our NFS share as /media/nfs.

$ sudo mkdir -p /media/nfs

Next, we will edit the /etc/exports file.

$ sudo nano /etc/exports

Each share gets its own line in the file. Across from that, you can list the hostname of an accepted client, if is available in the server’s hosts file.

/media/nfs      192.168.1.0/24(rw,sync,no_subtree_check)

You can include as many shares as you like, provided each has its own line for comparison. You can also include more than one hostname or IP in each line and assign them different permissions.

/media/nfs      192.168.1.112(rw,sync,no_subtree_check) 192.168.1.121(ro,sync,no_subtree_check)

Your share is now accessible from the client machines that you configured in your /etc/exports file.

How to Connect to NFS server from client

First thing we have to do is install the appropriate NFS packages on our system.

$ sudo apt install nfs-common

or

$ sudo dnf install nfs-utils

The NFS share(s) will be available with the package installed. So, to try it out, pick a directory to mount to, and run the mount command as root privileges .

$ sudo mount -t nfs4 192.168.1.110:/media/nfs /media/share

Your NFS server is now ready to start serving files.