Sharing Ubuntu 11.04 Folders with Remote Linux and UNIX Systems

From Techotopia
Revision as of 20:10, 27 October 2016 by Neil (Talk | contribs) (Text replacement - "<table border="0" cellspacing="0"> " to "<table border="0" cellspacing="0" width="100%">")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
PreviousTable of ContentsNext
Configuring an Ubuntu 11.04 Based Web ServerSharing Ubuntu 11.04 Files and Folders with Windows Systems

Purchase and download the full version of this eBook in PDF & ePub formats for only $12.99
PDF/ePub version contains 39 chapters and 255 pages.

Ubuntu 11.04 provides two mechanisms for sharing files and folders with other systems on a network. One approach is to use technology called Samba. Samba is based on Microsoft Windows Folder Sharing and allows Ubuntu systems to make folders accessible to Windows systems, and also to access Windows based folder shares from Ubuntu. This approach can also be used to share folders between other Linux based systems as long as they too have Samba support installed and configured. This is by far the most popular approach to sharing folders and in recent versions of Ubuntu has been given the most attention in terms of documentation and tools support. The topic of folder sharing using Samba is covered in Sharing Ubuntu 11.04 Files and Folders with Windows Systems.

Another option, which is targeted specifically at sharing folders between Linux and UNIX based systems uses technology called Network File System (NFS). NFS allows the file system on one Linux computer to be accessed over a network connection by another Linux or UNIX system. NFS was originally developed by Sun Microsystems in the 1980s and remains the standard mechanism for sharing of remote Linux/UNIX file systems to this day.

NFS is very different to the Windows SMB resource sharing technology used by Samba. In this chapter we will be looking at network based sharing of folders between Linux based systems using NFS.


Installing NFS Services on Ubuntu 11.04

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:

$ service nfs-kernel-server status
nfsd running

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

sudo service nfs-kernel-server start

Sharing Folders

Once the NFS service is installed and running, the next step is to configure any folders that are to be shared with remote systems. All folders to be shared are listed in the /etc/exports file which may be edited from a terminal window as follows:

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:

<folder path> <hostname>(permissions) 

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


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,sync,no_subtree_check) ubuntu2(rw,sync,no_sub_tree_check)

Alternatively, to provide 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 –a
sudo exportfs

Configuring the Firewall

If the Ubuntu system on which the NFS server is running has a firewall activated, it is essential that the firewall on the NFS server system be configured to allow NFS traffic before any folders can be mounted over the network. For more details on firewall configuration refer to Ubuntu 11.04 Firewall Basics and Using gufw and ufw to Configure an Ubuntu 11.04 Firewall. By default, Ubuntu does not configure a firewall to block NFS traffic when the nfs_kernel_package is installed on the system. Unless you have specifically configured a firewall since installing Ubuntu it should not, therefore, be necessary to make any changes for NFS to work.

Mounting a Remote Ubuntu NFS Folder

Once a folder has been exported it may then be mounted on a client system using the mount command.

To mount a remote folder from the command line, open a terminal window and create a folder where you would like the remote folder to be mounted:

mkdir /tmp/mnt

Next enter the command to mount to the remote folder (in this example we use ubuntu as the remote hostname):

sudo mount ubuntu:/tmp /tmp/mnt

The remote folder will then be mounted on the local system. Once mounted, the /tmp/mnt folder will contain the remote folder and all its contents. If the local system is running Ubuntu, the mount operation may fail with the following message:

mount: wrong fs type, bad option, bad superblock on,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)
       In some cases useful info is found in syslog - try
       dmesg | tail  or so

In the event that this error appears, this simply means that an additional package needs to be installed in the local Ubuntu system in the form of nfs-common. This may be achieved in a Terminal window as follows:

sudo apt-get install nfs-common

Once installed, repeat the mount command and the operation should now complete successfully.

Mounting an NFS File System on System Startup

It is possible to configure an Ubuntu system to automatically mount a remote file system each time the system starts up. This is achieved by editing the /etc/fstab file. To do this use sudo to load the /etc/fstab file into your favorite editor. It will likely look something like the following:

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    defaults        0       0
# /dev/sda1
UUID=bcde7125-d38d-4362-bcd8-c64f2b512760 /               ext3    defaults,errors=remount-ro 0    1
# /dev/sda5
UUID=b4ff42fa-7c9a-4c26-a640-b0af94f14820 none            swap    sw              0       0
/dev/hdc        /media/cdrom0   udf,iso9660 user,noauto     0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto  0       0

To mount, for example, a folder with the path /home/demo which resides on a system called ubuntu in the local folder with the path /nfsmount add the following line to the /etc/fstab file:

ubuntu:/home/demo /nfsmount nfs

Next time the system reboots the /home/demo folder on the remote ubuntu system will be mounted on the local /nfsmount mount point. All the files in the remote folder can then be accessed as if they resided on the local hard disk drive.

Unmounting an NFS Mount Point

Once a remote file system is mounted using NFS it can be unmounted using the unmount command with the local mount point as the command-line argument. For example, to unmount our example file system mount point requires the use of the following command:

sudo umount /nfsmount

Purchase and download the full version of this eBook in PDF & ePub formats for only $12.99
PDF/ePub version contains 39 chapters and 255 pages.

PreviousTable of ContentsNext
Configuring an Ubuntu 11.04 Based Web ServerSharing Ubuntu 11.04 Files and Folders with Windows Systems