The Handbook

    Theme
    • Guides
        • Check a system before installing FreeBSD
        • Orient a Linux administrator on FreeBSD
        • Supported FreeBSD releases
        • Choose a FreeBSD documentation and support channel
        • Move files safely without GNU mv -t
        • Update and Upgrade FreeBSD
        • Upgrade 14.4 or 15.0 to FreeBSD 15.1
        • Choose packages, ports, or poudriere
        • Choose the quarterly or latest package branch
        • Choose a FreeBSD download or package mirror
        • Make a system setting persistent
        • Run a command from cron reliably
        • Configure locale, keyboard, and time zone
        • Configure a serial console for recovery
        • Choose a custom kernel, module, or loader setting
        • Run a Linux binary with the compatibility layer
        • Check desktop and laptop hardware before installation
        • Choose and check a graphics driver
        • Choose Xorg or Wayland
        • Build a maintainable desktop baseline
        • Install and check a desktop browser
        • Check laptop Wi-Fi, power, and suspend
        • Check multimedia readiness
        • Choose and configure a printing stack
        • Run Windows applications with Wine
        • Snapshot and replicate a ZFS dataset
        • Choose a filesystem and storage layout
        • Operate ZFS without losing the recovery path
        • Restore files from a ZFS snapshot
        • Find what is using ZFS space
        • Grow a ZFS virtual disk
        • Read ZFS pool health and run a scrub
        • Replace a failed device in a ZFS mirror
        • Replicate a ZFS dataset over SSH
        • Change PF safely on a remote host
        • Configure a narrow WireGuard tunnel
        • Share a directory with NFS
        • Share files with a named Samba account
        • Plan a FreeBSD home server
        • Choose a mail server or an outgoing relay
        • Publish a network service safely
        • Choose a jail network model
        • Choose native jails or a jail manager
        • Choose a jail or a bhyve virtual machine
        • Establish a FreeBSD security baseline
        • Choose a MAC policy
        • Audit security-relevant activity
        • Start a DTrace performance investigation
    • Integrations
        • Create a first jail with Bastille
        • Compare jail managers and OCI tooling
        • Publish a Bastille service through PF
        • Mount a ZFS dataset in a Bastille jail
        • Update and upgrade Bastille jails
        • Back up and restore a Bastille jail
        • Prepare bhyve and vm-bhyve
        • Choose NFS or Samba for file sharing
        • Choose ZFS backup automation
        • Build a first signed poudriere repository
        • Operate a signed poudriere repository
        • Manage FreeBSD configuration with Ansible or Salt
        • Run Motion with webcamd on FreeBSD
        • Design a reverse proxy, certificates, and monitoring
    • FAQ
      • Troubleshooting
          • Recover an interrupted freebsd-update run
          • Resolve a package repository or ABI mismatch
          • Diagnose the FreeBSD boot path
          • Recover with a ZFS boot environment
          • Diagnose DNS, routing, and firewall paths
          • Diagnose network mbuf exhaustion
          • Bind a service to a low port without running it as root
          • Diagnose a service that will not start
          • Diagnose audio output or input
          • Diagnose webcamd, cuse, and a webcam
          • Fix USB device permissions without opening every device
      • About this handbook
      • Synopsis
      • Match the intended account
      • Prepare a narrow server filesystem
      • Start the server and locking services
      • Mount from the client
      • Enable and verify writes
      • Mount at boot when required
      • Primary references

      Share a directory with NFS

      Last reviewed
      7 November 2026
      Applies to
      15.1-RELEASE
      Tested on
      15.1-RELEASE

      Synopsis #

      Use NFSv3 with AUTH_SYS only between trusted clients whose numeric user and group identities are coordinated. The client supplies those identities; mapping client root to nobody does not stop a client administrator from impersonating another UID. For an untrusted network, choose a stronger authentication and transport design before exporting data.

      This procedure uses server 192.0.2.10, client 192.0.2.20, and dataset zroot/share mounted at /srv/share. Replace the documentation addresses with private addresses and substitute the actual pool. Keep NFS, mountd, rpcbind, and locking services inside the trusted network or VPN. Export restrictions do not replace a firewall.

      Match the intended account #

      On both systems, inspect the account that will use the files:

      $ id shareuser
      

      Its UID and primary GID must agree numerically. Matching account names alone are insufficient. If creating a dedicated account, select unused IDs on both hosts; for example:

      # pw groupadd -n shareuser -g 2001
      # pw useradd -n shareuser -u 2001 -g shareuser -m -s /bin/sh
      

      Do not renumber an existing account without reviewing ownership of its existing files.

      Prepare a narrow server filesystem #

      On the server:

      # zfs create -o mountpoint=/srv/share zroot/share
      # chown shareuser:shareuser /srv/share
      # chmod 0770 /srv/share
      

      Create a small file as shareuser, rather than as root:

      $ printf 'shared data\n' > /srv/share/example
      $ chmod 0600 /srv/share/example
      

      Add this read-only entry to /etc/exports, preserving other exports:

      /srv/share -ro -maproot=nobody 192.0.2.20
      

      The explicit client address matters. An entry without clients can export the filesystem to every reachable client.

      Start the server and locking services #

      Enable the server services and TCP NFS:

      # sysrc rpcbind_enable=YES nfs_server_enable=YES mountd_enable=YES
      # sysrc nfs_server_flags='-t'
      # sysrc rpc_statd_enable=YES rpc_lockd_enable=YES
      # service rpcbind start
      # service nfsd start
      # service statd start
      # service lockd start
      

      Starting nfsd also starts mountd. Review an existing nfs_server_flags value before replacing it. NFSv3 uses RPC services in addition to TCP 2049; opening only that port is insufficient. Review actual listeners and the site’s firewall policy:

      # sockstat -4 -6 -l
      $ showmount -e 192.0.2.10
      

      Mount from the client #

      On the client:

      # sysrc nfs_client_enable=YES rpc_statd_enable=YES rpc_lockd_enable=YES
      # service nfsclient start
      # service statd start
      # service lockd start
      # mkdir -p /mnt/share
      # mount -t nfs -o nfsv3,tcp 192.0.2.10:/srv/share /mnt/share
      

      As shareuser, read the file and attempt a temporary write:

      $ cat /mnt/share/example
      $ touch /mnt/share/write-check
      

      Reading should succeed; the write should report a read-only filesystem. Client root should not be able to read the private file through this export. These are distinct checks of filesystem ownership, export policy, and root mapping.

      Enable and verify writes #

      Unmount on the client:

      # umount /mnt/share
      

      On the server, remove only -ro from the selected export:

      /srv/share -maproot=nobody 192.0.2.20
      

      Reload the exports:

      # service mountd reload
      

      Mount again on the client with the preceding mount command. As shareuser, check create, rename, read, and delete operations:

      $ umask 027
      $ printf 'client data\n' > /mnt/share/write-check
      $ mv /mnt/share/write-check /mnt/share/renamed-check
      $ cat /mnt/share/renamed-check
      $ stat -f '%u:%g %Lp' /mnt/share/renamed-check
      $ rm /mnt/share/renamed-check
      

      Check the same file’s numeric ownership on the server before deleting it when diagnosing identity problems. Applications that use advisory locks also need working locking services on both systems. A successful copy alone does not qualify an application’s locking or concurrent-write behavior.

      Mount at boot when required #

      After a successful manual mount, add one client /etc/fstab entry:

      192.0.2.10:/srv/share /mnt/share nfs rw,nfsv3,tcp 0 0
      

      Perform a controlled reboot and repeat the account, mount, and file checks. A boot-time mount depends on the server and network being available; retain administrative access when adding it. Use umount /mnt/share before changing the mount or removing the entry.

      A writable share is an access path, not a backup. Keep snapshots and an independent copy, and use selective ZFS recovery when a client damages a file.

      Primary references #

      • FreeBSD Handbook: NFS
      • exports(5)
      • nfsd(8)
      • mount_nfs(8)
      • rpc.lockd(8)
      • fstab(5)

      Independent documentation. Not affiliated with or endorsed by the FreeBSD Project or the FreeBSD Foundation.

      Report a bug
      • Synopsis
      • Match the intended account
      • Prepare a narrow server filesystem
      • Start the server and locking services
      • Mount from the client
      • Enable and verify writes
      • Mount at boot when required
      • Primary references