23 September 2007

Easy Ubuntu File-sharing Using NFS

First, we'll need to configure the "server" (the machine where the files are physically stored). Open a terminal window and key in the following:

1. sudo apt-get install nfs-kernel-server nfs-common portmap

2. sudo gedit /etc/default/portmap and ensure that "bind loopback" is not enabled.

3. Save the file and sudo /etc/init.d/portmap restart if changes were made.

4. sudo gedit /etc/exports

5. In my case, I'd like to share my /home/chanweiyee/myshare directory, so I add the following line: /home/chanweiyee/share 192.168.1.2/10(rw,no_root_squash,async)

Note that chanweiyee is my username, myshare is the directory that I want to share and (rw,no_root_squash,async) implies full read-write permissions. If you require the client machine to have only read access, use (ro,async) instead.

Also note that 192.168.1.2/10 means that I'm allowing access to IPs 192.168.1.2 to 192.168.1.10. Do change the range to suit your needs.

6. Save the fille and issue the command sudo exportfs -a

7. sudo /etc/init.d/nfs-kernel-server restart

Now, we'll work on the client machine. By the way, I've seen some wikis out there claiming that portmap and nfs-common need to be installed on client machines, but in my case (I'm using Ubuntu Feisty) my share seems to be working perfectly without these packages. As far as I know, only the server requires these packages.

To continue, key in the following in the terminal window:

1. sudo mkdir ~/myshare

2. sudo gedit /etc/fstab and add this line:
192.168.1.2:/home/chanweiyee/myshare /home/chanweiyee/myshare nfs rw 0 0

That is assuming my server's IP is 192.168.1.2. Change this IP to whatever IP your server is having.

3. Reboot and you should find the remote directory mounted to your client's myshare directory.

2 comments:

unwesen said...

#4 on the client should just be "sudo mount /home/chanweiyee/myshare", there shouldn't be a need to reboot - is there?

Wei-Yee Chan said...

Yep, in fact I spotted the error just about the same time you did. Thanks.

The reboot was meant for the /etc/fstab changes.

I'd decided to omit the mount instruction, but in the process of editing, I accidentally cut and pasted the reboot instruction to the mount instruction.

So, the mount instruction did not get deleted as I'd mistaken it for the ftsab instruction.