1 / 3
Caption Text
2 / 3
Caption Two
3 / 3
Caption Three margin testing

Monday, October 12, 2009

Share folders between two Ubuntu computers on the same LAN with NFS

» Share folders between two Ubuntu computers on the same LAN with NFS // Clara Raubertas // Freelance Web Design & Web Development // Cambridge & Boston, Massachusetts

While most things about Ubuntu work pretty much the way you want/expect the first time, one exception is sharing folders between two computers on the same LAN ("Local Area Network" — in this case, multiple computers in the same house sharing an internet connection via a router). Surprisingly, it's easier/more intuitive to do this between an Ubuntu computer and a Windows computer! I wish Ubuntu would make a more intuitive, graphical way for non-technical users to do this — though I certainly have fun tinkering with these things and learning more about networking (or what-have-you) as I go.

Through some command-line magic, I've gotten my laptop to be able to access the music folder on my desktop — right now I'm playing music on my laptop that's actually stored on my desktop's much bigger hard drive. Sweet! How did I manage this?

Say you have two computers, both running Linux (in this case they're both running Ubuntu and I can't vouch that this will work on any other distro, but I suspect it would) — the server, which has the folder you want to share on its physical media, and the client, which will connect to the server and access its data.

On the client:
1. In a Terminal window, run

sudo apt-get install nfs-common

— this installs the software you'll need.

2. Run

ifconfig

to find your IP on the local network; it should look something like

inet addr:192.168.1.101

(If you see more than one instance of "inet addr" in the output of ifconfig, choose the address that doesn't begin with 127.)

On the server:

3. In a Terminal window, run

sudo apt-get install nfs-kernel-server

4. Edit the

/etc/hosts

file and add a line that looks like this:

neuron 192.168.1.101

where "neuron" is replaced with the hostname or a nickname for your client (in this case, "neuron" is the name of my laptop) and "192.168.1.101″ is replaced with the IP you found in step 2.

5. Test this — in a Terminal, run

ping -c 1 neuron

(or whatever name you used) and see if you get a response. If you get a response like "unknown host", something is wrong — re-check your work from the previous steps (and check that the two computers are really on the same network!). If you get a response like "… 64 bytes from neuron… 1 packets transmitted, 1 received … " then everything is hunky-dory so far and you are ready to move on!

6. Edit the

/etc/hosts.allow

file and add a line that looks like this:

ALL: 192.168.1.101

(again, use the IP that you found in Step 2).

7. Edit the

/etc/exports

file and add a line that looks like this:

/home/music 192.168.1.101(rw,sync,subtree_check,no_root_squash)

where again 192… is replaced with the IP from step 2, and "/home/music" is replaced with the full path to the folder you want to share. Note that for some reason it is important that the parenthesized arguments don't have a space between them.

8. Run

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

9. Run

ifconfig

and get the IP of your server, the same way that you found it for the client.

Back on the client!

10. Edit

/etc/hosts

and add a line like

192.168.1.103 boffin

where "192.168.1.103″ is replaced with the IP of your server (from step 9) and "boffin" is replaced with the hostname/nickname of your server ("boffin" is the name of my desktop).

11.

ping -c 1 boffin

to check that this worked, just like in Step 5.

12. Make a mountpoint for your shared directory — in my case, I used

mkdir /media/boffin-music

13. Mount the shared directory at the mountpoint, like this:

sudo mount -t nfs boffin:/home/music /media/boffin-music

replacing "boffin" with your server's name, "/home/music" with the location on the server of your shared folder, and "/media/boffin-music" with the mountpoint you created in step 12.

14. Now you should be able to browse to the mountpoint and see your shared files, and open them, and use them. Awesome!

No comments:

Post a Comment

Featured Post

Windows和Ubuntu双系统完全独立的安装方法

http://www.ubuntuhome.com/windows-and-ubuntu-install.html  | Ubuntu Home Posted by Snow on 2012/06/25 安装Windows和Ubuntu双系统时,很多人喜欢先安装windows,然...