Wednesday, October 10, 2012

Installing NFS Services on Ubuntu 12.10

The services required to enable NFS folder sharing are not installed by default on Ubuntu. They can easily be installed, however, by opening a terminal window and entering the following command:

#sudo apt-get install nfs-kernel-server

The installation process should automatically start the NFS service. To verify that the service is indeed running, execute the following command:

#sudo /etc/init.d/nfs-kernel-server status

If the output from the above command indicates that the service is not running, it may started as follows:

#sudo /etc/init.d/nfs-kernel-server start

Sharing Folders


Configuring an NFS server is as simple as placing a line in the /etc/exports file. That line has three pieces of information:

    The directory to be shared (exported)
    The computer, NIS group, hostname, domain name or subnet allowed to access that directory
    Any options, such as ro or rw, or several other options

Any folders which are to be shared are listed in the /etc/exports file which may be edited from a terminal window as follows. There's one line for each directory being shared. The general syntax is:

directory_being_shared subnet_allowed_to_access(options)

#sudo gedit /etc/exports

Each folder that is to be shared via NFS must have an entry in this file. The basic syntax is as follows:

(permissions)

For example, to allow a system with the IP address of 192.168.2.24 to access /tmp with read-only access, the following entry would be added to the /etc/exports file:

/tmp    192.168.2.24(rw,sync,no_subtree_check)

Similarly, to also make the folder accessible to a system with the hostname ubuntu2 with read/write permission, the line would read as follows:

/tmp    192.168.2.24(ro,sync,no_subtree_check) ubuntu2(rw,sync,no_sub_tree_check)

Alternatively, to provided read/write access to all hosts, simply use the wildcard character (*):

/tmp    *((rw,sync,no_sub_tree_check)

Once the folder entries have been made in the /etc/exports file, the current settings may be checked at any time by running the exportfs command:

#sudo exportfs
/tmp              192.168.2.24

Mounting an NFS Share on a Client

Mounting an NFS share on a client can be simple. At its simplest it might look like this:

#mount -t nfs -o ro 192.168.100.85:/data/altamonte /mnt/test

That same mount can be performed in /etc/fstab with the following syntax:

#192.168.100.85:/data/altamonte   /mnt/test   nfs   rw   0   0

There are many mount options that can be used, and those are listed in this article.

1 comments:

Unknown said...

Great NFS howto. It worked like a charm for me.