File Sharing in Ubuntu With NFS


The Network File System (NFS) was developed to allow Linux machines to mount a disk partition on a remote Linux machine as if it were a local disk. It allows for fast, seamless sharing of files across a network.

Note: All the commands are run by root user.

Brief about setup

I have two machine, both are running ubuntu 10.10 desktop edition. I am making one machine as a nfs server & another one as a nfs client

Server Machine IP

Client Machine IP

Server side setup Package installation

apt-get install nfs-kernel-server nfs-common portmap

Starting Services

/etc/init.d/nfs-kernel-server restart /etc/init.d/portmap restart

Test whether NFS is running correctly with the rpcinfo command. You should get a listing of running RPC programs that must include mountd, portmapper, nfs, and nlockmgr. You should get portmapper, nlockmgr, nfs, mountd port open by running rpcinfo command

rpcinfo -p localhost

Sharing files / Directories

You have to mention shares & their permission in / etc / exports file. I am sharing my / movies directory with another pc on the network. Giving read only permission to client machine Edit the file / etc / exports

vi / etc / exports

/ movies * (ro, sync)

If you want to share same folder with read & write permission then syntax will be

/ movies * (rw, sync)

If you want to share same folder only for particular machine on the network then

/ movies (ro, sync)

For more info you can refer man pages for NFS

man 5 exports

Whenever we modify / etc / exports, you must run

exportfs -av

-a Export or unexport all directories
-v Be verbose. When exporting or unexporting, show what's going on.

When displaying the current export list, also display the list

of export options.

Client side setup Package installation

apt-get install nfs-common portmap

Starting Services

/etc/init.d/portmap restart

Geting server share information

showmount -e

If you run above command you should get following output

Export list from

/ movies *

Mounting The NFS Shares On The Client

mkdir / tp mount -t nfs / tp

Confirm the share by mount command. You can also add mount entry in fstab file, so that at the next start of your machine you do not need to manually mount the share.

echo " / tp nfs defaults 0 0" >> / etc / fstab

Note: If you can not access nfs share from client please ensure that

1. TCP / UDP 2049,111 ports should be open on your firewall.

2. Check the output of rpcinfo command

3. Update the share information via exportfs -av command

4. Reload the service on NFS server as well as NFS client

For more tutorial visit TechieNote


Leave a Reply