How To Mount Nfs Share On Linux

How To Mount Nfs Share On Linux

Reading time1 min
#Linux#Networking#Storage#NFS#Sysadmin#Mounting

Mastering NFS Share Mounting on Linux: Engineer's Approach

Misconfigured mounts, inconsistent permissions, slow failovers—NFS can be a source of friction in production-grade Linux environments. At the same time, robust NFS integration enables scalable user access and streamlined storage management for distributed systems and CI/CD pipelines.

Below is a practical approach for reliably mounting NFS shares on Linux clients. The focus: minimal downtime, maintainable automount, and enough tuning flexibility for edge cases or legacy systems.


NFS Overview

NFS (Network File System) exposes remote filesystems over the network, allowing a client to mount directories as if they’re local. Unlike ad-hoc file copy or rsync-based sharing, NFS supports state consistency, supports locking (with caveats), and remains a backbone for centralized home directories, container storage backends and even Kubernetes PersistentVolumes in certain bare-metal clusters.

When to pick NFS

  • Multi-host workflows (e.g., HPC, build farms)
  • Centralized user directories (/home over NFS)
  • Dev/test environments sharing build artifacts

For heavy write concurrency or cross-platform needs (e.g., Windows–Linux), consider alternatives like SMB or CephFS.


Prerequisites

Checklist:

  • Confirm remote NFS server is configured and reachable.

  • Linux client running kernel 4.x or newer.

  • User has sudo privileges.

  • Install NFS client utilities:

    DistributionCommand
    Debian/Ubuntusudo apt-get install nfs-common
    CentOS/RHELsudo yum install nfs-utils
  • Network firewalls permit NFS traffic (port 2049 TCP/UDP minimum; rpcbind optional for v3).

A working /etc/exports entry on the server is mandatory. Example:

/srv/nfs/shared 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Note the no_root_squash—only use on trusted networks.


Step 1: Discover server exports

Quickly check available shares:

showmount -e 192.168.1.10

Typical output:

Export list for 192.168.1.10:
/srv/nfs/shared 192.168.1.0/24

If you see rpc: Program not registered, rpcbind is missing or the server is nfs v4-only. V4 doesn't need rpcbind for mounting.


Step 2: Prepare the client mount point

Define distinct mount paths for each environment to avoid accidental data mixups.

sudo mkdir -p /mnt/nfs/shared

Some admins prefer /data/<project> or /srv/mount/<team>. Consistency helps automation.


Step 3: Mount using the CLI

Short-term mount:

sudo mount -t nfs -o vers=4.2 192.168.1.10:/srv/nfs/shared /mnt/nfs/shared
  • vers=4.2 enforces protocol. Drop for auto-negotiation.
  • For v3: -o vers=3
  • Troubleshooting: Add -v (verbose) to see more details if mount hangs.

Verify:

df -hT | grep nfs

Or list files directly:

ls -l /mnt/nfs/shared

If you encounter "mount.nfs: access denied by server," check /etc/exports and for SELinux/AppArmor denials.


Step 4: Automate via /etc/fstab

Add a line to /etc/fstab for persistent mounts:

192.168.1.10:/srv/nfs/shared /mnt/nfs/shared nfs4 nfsvers=4.2,auto,_netdev,hard,noatime 0 0
OptionDescription
_netdevAvoids mount before network is ready
hardRetries indefinitely on failure (not ‘soft’)
noatimeSpeeds up access by suppressing atime update

After editing:

sudo umount /mnt/nfs/shared
sudo mount -a
# Watch for silent failures; check dmesg for mount issues

Known issue: With systemd, automount units (.mount and .automount) can avoid boot hangs if the NFS server is unavailable.


Common Problems and Real Output

Permissions: UID/GID Mismatch

Classic problem: NFS does not map users. If client UID 1001 writes a file, it's owned by 1001 on the server. Ensure consistent UID/GID mapping across hosts.

See also: root_squash/no_root_squash, and consider Kerberos/NFSv4 ACLs for secure environments.

Firewall and Connectivity

Missed ports create long timeouts:

mount.nfs: Connection timed out

Confirm with telnet 192.168.1.10 2049 or ss -tulpn | grep nfs.

Version Mismatch

Some distributions default to NFSv3; others to v4. Forcing the protocol (vers=3 or vers=4.2) reduces negotiation failures.


Performance and Advanced Options

Customize read/write block sizes for large file workloads:

sudo mount -t nfs -o rsize=65536,wsize=65536 192.168.1.10:/srv/nfs/shared /mnt/nfs/shared

Note: Too high values can reduce throughput on poor networks.

If stuck with legacy apps that rely on locking, ensure the nfs-lock service (statd) is active on both client and server.

Diagnostics:
Stale NFS file handle? Try:

umount -f /mnt/nfs/shared && mount -a

NFS4 recommends using a dedicated /export root on the server and exporting pathless roots to avoid complex path translation.


Non-Obvious Tuning Tip

In multi-user environments, cache invalidation can create subtle data visibility lags. Tune with the actimeo, acdirmax, and acregmax options for improved cache refresh rates:

-o actimeo=1

for aggressive cache expiry (at the cost of more server hits).


Summary

  • Confirm server/client compatibility, network visibility, and user mapping.
  • Favor automated fstab or systemd mounts—mitigate with _netdev and hard mount options.
  • Tweak as needed for your workload and organizational standards.

Not every production case can rely on basic NFS. For higher availability, investigate automount (autofs), systemd automount units, or distributed filesystems with client-side caching.


Note:
NFS’s simplicity is both its strength and its pitfall. Missing a single export option or fstab keyword can stall a fleet-wide deployment. Always validate mounts under simulated failure before rollout.


For real-world insights or pain points—drop examples below.