Custom Search

Thursday, June 9, 2011

ubuntu 11 NFS server and client setup and Configuration

ubuntu 11 NFS server and client setup and Configuration

Assume
-----------

Server Machine
IP 192.168.1.1

Client Machine
IP 192.168.1.3


Server side setup
============

1) Package installation
-----------------------
apt-get install nfs-kernel-server nfs-common portmap


2) 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


3) 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


4) 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
===========

1) Package installation
-----------------------
apt-get install nfs-common portmap


2) Starting Services
--------------------
/etc/init.d/portmap restart


3) Geting server share information
----------------------------------
showmount -e 192.168.1.1


4) 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

2 comments:

  1. Thanks for the write-up. FYI, rpcbind has now replaced portmap in Ubuntu.

    ReplyDelete
  2. Excellent nice and simple instructions. Corrections and fixes to server side:

    You will need to pre-pend sudo to most of these commands. In step 1 rpcbind has replaced portmap so do this instead:

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

    The command '/etc/init.d/portmap restart' complains about the syntax, so do this instead:

    sudo service portmap restart

    The command 'sudo exportfs -av' complains that there is no file or directory '/etc/exports.d'. Not sure it's needed but do this to prevent error, before running 'sudo exportfs -av':

    sudo mkdir /etc/exports.d

    I was using the NFS server to boot a root file system on an embedded device and these instructions worked but would not allow write access on the device. In /etc/exports I modified the line '/movies *(rw,sync)' to

    /movies *(rw,sync,no_root_squash)

    and it corrected the problem. Tested on Ubuntu 11.10.

    ReplyDelete