Mar 10

Share a folder on Ubuntu via NFS

Category: Linux   — Published by tengo on March 10, 2008 at 5:36 am

First post on the zen of linux. A good start would be a basic post about how to get multiple machines working on a shared folder.

The way to go in the linux/unix world is to use the pretty stable and reliable NFS filesystem.

At first, you have to select a machine you would like to make the "server". Open a console window and type

sudo aptitude install nfs-user-server

then configure it (you'll need to use sudo to edit these):
edit the /etc/exports file add this line:

/home/<name of dir to export/share> <ip of other machine/the client>(rw)

edit the /etc/hosts.allow file add this line

ALL:<ip of client machine>

edit the /etc/hosts.deny file add this line:

portmap:ALL

finally, on this machine (the server) restart nfs with:

sudo /etc/init.d/nfs-user-server restart

(alternatively use: sudo /etc/init.d/nfs-common restart - if we would use the common-server)
Now beginn to add the client machines:

First you need to create a pseudo-directory, a mount-point for the remote folder

cd /home
sudo mkdir shared

then change permissions for this dir

sudo chown root:users /home/shared
sudo chmod 777 /home/shared

edit the /etc/fstab file on the client machine to mount on boot:

sudo gedit /etc/fstab

add this line in /etc/fstab

xxx.xxx.x.<server IP>:/home/shared/ /home/shared nfs defaults 0 0

(alternatively:)
192.168.1.2<server IP>:/home/shared /home/shared nfs rsize=8192,wsize=8192,timeo=14,intr

then go and update the mounts for this session (without rebooting):

sudo mount -a