News
🐧 Linux Tutorials Mount an NFS Share Permanently with fstab

Mount an NFS Share Permanently with fstab

Connect a remote NFS export to your Linux machine, verify it works, then add it to /etc/fstab so it survives reboots without hanging the system.

NFS lets you treat a directory on another machine as a local filesystem. Once mounted, every tool — your editor, shell scripts, backup jobs — sees it as an ordinary directory. The goal is to make it mount automatically at boot, reliably, without hanging the system if the server is temporarily unreachable.


What you need

  • An NFS server already exporting a share (this tutorial covers the client side only)
  • The server's IP address or hostname
  • nfs-common (or nfs-utils) installed on the client:
sudo apt install nfs-common      # Debian / Ubuntu
sudo dnf install nfs-utils       # RHEL / Fedora / Rocky

Step 1 — Verify the export is reachable

Before touching fstab, confirm the server is advertising its exports:

showmount -e 192.168.1.10
Export list for 192.168.1.10:
/mnt/data    192.168.1.0/24
/home/shared *

If showmount hangs or returns nothing, check three things: the server is running the NFS service, the firewall is not blocking port 2049 (NFS) or 111 (portmapper), and your client's IP falls within the allowed range in the export definition.


Step 2 — Test the mount manually

Create a local mount point:

sudo mkdir -p /mnt/data

Mount manually to confirm the connection works:

sudo mount -t nfs 192.168.1.10:/mnt/data /mnt/data

Verify:

df -h /mnt/data
ls /mnt/data

If you can see the remote files, the connection is good. Unmount before adding to fstab to avoid a duplicate entry conflict:

sudo umount /mnt/data

Step 3 — Add the entry to /etc/fstab

The fstab format is:

<device>    <mountpoint>    <type>    <options>    <dump>    <pass>

A solid NFS entry looks like this:

192.168.1.10:/mnt/data    /mnt/data    nfs    defaults,_netdev,nofail,timeo=15,retrans=2    0    0

What the options do:

  • _netdev — marks this as a network device so the system waits for the network to come up before attempting the mount, rather than trying during early boot.
  • nofail — if the mount fails, the system continues booting instead of dropping to a recovery shell. Without this, a missing NFS server bricks the boot sequence.
  • timeo=15 — timeout in tenths of a second before retrying after a lost response. The kernel default is 600 (60 seconds), which means a dead server causes a very long hang. timeo=15 means 1.5 seconds.
  • retrans=2 — number of retries before giving up. Combined with a short timeout, this keeps a dead server from blocking the system for more than a few seconds.

For a read-only share, swap defaults for ro:

192.168.1.10:/home/shared    /mnt/shared    nfs    ro,_netdev,nofail,timeo=15,retrans=2    0    0

The final two columns (dump and pass) should always be 0 0 for NFS — NFS shares should not be included in dump backups or verified by fsck.

Building an fstab entry by hand is easy to get slightly wrong. The fstab Visual Editor lets you fill in each field with validation and generates the exact line to paste, including correct option combinations.


Step 4 — Test without rebooting

sudo mount -a

-a mounts everything in fstab that is not already mounted. If there is a syntax error in your entry, you will see it here rather than at boot time — which is a much better moment to find out.

df -h /mnt/data

If the share appears in the output, the entry is correct.


NFS version

Modern systems negotiate NFSv4 by default. If you need to pin a version:

192.168.1.10:/mnt/data    /mnt/data    nfs4    _netdev,nofail,timeo=15,retrans=2    0    0

Or force version 3 when the server does not support v4:

192.168.1.10:/mnt/data    /mnt/data    nfs    vers=3,_netdev,nofail,timeo=15,retrans=2    0    0

NFSv4 is generally preferred — it uses a single port (2049), which simplifies firewall rules, and handles authentication more cleanly.


Common errors

mount.nfs: access denied — the server's export does not include your client's IP. Check /etc/exports on the server. After editing it, reload with sudo exportfs -ra.

Mount hangs at boot. _netdev is missing from the fstab options, so the system is trying to mount before the network interface is ready. Add it.

Permission denied on files. NFS maps UIDs. If your user has UID 1001 on the client but the files are owned by UID 1000, you will be treated as a different user. Align UIDs between client and server, or configure no_root_squash carefully on the server export.