Showing posts with label NFS. Show all posts
Showing posts with label NFS. Show all posts

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

Folder sharing woes, and ultimate success!

Have you ever had a computer problem you've grappled with for days, experienced frustration and despair, and finally found an answer so simple it left you asking "Was that all there was to it?"
Well here is such a tale.
First some history. Sharing a folder between computers is supposed to be easy in Ubuntu, according to the Ubuntu documentation. At the time I tried it (probably around 8.04) there were two options for sharing folders with a right-click- Samba and NFS. Neither worked for me with the simple right-click option alone.
I had some success following this YouTube guide to Samba, which allows file sharing between Windows and Linux computers- and also between Linux computers. (The guide is for Ubuntu 6.10, but still seems relevant to current versions.) Accessing shared folders over the network was problematic, but using the IP address of the computer worked pretty well.
(The NFS option does not appear when attempting to share folders in Ubuntu 9.10 -Which makes me think it never worked as a right-click option without further configuration. It's interesting to note that the Samba guide considers Samba unnecessary for sharing folders between two Linux computers.)
After replacing an Ubuntu installation with Debian on my old computer recently, I tried to access the shared folder on my newer computer again- without any success. I looked at a lot of guides to Samba on the internet, and a lot of forum pages describing similar problems. This is where the frustration and despair mentioned above came in. (If I could have understood the guides and forum pages I looked at, I'm sure I'd be qualified as a network administrator.)
Eventually I found a partial answer. I'd been experimenting with a firewall (GUFW) and it had been blocking Samba. Removing the firewall (I'm behind a hardware firewall anyway) got me back to the previous situation- I could access the shared folder, but only by using the IP address of the computer, not the computer name. In frustration I uninstalled Samba and decided to have a go at using NFS- since it is recommended for sharing between two Linux computers.
I found a guide that seemed reasonably simple to follow, and had a go. Result? Failure. More frustration! But then I tried something mentioned in one of the comments. Suddenly it worked! I could see shared folders instantly and access files in a flash!
This was indeed the "Was that all there was to it?" I alluded to previously.
The thing that worked for me was to tell my computer the IP address of the computer I wanted to connect to. Which makes me think that my router is not good at matching a computer name to an IP address over the network. Which in turn makes me think that the reason I could get Samba to work (very well) may have been the same problem with one computer obtaining the IP address of the other.
I'm tempted to go back and try the right-click, 'Share this folder' option in Ubuntu again and see if it works now, but for the moment I'm going to post the guide to installing NFS folder sharing, in the hope that somebody might find it useful.