Install and configure NFS Server on FreeBSD
I will show you in this tutorial, step-by-step, how to setup NFS Server and configure it on FreeBSD system.
Introduction
NFS (or: Network File System) is a distributed file system created first by Sun MicroSystems and an open standard defined in RFC. NFS permit to client user to access (read/write) data (files/directories) on remote share over a network, similar to access data on your hard drive (local storage).
NFS Server installation on FreeBSD
On FreeBSD system, NFS server is installed by default but is disabled, so no need to install it just to enabled it.
Enabling NFS Server
To enable NFS Server you require to edit the file /etc/rc.conf with the following command :
nano /etc/rc.conf
And to add the following five lines to it (to bottom of file) :
rpcbind_enable="YES"
nfs_server_enable="YES"
nfs_server_flags="-u -t -n 4"
mountd_enable="YES"
mountd_flags="-r"
NFS Server Configuration
First, lets create a test directory and name it my_shared_dir with :
mkdir /root/my_shared_dir
Then, you need to edit and input your configuration to the file /etc/exports to allow others clients users on network to mount it and see it.
nano /etc/exports
And add the following line to it that allow the user on network with ip 192.168.8.31 to read/write data to NFS remote share /root/my_shared_dir on NFS server
/root/my_shared_dir -maproot=root:wheel 192.168.8.31
/root/my_shared_dir : is the directory that we have create it to share it over NFS in network.
-maproot=root:wheel : this option let us to set user(root) and group(wheel) to any newly added files by NFS client user on remote server, the absence of this option newly add files nobody user.
192.168.8.31 : is the ip address of NFS client user in network (user that see /root/my_shared_dir), you can specify many ip address separate them with spaces.
You should now restart your machine where NFS server is configured, or alternatively, you can start NFS services manually without rebooting the machine (for first time) with :
rpcbind
nfsd -u -t -n 4
mountd -r
Examples :
/root/my_shared_dir -maproot=root:wheel 192.168.8.31 192.168.8.32 192.168.8.33
if you like to share it to all clients on specified network then :
/root/my_shared_dir -maproot=root:wheel -network 192.168.8 -mask 255.255.255.0
or
/root/my_shared_dir -maproot=root:wheel -network 192.168.8/24
After you have made any changes to /etc/exports file you should restart NFS service to reload newly add configuration and modification :
kill -HUP `cat /var/run/mountd.pid`
or by executing mountd script with
/etc/rc.d/mountd reload
You can read more about NFS services on man documentation :
man exports
man nfsd
man rpcbind
man mountd
On the next tutorial, I will show you How to install and configure NFS Client on FreeBSD.