Sharing files through NFS
This tutorial is probably only interesting for you if you use Linux on your computers at home and want them to easily access files on the router. Although there are NFS clients for Windows it would probably be easier to use Samba for them. The goal here is to describe how to share the public_html folder of the myweb user via NFS so it can be mounted on a Linux computer and the web contents manipulated without the need for ftp. It's important to understand that access control in Unix is based on your username and UID. Every computer involved in NFS filesharing has to have the same userids defined and those userids also have to have identical UIDs on each computer. In large environments this is impossible to maintain so services like NIS or OpenLDAP are used there to provide mapping. But in your local home environment this is overkill so this guide assumes that you take care of the syncing. When you add users in FreeBSD and Linux, you always have a choice to specify the UID, you just have to remember that when you define your users.
You need a few services running for the NFS server to work. Add these lines to /etc/rc.conf.
A third service called mountd is also necessary but it will start automatically as soon as you start the NFS server so you don't need an extra line in /etc/rc.conf for it.
What you do need however is a file where you define what folder or folders you want to share and to whom. This file is called /etc/exports so let's create it.
# ee /etc/exports
The detailed syntax of this file is described in the manual page but you only need to enter one simple line to share your web folder.
/usr/home/myweb/public_html -alldirs -network 192.168.69.0 -mask 255.255.255.0
First on the line is the path to the folder you want to share but since you also want to access all its subfolders you have to add the option -alldirs. The rest of the line defines who can access this share. In this example you export the share to your whole internal LAN. Any computer on your LAN is allowed to mount this share but you could as well have defined unique computers. The details are all in the manual page. Don't forget to adjust the subnet to match the one you use on your own LAN. Now start the services manually.
# /etc/rc.d/rpcbind start Starting rpcbind. # /etc/rc.d/nfsd start Starting mountd. Starting nfsd.
It should now be possible to mount this folder from your Linux computer with the following command and of course you have to adjust the IP address and the mount point to match your own preferences.
# mount 192.168.69.1:/usr/home/myweb/public_html /mnt/router
- /etc/exports is the configuration file for your shares.
- /etc/rc.d/rpcbind and /etc/rc.d/nfsd are the start/stop scripts for the NFS server.
- Network File System (NFS) in the FreeBSD handbook.