Article

DamianMyerscough's picture
article
Reads:

6514

Score:
0
0
 
Comments:

0

NFS – Network File System

(View Disclaimer)

In this article we are going to look at setting up and configuring an NFS (Network File System) server to export part of the servers file system We will also look at configuring a NFS client which will mount the file system remotely on the network and allow users to write their data to this file system.

Installation

The installation of the NFS server is very simple, you can install the NFS server using the YaST utility either via a curses based interface or a GUI (Graphical User Interface). In this article we will be installing the NFS server via the command line using the yast sw_single command which will bring up a cruses based screen.

Once you have started the YaST utility you will need to search for a package called: "nfs-utils", this package contains the NFS server and client utilities. Once you have installed the "nfs-utils" package you can issue the rpm -q nfs-utils command which will check to see if the package exists in the RPM database as shown in Figure 1.

linux-mw4w:~ # rpm -q nfs-utils
nfs-utils-1.0.7-36.21

Figure 1: Querying the "nfs-utils" package.

As you can see in Figure 1 the package is printed onto the screen which contains the package name and the release version. If you didn't get anything similar then you have not installed the NFS utilities and will need to using the yast sw_single command or the yast2 sw_single command.

Configuring NFS Server

In this section of the article we will look at configuring the NFS server to serve a specific file system on the network to other users. The first step that we need to do is decide what directory will be exported, in this article we will export the /home directory. The file that we will need to edit is called: "exports" and is located within the /etc directory, the exports file contains no example on how to export a file system. However, it does provide details on which man page to read (exports(5)).

The syntax which you will use in the exports file is shown in Figure 2. Some of the most commonly used export options are listed in Table 1 with a description of what the option does.

<mount point to export>        <list of trusted hosts><export options>

Figure 2: "exports" file syntax.

Export Option Description
rw This option allows clients to read and write to the exported mount point.
ro This option only allows the clients to read the data but not write data.
async This option allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request
have been committed to stable storage (e.g. disc drive).
sync Reply to requests only after the changes have been committed to stable storage.
no_root_squash This option turns off root_squashing.
root_squash This option maps requests from UID/GID 0 to the anonymous UID/GID.

Table 1: Commonly used export options.

In this article we are going to export the /home directory and allow users on the 192.168.2.1/24 network access the file system. The entry that we will add to the exports file is shown in Figure 2.1.

/home   192.168.2.*(rw,root_squash,sync)

Figure 2.1: Exporting the /home directory.

As you may have noticed in Figure 2.1 you are allowed to use wild cards within the trusted hosts field, it is also possible to use CIDR notation. Once you have saved the chances you can start the NFS server using either the service command or the rcnfsserver command as shown in Figure 2.2.

linux-mw4w:/etc # rcnfsserver start
Starting kernel based NFS server                                      done

Figure 2.2: Starting the NFS server.

Once the NFS server has been started you can issue the rpcinfo command followed by the -p qualifier which will show you what port the NFS server is running on. Figure 2.3 shows the output off the rpcinfo command.

linux-mw4w:/etc # rpcinfo -p
   program vers proto   port
    100000    2   tcp    111  portmapper
    100000    2   udp    111  portmapper
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100024    1   udp  32774  status
    100021    1   udp  32774  nlockmgr
    100021    3   udp  32774  nlockmgr
    100021    4   udp  32774  nlockmgr
    100024    1   tcp  59589  status
    100021    1   tcp  59589  nlockmgr
    100021    3   tcp  59589  nlockmgr
    100021    4   tcp  59589  nlockmgr
    100005    1   udp  10001  mountd
    100005    1   tcp  10001  mountd
    100005    2   udp  10001  mountd
    100005    2   tcp  10001  mountd
    100005    3   udp  10001  mountd
    100005    3   tcp  10001  mountd

Figure 2.3: Querying portmapper to see if the NFS server is running.

Once the NFS server has been started successfully and is reported to be running by portmapper you can begin to setup the NFS client.

Configuring NFS Client

In this section of the article we will look at configuring the NFS client to mount the remote file system, this can be done simply by using the mount command. The first task that we need to do before mounting the NFS is to create a mount point for the NFS, this can be done by issuing the mkdir command as shown in Figure 3.

Server2:/ # mkdir /NewHome

Figure 3: Creating a mount point for the NFS.

Once you have created a mount point for the NFS you can use the mount command to mount the NFS as shown in Figure 3.1.

Server2:/ # mount 192.168.2.141:/home /NewHome/

Figure 3.1: Mounting the exported /home file system.

Once you have mounted the NFS you can issue the mount command on its own to see if the NFS mounted successfully as shown in Figure 3.2.

Server2:/ # mount
..
..
192.168.2.141:/home on /NewHome type nfs (rw,addr=192.168.2.141)

Figure 3.2: Checking to see if the NFS was mounted successfully.

As you can see in Figure 3.2 the NFS was successfully mounted, it also allows you to see what the default mount options were. Table 2 lists some of the most commonly used mount options.

Mount Option Description
rsize The number of bytes NFS uses when reading files from an NFS server.
wsize The number of bytes NFS uses when writing files to an NFS server.
timeo The value in tenths of a second before sending the first retransmission after an RPC timeout.
retry The number of minutes to retry an NFS mount operation in the foreground or background before giving up.

Table 2: NFS commonly used mount options.

Once you have mounted the NFS you can unmount it by issuing the umount command as shown in Figure 3.3. Once you have unmounted the NFS you can mount it again this time with some of the options listed in Table 2 as shown in Figure 3.4.

Server2:/ # umount /NewHome/

Figure 3.3: Unmounting the NFS safely.

Server2:/ # mount 192.168.2.141:/home /NewHome/ -o rsize=4096,wsize=4096

Figure 3.4: Mounting the NFS with a read size of 4096 and a write size of 4096.

Once you have mounted the NFS with the new options you can issue the mount command on its own to see if the NFS was mounted successfully with the read and write options as shown in Figure 3.5.

Server2:/ # mount
...
...
192.168.2.141:/home on /NewHome type nfs (rw,rsize=1024,wsize=1024,addr=192.168.2.141)

Figure 3.5: Checking the NFS has been mounted with our settings.

Automatically mount NFS

In this section of the article we will look at making sure the NFS is mounted automatically after the machine has been rebooted. The file that we need to be edited is called: "fstab" and is located within the /etc directory, Figure 4 shows the entry we used and Table 3 explains what each section is.

...
192.168.2.141:/home     /NewHome        nfs     rsize=4096,wsize=4096,timeo=14
...

Figure 4: /etc/fstab NFS entry.

Column Description
192.168.2.141:/home This column specifies the IP address of the NFS server and the exported directory separated by the colon (:).
/NewHome This column specifies the mount point on the local file system.
nfs This column specifies the file system type.
rsize=4096,wsize=4096,timeo=14 This column specifies the mount options for the NFS server.

Table 3: Figure 4 explained.

Once you have added the NFS to your fstab file you can unmount the NFS using the umount command and then issuing the mount command followed by the -a qualifier which will read the fstab file and mount and unmounted partitions including our NFS.

Final Thoughts

In this article we covered how to configure and setup an NFS server and client. I would recommend you look into either NIS+ or LDAP which will allow you to centralized login information and with NIS+ and NFS working together you can create a nice manageable environment. I would also recommend reading the O'Reilly book "Managing NFS and NIS, second edition".


Disclaimer: As with everything else at Cool Solutions, this content is definitely not supported by Novell (so don't even think of calling Support if you try something and it blows up).

It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.




User Comments

© 2013 Novell