NFS allows a system to share directories and files with others over a network. By using NFS, users and programs can access files on remote systems almost as if they were local files.
Some of the most notable benefits that NFS can provide are:
If you have a firewall you need to make sure ports 32771, 111 and 2049 are open
At a terminal prompt enter the following command to install the NFS Server on Ubuntu:
bash$ sudo apt-get install nfs-kernel-server
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.
The /etc/exports file contains a list of entries; each entry indicates a volume that is shared and how it is shared.
directory machine1(option11,option12) machine2(option21,option22)
/home 192.168.4.0/255.255.255.0(rw)
Some precautionary with NFS sharing:
The /etc/hosts.allow and /etc/hosts.deny 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:
In general it is a good idea with NFS (as with most internet services) to explicitly deny access to IP addresses that you don't need to allow access to.
The first step in doing this is to add the followng entry to /etc/hosts.deny:
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL
Furthermore, adding an entry ALL:ALL in the file /etc/hosts.deny causes any service that looks at these files to deny access to all hosts unless it is explicitly allowed.
Next, we need to add an entry to /etc/hosts.allow to give any hosts access that we want to have access. Entries in hosts.allow follow the format:
service: [host | network/netmask] , [host | network/netmask]
To start the NFS server on Ubuntu, you can run the following command at a terminal prompt:
bash$ sudo /etc/init.d/nfs-kernel-server start
NFS serving is taken care of by five daemons:
The daemons are all part of the nfs-utils package, and may be either in the /sbin directory or the /usr/sbin directory.
To do this, query the portmapper to find out what services it is providing by using this command:
bash$ rpcinfo quota
You should get something like this:
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100011 1 udp 749 rquotad
100011 2 udp 749 rquotad
100005 1 udp 759 mountd
100005 1 tcp 761 mountd
100005 2 udp 764 mountd
100005 2 tcp 766 mountd
100005 3 udp 769 mountd
100005 3 tcp 771 mountd
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
300019 1 tcp 830 amd
300019 1 udp 831 amd
100024 1 udp 944 status
100024 1 tcp 946 status
100021 1 udp 1042 nlockmgr
100021 3 udp 1042 nlockmgr
100021 4 udp 1042 nlockmgr
100021 1 tcp 1629 nlockmgr
100021 3 tcp 1629 nlockmgr
100021 4 tcp 1629 nlockmgr
Modification to /etc/exports file may not take effect immediately. Run the command below to force nfsd to re-read the /etc/exports file.
bash$ exportfs -ra
If you can't find the exportfs command, then you can kill nfsd with the -HUP flag:
bash$ kill nfsd -HUP
In general, check that the client machine supports NFS mounting by looking into the /proc/filesystems and make sure there is a line containing nfs. If not, type in this command below to insert the nfs module:
bash$ insmod nfs
To begin using machine as an NFS client, you will need the portmapper running on that machine, and to use NFS file locking, you will also need rpc.statd and rpc.lockd running on both the client and the server. Most recent distributions start those services by default at boot time.
For Ubuntu, make sure the nfs-common package is installed on your client. To install nfs-common enter the following command at the terminal prompt:
bash$ sudo apt-get install nfs-common
Use the mount command to mount a shared NFS directory from another machine, by typing a command line similar to the following at a terminal prompt:
bash$ sudo mount -f nfs server.name.com:/export/home /mnt/home
Note: The mount point directory /mnt/home must exist. There should be no files or subdirectories in the /mnt/home directory.
To unmount the NFS, simply type in this command:
bash$ umount /mnt/home
To check what is mounted on your client, type in this command:
bash$ mount
An alternate way to mount an NFS share from another machine is to add a line to the /etc/fstab file. The line must state the hostname of the NFS server, the directory on the server being exported, and the directory on the local machine where the NFS share is to be mounted.
The general syntax for the line in /etc/fstab file is as follows:
device mountpoint fs-type options dump fsckorder
....
server.name.com:/home /mnt/home nfs rw,hard,intr 0 0
....
Options:
The mount command options rsize and wsize specify the size of the chunks of data that the client and server pass back and forth to each other. Here are some pointer for optimizing the transfer speed by modifying the option rsize and wsize:
You will want to experiment and find an rsize and wsize that works and is as fast as possible. You can try to transfer 16384 blocks of 16k each from the special file /dev/zero (which if you read it just spits out zeros really fast) to the mounted partition. Time to see how long it will take to do this operation:
bash$ time dd if=/dev/zero of=/mnt/home/testfile bs=16k count=16384
This creates a 256Mb file of zeroed bytes. In general, you should create a file that's at least twice as large as the system RAM on the server, but make sure you have enough disk space. Then read back the file into the great black hole on the client machine (/dev/null) by typing the following:
bash$ time dd if=/mnt/home/testfile of=/dev/null bs=16k
Repeat this a few times and average how long it takes. Be sure to unmount and remount the filesystem each time (both on the client and, if you are zealous, locally on the server as well), which should clear out any caches. The block size should be a power of two since most of the parameters that would constrain it (such as file system block sizes and network packet size) are also powers of two. However, some users have reported better successes with block sizes that are not powers of two but are still multiples of the file system block size and the network packet size.
Remember to edit /etc/fstab to reflect the rsize/wsize you found to be the most desirable.
Here are some benchmarks that may prove useful:
Here are some ways for experimenting with your network card to find out how it can best handle traffic: