Networking: FreeBSD NFS File Server
Setting up a Free BSD NFS Server:
This is a project that I recently ran into some problems with. I, unfortunately, could not find sufficient documentation on the justlinux.com website to help myself with, so I'm contributing what information I've gathered, in hopes that others will find it useful.
This How-To will assume the following:
- You are familiar with Linux, Free BSD, or other *nix operating systems
- You know basic commands, and are comfortable with editing configuration files
- You have a operating SSH daemon running on the Free BSD machine
- You already have Free BSD successfully installed.
- You have a functional network connection on 2+ *nix boxen (including the Free BSD server)
Step 1: Decide what you want to share, and where you want to share it.
Possibly the most important part of this, is knowing what you're going to do with the NFS shares when you're done. So, let's say you want to create a 'music' share, and a 'movies' share. Simple enough for what we'll be doing.
Next you want to decide how you want to have the shares set up on your Free BSD box.
Do you want to create a new user for each share, and put the files in their ~ directory? Or would you prefer to have 1 user, and export individual directories? Or even have them in
a directory such as /share? That's up to you, it doesn't make a terribly big difference.
For this guide, we'll have 1 user, and export multiple directories from their ~ directory.
Step 2: Create the directories and copy over any needed information
What this step does is create the paths to export. In my case, I already had mp3's that I
wanted to transfer over, so I'll include information on how to do that.
(REMEMBER: Do not put a $ in front of your commands, this is just to show that it is a command)
Step 3: Allow the connections to be accepted on the Free BSD box
$ mkdir music
$ cd music
$ scp -r darkbolt@zion:/home/darkbolt/music/* .
$ cd ../
$ mkdir movies
$ cd movies
$ scp -r darkbolt@zion:/home/darkbolt/movies/* .
This is important, we'll be editing /etc/hosts.allow to accept NFS requests from an internal network.
So open /etc/hosts.allow up with your favorite text editor, I used nano, but many people refer vi/m or gedit, it doesn't really matter.
Add the following at the end
(NOTE: don't include the ' marks)
'portmap : 192.168.0.0/255.255.255.0 : allow'
'portmap : 255.255.255.0 0.0.0.0'
You can save that and exit, if you're using a different IP range for your network, such as 192.168.1.* then adjust the line above accordingly. Simple enough eh?
Step 4: Edit the exports file
Now we're going to tell Free BSD what directories to export. The file that does this is /etc/exports, once again, open it with your favorite text editor.
What's tricky about this, is that if the directories you want to share are on the same partition, then the path's go on the same line. If they're on different partitions, they go on separate lines.
This would be the example for what' we're sharing if they're on the same partition
What the -maproot=darkbolt option does, is if the user that wants to access the exports, is root, it will allow them the privileges of the user 'darkbolt' on the Free BSD server.
/usr/home/darkbolt/music /usr/home/darkbolt/movies -maproot=darkbolt zion
the last part, 'zion' specifies what computers can access it. In my case, zion is the hostname of my slackware box, if you want multiple boxen to be able to access it, list their hostnames/IPs after zion
This now allows zion and 192.168.0.4 to mount the NFS shares.
/usr/home/darkbolt/music /usr/home/darkbolt/movies -maproot=darkbolt zion 192.168.0.4
If the shares are on two different partitions, such as the music share being on ad0s1a and
the movie share on ad0s1b then you want the shares on different lines like this:
Once again, if you want more than just zion to be able to access it, add it after.
/usr/home/darkbolt/music -maproot=darkbolt zion
/usr/home/darkbolt/movies -maproot=darbolt zion
Step 5: Set up the rc.conf to allow NFS sharing to be done by default
Open /etc/rc.conf, and make sure these lines are in it, and uncommented, or add them yourself
Save it, and though it will make you cringe, I know, reboot.
Step 6: Start the daemons
Now its time for the moment of truth, its time to see if the daemons will work.
So as root
If you don't get any output, then that's a good thing, but check /var/log/messages to make sure.
This is it, The server is set up. All you have to do now is mount them on your client machine, but you need a few things first:
If it isn't compiled into the kernel(on Linux),
Step 7: Client mounting
replace bsdbox with your Free BSD hostname/IP address.
# modprobe nfsd
Now you need to run as root
To mount it
mount -t nfs bsdbox:/usr/home/darkbolt/music /mnt/music
For any questions, PLEASE, PLEASE, Post them on justlinux.com so other people can benefit
For corrections or comments, please email me at firstname.lastname@example.org , I check my email multiple times a day.