NFS DocumentationNetwork File System (NFS) allows a system to share directories and files with others over a network. Users and programs can access files on remote systems almost as if they were local files. MidnightBSD includes NFS support derived from FreeBSD 13.x, supporting NFSv3 and NFSv4.
NFS is commonly used to share home directories across multiple machines, provide centralized storage, or mount read-only media such as installation trees. MidnightBSD supports both the traditional kernel-based NFS server and client as well as integration with ZFS dataset sharing.
To enable the NFS server at boot, add the following lines to /etc/rc.conf:
rpcbind_enable="YES"
nfs_server_enable="YES"
mountd_enable="YES"
mountd_flags="-r"
nfsv4_server_enable="YES"
The rpcbind service is required for NFSv3. If you only intend to use NFSv4,
it is optional. The mountd daemon manages mount requests from clients and
reads /etc/exports to determine which file systems may be exported.
You can also enable the NFS server status monitor, which helps clients recover after a server reboot:
rpc_statd_enable="YES"
rpc_lockd_enable="YES"
After editing /etc/rc.conf, start the services without rebooting:
service rpcbind start
service nfsd start
service mountd start
The /etc/exports file controls which file systems the NFS server exports and
to which hosts. Each line specifies a file system path followed by export options and
a list of allowed hosts or networks.
A simple export allowing full access from a single host:
/usr/home/shared -alldirs 192.168.1.10
Export a directory read-only to an entire network:
/usr/local/share/data -ro -network 192.168.1.0 -mask 255.255.255.0
Export a directory with read-write access to multiple hosts:
/tank/media -alldirs 192.168.1.10 192.168.1.11 192.168.1.12
For NFSv4, you must define an export root using the V4: keyword and
specify the NFSv4 root path:
V4: /tank
/tank/home -alldirs 192.168.1.0/24
/tank/media -ro 192.168.1.0/24
Common export options include:
-ro — export read-only-alldirs — allow mounting of any subdirectory-maproot=0 — map remote root user to local root (use with caution)-maproot=nobody — map remote root to the nobody user-mapall=nobody — map all remote users to nobody-network — restrict access to a network address range-mask — subnet mask used with -networkAfter modifying /etc/exports, reload the export table without restarting
the server:
service mountd reload
To enable the NFS client at boot, add the following to /etc/rc.conf:
rpcbind_enable="YES"
nfs_client_enable="YES"
For NFSv4 clients, also add:
nfsv4_client_enable="YES"
To mount an NFS share manually, use the mount command:
mount -t nfs 192.168.1.100:/tank/home /mnt/home
To mount an NFSv4 share explicitly:
mount -t nfs -o nfsv4 192.168.1.100:/tank/home /mnt/home
To mount NFS shares automatically at boot, add entries to /etc/fstab:
192.168.1.100:/tank/home /mnt/home nfs rw,noatime 0 0
A read-only fstab entry:
192.168.1.100:/usr/local/share/data /mnt/data nfs ro,noatime 0 0
Common mount options for NFS clients include:
rw / ro — read-write or read-onlynoatime — do not update access times, improves performancesoft — return errors after a timeout instead of hanging indefinitelyhard — keep retrying until the server responds (default)intr — allow interrupting a hung NFS mount with a signalnfsv4 — force NFSv4 protocoltcp — use TCP instead of UDP (recommended for reliability)To start NFS client services without rebooting:
service rpcbind start
service nfsclient start
ZFS datasets can be shared over NFS directly using ZFS properties, without manually
editing /etc/exports. This approach manages NFS exports alongside the
datasets themselves.
First, enable the ZFS sharing service in /etc/rc.conf. The standard NFS
server daemons must also be enabled as described in the server setup section above:
zfs_enable="YES"
nfs_server_enable="YES"
mountd_enable="YES"
rpcbind_enable="YES"
To share a ZFS dataset over NFS, set the sharenfs property. A value of
on exports the dataset using default options:
zfs set sharenfs=on tank/home
You can pass NFS export options directly as the property value:
zfs set sharenfs="-alldirs -ro -network 192.168.1.0 -mask 255.255.255.0" tank/media
Allow read-write access from a specific host:
zfs set sharenfs="-alldirs 192.168.1.10" tank/projects
To disable NFS sharing on a dataset:
zfs set sharenfs=off tank/home
To view the current sharenfs setting on a dataset:
zfs get sharenfs tank/home
To see all datasets with NFS sharing enabled:
zfs get sharenfs
After setting ZFS NFS properties, share all configured datasets and update the running export table:
zfs share -a
Note that ZFS-managed NFS exports and entries in /etc/exports can coexist.
The mountd daemon reads both sources when loading exports.
If clients cannot connect, verify that the server's firewall allows traffic on the
NFS-related ports. For NFSv4, TCP port 2049 is required. NFSv3 additionally uses
rpcbind (port 111) and dynamic ports for mountd and
statd.
To fix mountd dynamic port assignments for firewall rules, pin them
in /etc/rc.conf:
mountd_flags="-r -p 1234"
rpc_statd_flags="-p 1235"
rpc_lockd_flags="-p 1236"
To see what file systems are currently exported by the server:
showmount -e localhost
To check which clients have active mounts:
showmount -a localhost
On the client side, to list available exports from a server:
showmount -e 192.168.1.100
If an NFS mount hangs, check that rpcbind is running on both the
server and client, and that the server's nfsd and mountd
processes are active:
service rpcbind status
service nfsd status
service mountd status