Setting Up an NFS Server
Setting up the Configuration Files
There are three main configuration files you will need to edit to set up an NFS server: /etc/exports, /etc/hosts.allow, and /etc/hosts.deny.In real we need to edit /etc/exports to get NFS to work, but then we would be left with an extremely insecure setup. You may also need to edit your startup scripts.
. /etc/exports
This file contains a list of entries; each entry indicates a volume that is shared and how it is shared.An entry in /etc/exports will typically look like this:
directory machine1(option11,option12) machine2(option21,option22)
|
directory
- the directory that you want to share. It may be an entire volume though it need not be. If you share a directory, then all directories under it within the same file system will be shared as well.
- machine1 and machine2
- client machines that will have access to the directory. The machines may be listed by their DNS address or their IP address (e.g., machine.company.com or 192.168.0.8). Using IP addresses is more reliable and more secure. If you need to use DNS addresses, and they do not seem to be resolving to the right machine.
- optionxx
- the option listing for each machine will describe what kind of access that machine will have. Important options are:
- ro: The directory is shared read only; the client machine will not be able to write to it. This is the default.
- rw: The client machine will have read and write access to the directory.
- no_root_squash: By default, any file request made by user root on the client machine is treated as if it is made by user nobody on the server. (Excatly which UID the request is mapped to depends on the UID of user "nobody" on the server, not the client.)
- If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server. This can have serious security implications, although it may be necessary if you want to perform any administrative work on the client machine that involves the exported directories. You should not specify this option without a good reason.
- no_subtree_check: If only part of a volume is exported, a routine called subtree checking verifies that a file that is requested from the client is in the appropriate part of the volume. If the entire volume is exported, disabling this check will speed up transfers.
- sync: By default, all but the most recent version (version 1.11) of the exportfs command will use async behavior, telling a client machine that a file write is complete - that is, has been written to stable storage - when NFS has finished handing the write over to the filesysytem. This behavior may cause data corruption if the server reboots, and the sync option prevents this.
. /etc/hosts.allow and /etc/hosts.deny
These two files specify which computers on the network can use services on your machine. Each line of the file contains a single entry listing a service and a set of machines. When the server gets a request from a machine, it does the following:- It first checks hosts.allow to see if the machine matches a description listed in there. If it does, then the machine is allowed access.
- If the machine does not match an entry in hosts.allow, the server then checks hosts.deny to see if the client matches a listing in there. If it does then the machine is denied access.
- If the client matches no listings in either file, then it is allowed access.
Linux Beginners Guide to NFS Mount Using Exportfs
Using NFS (Network File System), you can mount a disk partition of a remote machine as if it is a local disk. This article explains how to export a file system to a remote machine and mount it both temporarily and permanently.
1. Export File System to Remote Server using exportfs
To export a directory to a remote machine, do the following.
exportfs REMOTEIP:PATH
- REMOTEIP – IP of the remote server to which you want to export.
- : – delimiter
- PATH – Path of directory that you want to export.
2. Mount Remote Server File System as a Local Storage
To mount the remote file system on the local server, do the following.
mount REMOTEIP:PATH PATH
Explanation
- REMOTEIP – IP of the remote server which exported the file system
- : – delimeter
- PATH – Path of directory which you want to export.
3. Unmount Remote File System
Umount the remote file system mounted on the local server using the normal umount PATH. For more option refer to umount command examples.
4. Unexport the File System
You can check the exported file system as shown below.
# exportfs
/publicdata webserver.pq.net
To unexport the file system, use the -u option as shown below.
# exportfs -u REMOTEIP:PATH
After unexporting, check to make sure it is not available for NFS mount as shown below.
# exportfs
5. Make NFS Export Permanent Across System Reboot
Export can be made permanent by adding that entry into /etc/exports file.
# cat /etc/exports
/publicdata webserver.pq.net
6. Make the Mount Permanent Across Reboot
mount can be made permanent by adding that entry into /etc/fstab file.
# cat /etc/fstab
webserver.pq.net:/publicdata /mydata ext3 defaults 0 0
exportfs -a : Exports all shared directories from /etc/exports
exportfs -r : Revises the list of shared directories after you have changed /etc/exports
This sends the appropriate signals to the rpc.nfsd and rpc.mountd daemons to reread the /etc/exports file and update their internal tables
exportfs -u : Unexports all directories
exportfs -v : Display currently shared directories.
If you have an error in your /etc/exports file, it is reported when NFS starts up in syslog
Comments
Post a Comment