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 192.168.1.1

Client Machine
IP 192.168.1.3

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.

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		192.168.1.3(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 192.168.1.1

Mounting The NFS Shares On The Client

mkdir /tp
mount -t nfs 192.168.1.1:/movies /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 don’t need to manually mount the share.

echo "192.168.1.1:/movies/	/tp	nfs	defaults	0 0" >> /etc/fstab

Note : If you can’t 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

Subscribe / Share

Article by Vidyadhar

My name is Vidyadhar Sarmalkar & I work as a consultant and have done RHCE & CCNA.
Vidyadhar tagged this post with: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Read 270 articles by

8 Comments

  1. Pete says:

    This worked a fucking treat, thanks!

  2. tuk says:

    thanks a lot! your NFS method works great for me! may your tribe increase!

  3. je suis says:

    Huge success! Thanks a million. You might have just saved my college diploma. =)

  4. Topher says:

    AKAIK you’ve got the anwser in one!

  5. William O. B'Livion says:

    The really sad thing is that it’s easier to mount CIFS/Windows shares under Ubuntu than to get NFS set up.

  6. Prince Kropotkin says:

    This did the trick. Nice one!

Leave a Reply

rss twitter facbook

Categories

Archives