The Network Files System (NFS) allows to access files and directories over the network on Linux (Unix) computers. If there is a Windows computer samba is the alternative to nfs. The computer holding those data must have a nfs server and the computer requesting access to the data must have a nfs client.
There are different major versions and therefore incompatibilities. Having everywhere the same version obviously is a good idea.
To work with nfs, the nfs kernel features need to be enabled. The nfs-utils package needs to be installed.
For Gentoo Linux check also the nfs useflags and the nfs useflags indicating the nfs version.
Finally, check if your number assignments for user and group names are consistent between the computers. cat /etc/passwd and cat /etc/group
See also: http://nfs.sourceforge.net/
To get the client and the server emerge nfs-utils on all computers involved.
The configuration file that has to be edited on the server is
/etc/exports
to define what will be available on the network. See
also man exports
<server directory> <client computer name>(rw) <other server directory> 192.168.1.33(rw)
or as example
/home/lindegur/Urs black(rw,async,no_subtree_check)
Either the clients IP address or the name of the computer have to be added. An example to give read only access to the multimedia directory:
/home/lindegur/media 192.168.1.3(ro,async,no_subtree_check)
Avoid exporting symlinks
mounting As man 5 exports tells, wildcards in ip addresses might work just per accident, so avoid to use them use a netmask instead.
No space is allowed in front of the ( character.
To give all computer in a home net access us a netmask
/home/lindegur/media 192.168.1.0/255.255.255.0(rw,async,no_subtree_check)
or in the form counting the bits in the netmask having a 1
/home/lindegur/media 192.168.1.0/24(rw,async,no_subtree_check)
To start the server (and client) /etc/init.d/nfs start and consider to add it to the init scripts rc-update add nfs default
After editing and when the server is already running type exportfs -a
This is necessary to move the
stuff to /var/lib/nfs/xtab
.
Some commands to show if the system is happy:
rpcinfo -p to see if the daemons are running
showmount -e to see what the server exports
showmount -a to see who accesses the server
Or directly from the kernel cat /proc/fs/nfs/exports
nfs does not use inetd or xinetd,
however it considers the two files /etc/hosts.allow
and
/etc/hosts.deny
from xinetd
for more details.
The data on those computers can simply be mounted as it would be a local disk drive:
mount -t nfs <remote computer>
:/<remote directory>
</local mounting point>
An example:
mount -t nfs 192.168.1.33:/home/lindegur/media /mnt/media
or
mount -t nfs <computername>
:/home/lindegur/media /mnt/media
When done do a umount</local mounting point>
It is also possible to have it mounted without typing a lot by using a line in
/etc/fstab
such as:
<remote computer>
:/<remote dir>
</local mounting point>
nfs user,auto,exec 0 0
After that you can mount -a to get everything mounted that is defined in
/etc/fstab
. The option auto is quite important, when the server is running during boot of the client the
clients mounts the network drives automatically. Otherwise they would have to be mounted manually. If the remote computer is not accessible then boot struggles with retraining to connect and finally after a long time out it continuous with its boot process.
The automounter autofs is a better option since it mounts the network drives just on demand when they are getting accessed.
If your nfs server is not always online you can set noauto in
/etc/fstab
so it will not cause delays on boot due to failures and retries to connect the unavailable nfs server.
<remote computer>
:/<remote directory>
</local mounting point>
nfs user,noauto,exec 0 0
If the server is up you simply can mount the drives manually by mount /mnt/<mountpoint>
.
Instead using /etc/fstab autofs
can be used that mounts the network drive on demand.
Since time is moving and the system evolves things can happen:
If you get IP6 errors when start the server then comment or uncomment IP6 stuff in /etc/netconfig
.
If you get:
mount.nfs: an incorrect mount option was specified
and run nfs version 3 on a new system you might get in troubles since it wants to take version 4. You can fix that with modifying /etc/fstab
to hold the nfsvers=3 parameter:
<remote computer>
:<remote directory>
<local mounting point>
nfs user,auto,exec,nfsvers=3 0 0