Configuring NFSv4 Server with ZFS on FreeBSD: A Complete Guide


2 views

When working with FreeBSD and ZFS, it's important to note that native NFS support is built into the system, not provided through ports like some Linux distributions. The confusion often arises between traditional NFSv3 configuration and the newer NFSv4 implementation.

# Verify existing NFS services
service nfsd status
service mountd status

Your ZFS dataset creation is correct, but we need to modify the sharenfs property specifically for NFSv4:

zfs create tank/project1
zfs set sharenfs="rw=@192.168.1.0/24,no_root_squash" tank/project1
zfs set sharesmb=off tank/project1

FreeBSD's NFS server implementation supports both v3 and v4 protocols. Edit /etc/rc.conf:

# Add these lines
nfs_server_enable="YES"
nfsv4_server_enable="YES"
nfsuserd_enable="YES"
rpcbind_enable="YES"
mountd_enable="YES"
mountd_flags="-r -S"  # -S for v4 state tracking

Create the NFSv4 configuration file at /etc/nfsv4.conf:

# NFSv4 domain (should match across server and clients)
nfsv4_enable="YES"
nfsv4_server_only="NO"
nfsv4_domain="example.com"  # Replace with your domain

After configuration, start the services in the correct order:

service rpcbind start
service nfsuserd start
service mountd start
service nfsd start

If using a firewall, open the necessary ports:

# For IPFW
ipfw add allow tcp from any to any 111,2049,32803
ipfw add allow udp from any to any 111,2049,32803

# For PF
pass in proto { tcp udp } to port { 111 2049 32803 }

Check the export configuration:

showmount -e localhost
zfs get sharenfs tank/project1

On your Linux client, mount the share with:

# Mount with NFSv4
mount -t nfs4 freebsd-server:/tank/project1 /mnt/project1 -o proto=tcp,port=2049

# For persistent mounts, add to /etc/fstab:
freebsd-server:/tank/project1  /mnt/project1  nfs4  rw,hard,intr,proto=tcp,port=2049  0  0

If you encounter issues:

# Check logs
tail -f /var/log/messages

# Verify service status
service nfsd status
service mountd status

# Check RPC services
rpcinfo -p localhost

For better performance with ZFS and NFSv4:

# Set ZFS properties
zfs set primarycache=metadata tank/project1
zfs set atime=off tank/project1
zfs set sync=disabled tank/project1  # For async writes

# Tune NFS server
sysctl vfs.nfsd.server_max_nfsvers=4
sysctl vfs.nfsd.issue_delegations=1

Setting up NFSv4 on FreeBSD differs from the traditional NFSv3 approach, especially when integrating with ZFS. Unlike NFSv3, NFSv4 introduces improved security, stateful operations, and compound RPC calls, making it more suitable for modern networked environments.

Before proceeding, ensure your FreeBSD 9 system meets these requirements:

  • ZFS pool and dataset created (e.g., tank/project1)
  • Root access or sudo privileges
  • Basic networking configured (firewall rules adjusted if necessary)

FreeBSD’s NFSv4 support is built into the base system. No additional ports or packages are required. Follow these steps:

# Enable NFS server in rc.conf  
echo 'nfs_server_enable="YES"' >> /etc/rc.conf  
echo 'nfsv4_server_enable="YES"' >> /etc/rc.conf  
echo 'rpcbind_enable="YES"' >> /etc/rc.conf  

ZFS simplifies NFS sharing via the sharenfs property. Update your dataset:

# Set NFSv4 sharing with specific options  
zfs set sharenfs="rw=@192.168.1.0/24,no_root_squash" tank/project1  
zfs set sharenfs="vers=4" tank/project1  # Enforce NFSv4  

Activate the services without rebooting:

service rpcbind start  
service nfsd start  
service mountd start  # Handles ZFS exports  

Check the export status:

showmount -e  # Lists exported directories  
zfs get sharenfs tank/project1  # Confirms ZFS share properties  

On the Linux host, use the following to mount the NFSv4 share:

sudo mount -t nfs4 freebsd-server:/tank/project1 /mnt/project1  

Add to /etc/fstab for persistence:

freebsd-server:/tank/project1  /mnt/project1  nfs4  rw,hard,intr  0  0  
  • Permission Issues: Ensure no_root_squash is set if root access is needed.
  • Firewall: Open ports 2049 (NFS) and 111 (RPCbind).
  • Logs: Check /var/log/messages for NFS-related errors.