Whenever two (or more) computers are connected to each other, there are certain things they want to do: Usually files need to be shared among users on the systems and printers should be available for printing from all workstations (and even from the playstations
). The way to achieve this is called protocol. In order to share files and printers, the OSes on all machines involved have to speak the same language, follow the same protocol.
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.
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.
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?
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.
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!)
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.
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!
Find out how…
and look up information (man, info) about the following programs:
Be brave! Combine what you have just read with this: My partition is full! Do I need to reinstall? :)
Copyright (c) by the authors.
Prior to editing, authors agreed to license their contributions by the terms of the GPL.
See our licensing page for details.
Linux® is a registered trademark of Linus Torvalds.