Skip to content

Set Up a Restricted Linux NFS Share

Admin
October 5, 2026
8 min read
Intermediate
💻 Target OS: Ubuntu 24.04+ / Debian 12+ / RHEL 9+

Before you begin

  • Applies to:Linux NFS servers and clients. Package commands cover Debian or Ubuntu and Fedora or RHEL-family systems.
  • Where to start:Start on the NFS server for the export configuration. Switch to the approved client for mount and access checks.
  • What you need:Have administrative access on both hosts, the export path, and the intended client address or network.
Guide tools
Guide tools
0/0 Steps (0%)

Network File System (NFS) lets Linux clients access a server-side directory over the network. This walkthrough starts with a read-only export limited to a private test subnet. Use your organization’s approved package, firewall, and identity-management procedures before making it reachable to other hosts.


01

Install the NFS Server Package

Server Setup

Install on the intended server. The service name differs across distributions. Avoid running two NFS server implementations at once.

Terminal window
# Debian or Ubuntu
sudo apt update
sudo apt install nfs-kernel-server
sudo systemctl enable --now nfs-kernel-server
# Fedora or RHEL family
sudo dnf install nfs-utils
sudo systemctl enable --now nfs-server
❯ Illustrative Output (Results Vary)
Active: active (exited) or active (running), depending on distribution

02

Create a Dedicated Export Directory

Directory Access

Use a new directory for the export and give it an owner/group that matches your access model. Numeric user and group IDs need to be consistent between clients and server unless you use a centralized identity service.

Terminal window
sudo test ! -e /srv/nfs/team-readonly || { echo 'Export path already exists; inspect it before changing ownership or permissions.' >&2; exit 1; }
sudo test ! -L /srv/nfs/team-readonly || { echo 'Export path is a symlink; inspect it before continuing.' >&2; exit 1; }
sudo install -d -o root -g root -m 0755 /srv/nfs/team-readonly
sudo stat -c '%A %U:%G %n' /srv/nfs/team-readonly
❯ Illustrative Output (Results Vary)
drwxr-xr-x root:root /srv/nfs/team-readonly

03

Allow Only the Intended Client Network

Export Policy

Add one export rule. The example subnet is reserved for documentation; substitute the exact client CIDR. ro makes the export read-only, sync requests synchronous replies, and root_squash maps remote root to an unprivileged identity (the usual safer default).

Terminal window
# Inspect existing exports and add this line with an editor, avoiding duplicate entries:
sudoedit /etc/exports
# Add only after replacing the documentation CIDR with the approved client subnet:
# /srv/nfs/team-readonly 192.0.2.0/24(ro,sync,root_squash)
sudo exportfs -rav
sudo exportfs -v
❯ Illustrative Output (Results Vary)
exporting 192.0.2.0/24:/srv/nfs/team-readonly
/srv/nfs/team-readonly 192.0.2.0/24(ro,wdelay,root_squash,...)
Linux terminal showing the restricted read-only NFS export and active NFS server service

Terminal: Verify the export is restricted to the client subnet and the NFS service is active.


04

Mount from One Test Client

Client Validation

Install the NFS client tools on the client, create a temporary mount point, and mount the share for a read test. Use the server’s resolvable name or approved address. This temporary mount disappears at reboot.

Terminal window
# Debian or Ubuntu client
sudo apt install nfs-common
# Fedora or RHEL family client
sudo dnf install nfs-utils
sudo test ! -e /mnt/team-readonly || { echo 'Mount point already exists; inspect it and choose an empty directory.' >&2; exit 1; }
sudo test ! -L /mnt/team-readonly || { echo 'Mount point is a symlink; inspect it before continuing.' >&2; exit 1; }
sudo install -d -o root -g root -m 0755 /mnt/team-readonly
sudo mount -t nfs nfs01.example.net:/srv/nfs/team-readonly /mnt/team-readonly
findmnt /mnt/team-readonly
touch /mnt/team-readonly/should-fail.txt
❯ Illustrative Output (Results Vary)
TARGET SOURCE
/mnt/team-readonly nfs01.example.net:/srv/nfs/team-readonly
touch: cannot touch ...: Read-only file system

05

Check the Export and Close the Test Mount

Verification

On the server, confirm the effective export and service health. On the client, confirm the mount options and unmount after testing. Add a persistent /etc/fstab entry only after the mount, DNS, routing, and boot-order behavior are understood.

Terminal window
# Server
sudo exportfs -s
systemctl --no-pager --full status nfs-server 2>/dev/null || \
systemctl --no-pager --full status nfs-kernel-server
# Client
findmnt -no SOURCE,FSTYPE,OPTIONS /mnt/team-readonly
sudo umount /mnt/team-readonly
❯ Illustrative Output (Results Vary)
Confirm only the intended subnet is listed and the client mount is gone.

Further reading: exports(5) and nfs(5).

Comments