Configuring NFS on the Client
NFS configuration on the client requires you to start the NFS application; create a directory on which to mount the NFS server's directories that you exported via the /etc/exports file, and finally to mount the NFS server's directory on your local directory, or mount point. Here's how to do it all.
Starting NFS on the Client
Three more steps easily configure NFS on the client:
1. | Use the chkconfig command to configure the required nfs and RPC portmap daemons to start at boot. Activate nfslock to lock the files and reduce the risk of corrupted data:
[root@smallfry tmp]# chkconfig --level 35 netfs on
[root@smallfry tmp]# chkconfig --level 35 nfslock on
[root@smallfry tmp]# chkconfig --level 35 portmap on
| 2. | Use the init scripts in the /etc/init.d directory to start the nfs and RPC portmap daemons. As on the server, the examples use the start option, but you can also stop and restart the processes with the stop and restart options:
[root@smallfry tmp]# service portmap start
[root@smallfry tmp]# service netfs start
[root@smallfry tmp]# service nfslock start
| 3. | Test whether NFS is running correctly with the rpcinfo command. The listing of running RPC programs you get must include status, portmapper, and nlockmgr:
[root@smallfry root]# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 32768 status
100024 1 tcp 32768 status
100021 1 udp 32769 nlockmgr
100021 3 udp 32769 nlockmgr
100021 4 udp 32769 nlockmgr
100021 1 tcp 32769 nlockmgr
100021 3 tcp 32769 nlockmgr
100021 4 tcp 32769 nlockmgr
391002 2 tcp 32770 sgi_fam
[root@smallfry root]#
|
NFS and DNS
The NFS client must have a matching pair of forward and reverse DNS entries on the DNS server used by the NFS server. In other words, a DNS lookup on the NFS server for the IP address of the NFS client must return a server name that will map back to the original IP address when a DNS lookup is done on that same server name.
[root@bigboy tmp]# host 192.168.1.102
201.1.168.192.in-addr.arpa domain name pointer 192-168-1-102.my-web-
site.org.
[root@bigboy tmp]# host 192-168-1-102.my-web-site.org
192-168-1-102.my-web-site.org has address 192.168.1.102
[root@bigboy tmp]#
This is a security precaution added into the nfs package that lessens the likelihood of unauthorized servers from gaining access to files on the NFS server. Failure to correctly register your server IPs in DNS can result in "fake hostname" errors:
Nov 7 19:14:40 bigboy rpc.mountd: Fake hostname smallfry.my-web-
site.org for 192.168.1.1 - forward lookup doesn't exist
Making NFS Mounting Permanent
In most cases, users want their NFS directories to be permanently mounted. This requires an entry in the /etc/fstab file in addition to the creation of the mount point directory.
The /etc/fstab File
The /etc/fstab file lists all the partitions that need to be auto-mounted when the system boots. Therefore, you need to edit the /etc/fstab file if you need the NFS directory to be made permanently available to users on the NFS. For the example, mount the /data/files directory on server Bigboy (IP address 192.16801.100) as an NFS-type filesystem using the local /mnt/nfs mount point directory:
#/etc/fstab
#Directory Mount Point Type Options Dump
FSCK
192.168.1.100:/data/files /mnt/nfs nfs soft,nfsvers=2 0
0
This example used the soft and nfsvers options; Table 29.1 outlines these and other useful NFS mounting options you may want to use. See the NFS man pages for more details.
Table 29.1. Possible NFS Mount OptionsOption | Description |
|---|
bg | Retry mounting in the background if mounting initially fails. | fg | Mount in the foreground. | soft | Use soft mounting. | hard | Use hard mounting. | rsize=n | The amount of data NFS will attempt to access per read operation. The default is dependent on the kernel. For NFS version 2, set it to 8192 to assure maximum throughput. | wsize=n | The amount of data NFS will attempt to access per write operation. The default is dependent on the kernel. For NFS version 2, set it to 8192 to assure maximum throughput. | nfsvers=n | The version of NFS the mount command should attempt to use, | tcp | Attempt to mount the filesystem using TCP packets; the default is UDP. | intr | If the filesystem is hard mounted and the mount times out, allow for the process to be aborted using the usual methods such as CTRL-C and the kill command. |
The steps to mount the directory are fairly simple, as you'll see.
Permanently Mounting the NFS Directory
You'll now create a mount point directory, /mnt/nfs, on which to mount the remote NFS directory and then use the mount -a command to activate the mount. Notice how before mounting there were no files visible in the /mnt/nfs directory, this changes after the mounting is completed:
[root@smallfry tmp]# mkdir /mnt/nfs
[root@smallfry tmp]# ls /mnt/nfs
[root@smallfry tmp]# mount -a
[root@smallfry tmp]# ls /mnt/nfs
ISO ISO-RedHat kickstart RedHat
[root@smallfry tmp]#
Each time your system boots, it reads the /etc/fstab file and executes the mount -a command, thereby making this a permanent NFS mount.
|
There are multiple versions of NFS, the most popular of which is version 2, which most NFS clients use. Newer NFS servers may also be able to handle NFS version 4. To be safe, it is best to force the NFS server to export directories as version 2 using the nfsvers=2 option in the /etc/fstab file as shown in the example. Failure to do so may result in an error message:
[root@probe-001 tmp]# mount -a
mount to NFS server '192.168.1.100' failed: server is
down.
[root@probe-001 tmp]#
|
Manually Mounting NFS File Systems
If you don't want a permanent NFS mount, then you can use the mount command without the /etc/fstab entry to gain access only when necessary. This is a manual process; for an automated process, see the section "The NFS automounter."
In this case, you're mounting the /data/files directory as an NFS-type filesystem on the /mnt/nfs mount point. The NFS server is Bigboy whose IP address is 192.168.1.100.
Notice how before mounting there were no files visible in the /mnt/nfs directory, this changes after the mounting is complete:
[root@smallfry tmp]# mkdir /mnt/nfs
[root@smallfry tmp]# ls /mnt/nfs
[root@smallfry tmp]# mount -t nfs 192.168.1.100:/data/files /mnt/nfs
[root@smallfry tmp]# ls /mnt/nfs
ISO ISO-RedHat kickstart RedHat
[root@smallfry tmp]#
Congratulations! You've made your first steps towards being an NFS administrator.
|