Networking: FreeBSD NFS File Server


Results 1 to 2 of 2

Thread: Networking: FreeBSD NFS File Server

  1. #1
    Join Date
    Jul 2002
    Location
    San Diego, CA
    Posts
    505

    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.
    Examples are:
    • /usr/home/darkbolt/music
    • /usr/home/darkbolt/movies


    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)
    Code:
    	$ mkdir music
    	$ cd music
    	$ scp -r darkbolt@zion:/home/darkbolt/music/* .
    	$ cd ../
    	$ mkdir movies
    	$ cd movies
    	$ scp -r darkbolt@zion:/home/darkbolt/movies/* .
    Step 3: Allow the connections to be accepted on the Free BSD box
    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
    Code:
    	
    	'portmap : 192.168.0.0/255.255.255.0 : allow'
    	'portmap : 255.255.255.0 0.0.0.0'
    (NOTE: don't include the ' marks)

    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

    Code:
    /usr/home/darkbolt/music /usr/home/darkbolt/movies -maproot=darkbolt zion
    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.
    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
    example:
    Code:
    /usr/home/darkbolt/music /usr/home/darkbolt/movies -maproot=darkbolt zion 192.168.0.4
    This now allows zion and 192.168.0.4 to mount the NFS shares.

    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:
    Code:
    		
    		/usr/home/darkbolt/music -maproot=darkbolt zion
    		/usr/home/darkbolt/movies -maproot=darbolt zion
    Once again, if you want more than just zion to be able to access it, add it after.

    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
    Code:
    	nfs_reserved_port_only="YES"
    	nfs_server_enable="YES"
    	mountd_flags="-r"
    	portmap_enable="YES"
    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
    Code:
    	#  /sbin/nfsd
    	# /sbin/mountd
    	# /usr/sbin/portmap
    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
    Code:
    	# modprobe nfsd
    	
    	Now you need to run as root
    	# rpc.portmap
    
    	To mount it
    	mount -t nfs  bsdbox:/usr/home/darkbolt/music /mnt/music
    replace bsdbox with your Free BSD hostname/IP address.

    For any questions, PLEASE, PLEASE, Post them on justlinux.com so other people can benefit

    For corrections or comments, please email me at darkbolt@sfexplore.com , I check my email multiple times a day.
    Join the JustLinux irc chat | irc.freenode.net | #linuxn00b
    San Diego Web Development | Used Computers for Sale

    Slackware Linux | Gentoo Linux | Debian GNU/Linux
    Registerd Linux User #313504

  2. #2
    Join Date
    Apr 2003
    Location
    Buenos Aires, Argentina
    Posts
    4,219
    < searching keywords >
    freebsd
    nfs
    djserz.com.ar
    "All the drugs in this world won't save you from yourself..."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •