How to NFSv4 share a ZFS file system on FreeBSD?

Solution 1:

NFSv4 is built in on FreeBSD (Experimental support in 8.x, production quality in 9.x and lter).
The nfsd should be located in /etc/rc.d/nfsd

You should first enable it within rc.conf file or running /etc/rc.d/nfsd onestart

1) Enable nfs
echo nfs_server_enable="YES" >> /etc/rc.conf

For NFSv4 you will also need the following:

echo nfsv4_server_enable="YES" >> /etc/rc.conf (To enable NFSv4)
echo nfsuserd_enable="YES" >> /etc/rc.conf (The NFS user/group info needed for v4)

2) Create directories and export them

# mkdir -p /mnt/{dir1,dir2}
# vi /etc/exports 

(add the following lines to the /etc/exports file)

/mnt/dir1  -alldirs  192.168.1.x/24
/mnt/dir2  -alldirs  192.168.1.x/24

3) restart nfsd either using /etc/rc.d/nfsd restart or service nfsd restart

See The section of the FreeBSD handbook dealing with NFS for more information.