Monday, January 18, 2010

Share files in a local network with NFS on Linux

Here's a really easy way to share folders and files between two Linux computers on a local network from mybeNi. (I've done it with Ubuntu and Debian.) It doesn't require the skills of a network administrator to implement, and uses NFS, which seems to be fast and reliable.
Here are the steps to go through- details are at the link above.

On the first computer:
Install NFS (either using Synaptic or the command line).
Edit an NFS configuration file to tell NFS which folder to share, which computer to share it with, and specify options.
Restart the NFS server.
On the second computer:
Install NFS.
Make a directory to contain the shared directory from the first computer.
Mount the directory.
Edit an NFS configuration file to mount the directory automatically if required.
Folder locations in the tutorial change be changed. For example, I shared...
/home/username/Shared
...on the first computer and created...
/home/username/Shared
...on the second.

Be carefully with typing the locations because case and spelling mistakes will mean the share won't work

For me, the tutorial didn't work at first. Then I noticed a comment which provided the answer. As described in later comments, I added lines to the /etc/hosts file on my computers to tell them the IP address of the other computer.

To edit the file:
sudo gedit /etc/hosts
Add:
'IP address' 'computer name', for example:
192.168.2.2 compaq
(To find the name of each computer, type the following in a terminal:
hostname)
Thanks to Beni for the tutorial.

Update: the original tutorial has gone, but I found a condensed version of it here:

==NFS shares
Condensed frm http://mybeni.rootzilla.de/mybeNi/2007/how_to_set_up_nfs_and_how_to_share_files_in_a_local_network_with_ubuntu_linux

====Share /media/music from 'ERNIE':
$ sudo apt-get install nfs-kernel-server

Add a line to /etc/exports:
$ ECHO "/media/music BERT(ro,async,all_squash)" >> /etc/exports

Restart the NFS Server
$ sudo /etc/init.d/nfs-kernel-server restart

====Connect and mount from 'BERT'
$ sudo apt-get install nfs-common
$ mkdir /var/music
$ sudo mount ernie:/media/music /var/music

To automount at start, add a line to /etc/fstab
$ ECHO "ernie:/media/music  /var/music     nfs r,hard   0  0" >> /etc/fstab

May have to add a line to /etc/hosts.allow

1. The server rejected the requests. What I did was I opened ports: 111, 2049, 32771 (from client and server, but not from router). This wasn't enough. I had to tell the servers firestarter to allow connections from my clients ip (in the lan).
2. Then I ran in to a new problem, but at least the server responded:
mount.nfs: access denied by server while mounting timo-desktop:/media/musiikki
Then I realized that for some reason I had to add the clients ip in to the file /etc/hosts
Like this
192.168.1.51 timo-laptop
after doing that and then I ran on the server:
sudo exportfs -ra
sudo /etc/init.d/portmap/ restart
sudo /etc/init.d/nfs-kernel-server restart

No comments:

Post a Comment