Printed from http://kimbriggs.com

NFS Setup on Home Fileserver: Linux to Linux File Sharing

Summary: This is a description of what I did to get linux-to-linux file sharing working on a home network where client computers get full access to files on the server without constantly entering a username and password. This method does involve running a script once to mount, or make available, the desired files on the server. This method allows you to work seamlessly with files on a central file server without ever encountering a "shortcut" instead of a network folder, as has happened to me occansionaly when using Samba file sharing. I describe the process using Ubuntu Linux, which means it probably is applicable to Debian GNU/linux.

1. Install NFS Server and Client Software

Using the command line (terminal), type sudo apt-get install nfs-common nfs-kernel-server, or use the Synaptic pacage manager to install the two packages listed on your home file-server. The client machine only needs the "nfs-common" package, which contains the NFS client software. Not completely obvious to a new-comer, but now you know there is no "nfs-client" package.

2. Give Your Computers Fixed IP Addresses

The simplest way to do refer to your computers in a home or SOHO LAN is to use fixed IP addresses. This eliminates an extra step of matching computer names to IP addresses. Computers like numbers better. You can give you system a fixed IP address, even if you use DHCP on your Linksys or other type of router. I give a description how to do this in the Apache2 Virtual Directories How-to. Put all the fixed IP addresses you are using in the /etc/hosts file per the example in the default file.

3. Modify the /etc/exports File

The real trick to making files available for NFS sharing is modifying the /etc/exports file. You can do this with a GUI tool by typing sudo gedit /etc/exports in a terminal and supplying the super-user password. The formatted text below is the complete content of a working file. There is one line for each share. I am sharing all the files from a single user's home directory, but that is not necessary. Following the file (folder) to be shared, there is one entry for each client describing the conditions of the mount. For example, rw means both "read" and "write" permissions are given. I added the "no_subtree_check simply to get rid of a notification message. I can't explain why it's there. It works without it. Note there are commas inside the parentheses, but not outside them. There is no whitespace within the parentheses or between them and the IP address. Including spaces will generate an error. The hash marks (pound signs) are for comments.

***This makes your files mountable in an insecure (writeable) fashion. Do not use for sensitive data.***

# /etc/exports: the access control list for filesystems which may be exported to NFS clients.
# See exports(5).
#
# The user's name (SERVER_USER) on the fileserver needs to be filled in
# Client machines fixed IP addresses should be substituted for the ones below (and add/subtract as needed)
# This file is sensitive to whitespace within each entry
#
/home/SERVER_USER/documents 192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/SERVER_USER/audio 192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/SERVER_USER/music_CDs 192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/SERVER_USER/photos 192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/SERVER_USER/public_html 192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)
/home/SERVER_USER/videos 192.168.1.13(rw,no_subtree_check) 192.168.1.21(rw,no_subtree_check)

4. Creating Mount Points on the Client Machines

In the home directory of your client machines you need to create folders (a.k.a. mount points) so your computer knows where to put the locations of all the files you have access to on the fileserver. I happen to use most of the same name in both places, but that is not necessary. I mount the server's public_html folder to a client folder called "websites". My folders in the example are audio, documents, music_CDs, photos, websites, videos.

5. Mounting the Shares from Client Machines

Sure, there is a way you can have shares automatically mounted via NFS, but for a home network it may be more trouble than it's worth. I have read how you can also go into a permanent "hang" if you have it set on your client but your server isn't on at that time. Let me know if you find an easy way. In the meantime, I click on a terminal shortcut that I put in my top panel and type one command when I need access to the files on the server. They stay mounted until one of the comptuers is turned off. Here is the command.

./mountem.sh

Then I need to enter the super-user password once. The "mounting" of all six shares takes about 1 second. No files are actually transferred to the client. Below is the content of the mountem.sh script, with both the server and client usernames left for you to fill in. The fixed IP in this script is the IP address of the SERVER. It is a plain text file that should be kept in your home directory and made executeable [chmod u+x mountem.sh].

sudo mount 192.168.1.19:/home/SERVER_USER/audio /home/CLIENT_USER/audio -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/documents /home/CLIENT_USER/documents -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/music_CDs /home/CLIENT_USER/music_CDs -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/photos /home/CLIENT_USER/photos -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/public_html /home/CLIENT_USER/websites -o rw
sudo mount 192.168.1.19:/home/SERVER_USER/videos /home/CLIENT_USER/videos -o rw

Once the software is installed and the two files listed above are set up, there is only about 5 seconds worth of effort each time you want to access your files. They are unreachable in the meantime, in the case you do want to keep others from accessing them.

Google
 
CC License Ubuntu Bluefish Editor Graphics by GIMP Eliminate DRM Get Firefox php.net Play Ogg Valid XHTML 1.0 why the icons?