Thursday, September 11, 2008

HowTo: Setup a NFS server on FreeBSD

On a previous post I went through the needed steps to enable NFS client operations on FreeBSD 7.0 so now lets wrap up with the need steps to setup a NFS server.

Lets begin:
  1. % su
  2. # echo 'nfs_server_enable="YES"' >> /etc/rc.conf
  3. # echo 'rpcbind_enable="YES"' >> /etc/rc.conf
  4. # echo 'mountd_flags="-r"' >> /etc/rc.conf
  5. # echo 'rpc_lockd_enable="YES"' >> /etc/rc.conf
  6. # echo 'rpc_statd_enable="YES"' >> /etc/rc.conf
By passing these options we guarantee that NFS related daemons are started at boot time. Steps 2 to 4 are mandatory and enable the NFS daemons, steps 5 and 6 are optional and are used to guarantee file locking operations over NFS and monitor NFS client so that the NFS server can free resources when the host disappears.

Lets proceed by identifying what we want to share:
  1. % su
  2. # vi /etc/exports
  3. add the following line:
/usr/ports/distfiles -network 192.168.1 -mask 255.255.255.0
Step 3 shares the /usr/ports/distfiles directory and make it available to any client with an IP address beginning in 192.168.1 and netmask of 255.255.255.0.

Now that we've enabled the NFS server settings and configured the exports file, lets start the server by:
  1. % su
  2. # rpcbind
  3. # nfsd -u -t -n 4
  4. # mountd -r
If you perform any changes changes to the exports file, reload it by:
  1. % su
  2. # /etc/rc.d/mountd onereload
Also, the showmount command can be used to display the exports on the server:
  1. % su
  2. # showmount -e
I've focused on the basis to setup a home network NFS share, however there are loads of performance tunning flags that can be set on both server and client sides.
For more detailed documentation take a look into:
http://www.freebsd.org/doc/en/books/handbook/network-nfs.html
http://nfs.sourceforge.net/nfs-howto/index.html

4 comments:

Anonymous said...

this is a perfect howto, it all worked like charm! Thank you very much, you are a true geek!
Kolaloka

tangram said...

Hi,

I'm glad it proved useful.

I try to write the howtos as best as possible because in the future it will be using them. Blame it on my weak memory) ;-)

Regards.

Anonymous said...

Great! it works fine for me..

thank you very much
Marcel from Switzerland

tangram said...

Thanks for the feedback Marcel ;-)