If only UN*X machines are involved, NFS and CUPS are the means of choice. In this lesson we will assume there is a linux-only network (read: Only Linux-PCs will offer and/or ask for files). Windows-PCs can be in the network, but if they want to take part in the sharing, we will have to use the SMB-Protocol. SMB is explained in the Samba-Lesson. For easy comparison, I tried to preserve the structure of the Samba-Lesson also in this document.
Assumptions
-
‘eighty-one’ is our big Linux box with a lot of disk space to give.
-
‘laptop’ is our laptop wanting to use 81′s resources.
-
Name resolution works. That means, /etc/hosts is up to date or other means of resolving hostnames to ip-adresses (e.g. DNS) are set up.
-
The network is configured so that they can ping each other.
-
The user names on both systems should be the same, since it makes things easier for getting started. I use ‘stw’. It makes things easier if the user-IDs are the same on all machines.
-
It is also assumed that you have installed NFS with your favorite package-manager. There are seperate packages for the server and the client. Since a PC can be server and client at the same time, you might want to install both.
-
You know how the NFS-Server is started in your specific installation.
Quickstart: /etc/exports
The main configuration file for the NFS-Server is /etc/exports. The directories to be shared with other computers are listed there. On eighty-one it looks like this:
# /etc/exports /srv/80/NetSpace *(ro,root_squash,sync) /srv/samba/Krone/ laptop(rw,root_squash,sync) /srv/samba/Share laptop(rw,root_squash,sync) /home/stw laptop(rw,root_squash,sync)
The lines starting with a ‘#’ are comments; blanks are ignored. These lines tell the server that /srv/80/NetSpace should be readable (not writable) for all computers on the network, that the remote root-users have no special privileges in this directory and that the transmission in sync’d, which makes sure your data is on disk before the command returns. The other three directories are accessible (read & write) to ‘laptop’ only.
Mounting directories across the network
After starting the NFS-Server (SuSE: ‘rcnfsserver start’, as root) you can mount these directories on ‘laptop’ and they will show up in ‘df’ like this:
laptop:/home/stw # mount -t nfs eighty-one:/home/stw /home/stw/FILES
laptop:/home/stw # mount -t nfs eighty-one:/srv/samba/Krone /SRV/Krone
laptop:/home/stw # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 4,0G 3,1G 698M 82% /
/dev/hda2 4,0G 2,5G 1,3G 66% /Debian
/dev/hda1 28G 19G 9,8G 66% /WinXP
/dev/hda6 20G 8,6G 9,9G 47% /home
tmpfs 252M 0 252M 0% /dev/shm
eighty-one:/srv/samba/Krone
38G 19G 18G 52% /SRV/Krone
eighty-one:/home/stw 38G 19G 18G 52% /home/stw/FILES
As you can see, the mount-command is like allways. Only the device to be mounted consists of the host, a colon and the path on the host. To make things even easier, we can add lines to /etc/fstab like these:
eighty-one:/srv/samba/Krone /SRV/Krone nfs noauto,users,noexec 0 0 eighty-one:/srv/samba/Share /SRV/Share nfs noauto,users,noexec 0 0 eighty-one:/home/stw/ /home/stw/FILES nfs noauto,users,noexec 0 0
These lines will allow mere users to mount the directories when needed (‘mount /SRV/Krone’). If we had a workstation which is permanently connected to the LAN, the directories could be mounted at boottime by ommiting the ‘noauto’.
If you are really brave, combine what you have just read with this: My partition is full! Do I need to reinstall?.
Your Place or my Place? Going Home
We can add more exports to be shared. If we have more than one person using our computers, we might consider putting an export for each one of them to store personal files. These shares could point to the corresponding home-directories of those users. With a growing number of users, the task of administering such a setup gets harder and harder. So we simply mount /home via NFS
# /etc/exports (cont.) /home *(rw,root_squash,sync)
This way, each workstation mounts home from the server, providing users with their files and configurations wherever they log in. It does not matter which WS they use, the files are stored on the server. While this is not the top-solution for laptops which are not always connected to the net, it is really great for usual LAN. (Well, what is ‘usual’ these days, anyway?)
The laptop could have a basic /home as part of its root-partition which allows the users to do at least some basic work. In /etc/fstab /home is mounted via NFS if the network is available. This would hide the contents of the /home on the disk and giving the users all the possibilities they are used to have.
The Note at the Mirror: Sharing Printers
Printers are a kind of hardware which are perfectly suitable for sharing in a network, since usually you don’t need them all the time, and they come in very distinct flavors: Fast black-and-white lasers are cheap, the inkjet printers are not quite so fast and a little more expensive, but they print in color. So even if each computer in a network has a printer of his own, there are occasions, when the other’s printer is just better for the job at hand.
This is where you would use CUPS, which is not part of this lesson (yet?). But it is just about as straightforward to configure as NFS is. (And even has a GUI!)
Behind the Mirror: Windows in the mix
So, the Windows clients want to access our disks too. No problem: As you might have already guessed by the pathnames, the same directory can be shared via NFS and Samba.
In fact I use them both at the same time since I installed SuSE9.0 on my laptop. The smbmnt-command used there is broken, and thus I could not use samba to share disks between two linux-boxes. Setting up NFS way easier that fixing the samba-install on the laptop.
Disclaimer
This is a lesson provided for free (As everything on LBo!). I have shared my knowledge about NFS as well as I was able to. Yet, there might be mistakes, typos, misunderstanding on my part, omissions and many other things that might cause the information in this document to be wrong.
Security has not been taken in to consideration at all! This document only tries to give readers a start in using NFS in a home environment. Where you go from there is your choice, but if you start using NFS seriously, tighten it up!
Assignments
Find out how…
-
…to block access to the NFS-Server (/etc/hosts.allow and /etc/hosts.deny)
-
…to block access to certain exports (/etc/exports)
and look up information (man, info) about the following programs:
-
nfs
-
exports
Be brave! Combine what you have just read with this: My partition is full! Do I need to reinstall? :)
No comments yet.