MandrakeUser.Org - Your Mandrake-Linux Knowledge Base!


 
 

*DocIndex - Connectivity

NFS I

* Setting Up The Server
* Testing Your Setup

Related Resources:

NFS HOWTO
NFS FAQ
man nfs, man exports, man mount

Revision / Modified: June 23, 2001 / Oct. 31, 2001
Author: Tom Berger

 

NFS, the Network File System, is the protocol of choice when it comes to file-sharing between machines running Linux or other variants of Unix (BSD, Mac OS X, Solaris etc). The nice thing about NFS is that the clients do not need to have support for the underlying file system of the server, you can use for example Mac Os X as a server for Linux clients et vice versa. However, if your network also contains non-Unix machines, you are advised to use a different mechanism, SMB for example.

* Setting Up The Server

To install the necessary software, type

urpmi nfs-utils

This will install the packages portmap, nfs-utils-clients and nfs-utils. Next, start the portmapper (as root):

service portmap start

Notice that all the installed services will be automatically started on next boot, so you don't have to worry about that. For the current session however, you will have to do it by hand.

Before starting the NFS server, you have to define at least one directory to be exported. You define these directories in '/etc/exports'. I just created a new directory '/usr/export' and my '/etc/exports' file looks like this:

/usr/export    192.168.1.0/255.255.255.0(rw)

The first entry is the directory to be exported. The second marks the machine(s) which are allowed to access it, and the third lists NFS options. In this case the exported directory is /usr/export, open for all machines on the 192.168.1.* subnet, and they are allowed to read and write to the directory (default is read-only).
You'll need a new line for every directory you want to export. NFS does not work across mounts, that is a subdirectory of an exported directory will not be exported if it is on different partition or device. You will have to export it explicitly.You can specify different machines with different NFS options for the same directory:

/usr/export    192.168.1.75(ro) 192.168.1.76(rw)etc.

and you can specify them either by IP address or by DNS hostname. To export a directory to all clients, regardless of their IP, just omit the IPs:

/usr/export    (ro)

As for NFS options, there are only two which are of interest: (rw) which enables the clients to write on the exported volume and (no_root_sqash) which allows a root user on a client to exercise root privileges on the exported volume (by default, all NFS clients are using the volume as user 'nobody').
If you change /etc/exports later on, issue

exportfs -ra

every time to make the changes known to the system.

Now start NFS with

service nfs start

Check with

rpcinfo -p

If everything is running correctly you should get something like this:

program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 838 rquotad
100011 2 udp 838 rquotad
100005 1 udp 1031 mountd
100005 1 tcp 1040 mountd
100005 2 udp 1031 mountd
100005 2 tcp 1040 mountd
100005 3 udp 1031 mountd
100005 3 tcp 1040 mountd
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100021 1 udp 1032 nlockmgr
100021 3 udp 1032 nlockmgr
100021 4 udp 1032 nlockmgr

* section index * top

* Testing Your Setup

While it is in theory possible to mount the NFS share on the client right away, I would recommend that you install portmap on it first. Otherwise trying to mount the share may have some strange side effects (I'm not sure if this is a bug or intended). So:

urpmi portmap && service portmap start

Assuming the NFS server is on 192.168.1.75:

mount 192.168.1.75:/usr/export /mnt/disk

mounts /usr/export read-only from the server on /mnt/disk on the client. Do a

mount -v | grep nfs

and you should get

192.168.1.75:/usr/export on /mnt/disk type nfs (ro,addr=192.168.1.75)

Assuming the client's IP is 192.168.1.76, doing a

showmount 192.168.1.75

on the server should return

Hosts on 192.168.1.75: 192.168.1.76

Congratulations, your NFS setup is ready :-).

Mac OS X users can use NFS, too, since Mac OS X is a Unix in its own right.
There's a small but very important difference, however: By default, the Linux implementation uses a privileged port (i.e. a port lower than 1024) for NFS and denies - for security reasons - cooperation with NFS clients using a non-privileged port. But this is what Mac OS X NFS does. So you have to tell the Mac OS X NFS client to use a privileged port when trying to mount an NFS share from a Linux server. This is done with the "-P" option:

mount -o "-P" 192.168.1.75:/usr/export /mnt/share

will mount the Linux NFS share to the directory '/mnt/share' on the Mac OS X client.

* section index * top

* Customizing and securing NFS, Pitfalls

 
Legal: All texts on this site are covered by the GNU Free Documentation License. Standard disclaimers of warranty apply. Copyright LSTB (Tom Berger) and Mandrakesoft 1999-2002.