This article presents the methods for preparing a set of directories that can be exported to remote NFS clients under Linux.
Under Linux this is can be accomplished by editing the /etc/exports file.
About the /etc/exports File
The /etc/exports file contains an entry for each directory that can be exported to remote NFS clients. This file is read automatically by exportfs command. If you change this file, you must run the exportfs command before the changes can be affected the way the daemon operates.
Only when this file is present during system startup does the rc.nfs script execute the exportfs command and start the service NFS (nfsd) and MOUNT (mountd) daemons.
Edit the exports file and add the following lines:
* /dir/to/export is the directory you want to export.
* host#.yourdomain.com is the machine allowed to log in this directory.
* The ro option mean mounting read-only. And the rw option mean mounting read-write.
* The root_squash option for not allowing root write access in this directory. And the no_root_squash option for allowing root write access in this directory.
For this change to take effect, you will need to run the following command on your terminal:
# /usr/sbin/exportfs -avr
Next thing is configure automatic mapping to this NFS system:
On your remote linux machine, edit the /etc/fstab and add the following line:
NFS_host_name:/dir/to/export /local/mapping/dir nfs hard,intr 0 0
Save and run the following command:
mount -t nfs -a
to mount all nfs entries in /etc/fstab with the corresponding options.
If you want to experiment with rsize and wsize parameters to get that last bit of performance.
NFS_Server_name:/dir/to/export /local/mapping/dir/ nfs rsize=8192,wsize=8192,timeo=20,retrans=6,async,rw,noatime,intr 0 0
- As with most things in linux, watch the log files. If you get an error on the client when trying to mount a share, look at /var/log/messages on the server. If you get an error like "RPC: program not registered" that means that the portmap service isn't running on one of the machines. Verify all the processes are running and try again.
- The second problem has to do with username mappings, and is different depending on whether you are trying to do this as root or as a non-root user.
If you are not root, then usernames may not be in sync on the client and the server. Type id [user] on both the client and the server and make sure they give the same UID number. If they don't then you are having problems with NIS, NIS+, rsync, or whatever system you use to sync usernames. Check group names to make sure that they match as well. Also, make sure you are not exporting with the all_squash option. If the user names match then the user has a more general permissions problem unrelated to NFS.
And if you cannot find the solution for your problem, please refer to the following url:
/etc/exports is VERY sensitive to whitespace - so the following statements are not the same:
/export/dir hostname (rw,no_root_squash)
The first will grant hostname rw access to /export/dir without squashing root privileges. The second will grant hostname rw privs w/root squash and it will grant EVERYONE else read-write access, without squashing root privileges. Nice huh?