How to set up NFS and How to Share Files in a local network with Ubuntu Linux?
August 31st, 2007In this small Tutorial I will show you how to set up a working directory / file share between two or more Ubuntu Linux Computers.
We’re gonna share the directory /media/music on the Ubuntu Linux box ernie, in order to allow the other Linux box bert to access it and listen to ernie’s music, Let’s go!
1 - Setting up ernie (who is sharing the directory):
Just Execute the following commands in a Terminal on ernie - At first, we need to Install the Packages which are needed in order to share the files via NFS:
sudo apt-get install nfs-kernel-server - Now, edit /etc/exports in order to share our music folder!
sudo nano /etc/exportsand add the line/media/music bert(ro,async,all_squash)
ro means “read only”, so the others can not delete your files. If you wish to allow writing to this directory, use rw “read write” instead! - Restart the NFS Server by executing
sudo /etc/init.d/nfs-kernel-server restart - We’ve configured
ernievery fast, didn’t we? Now it’sbert’s turn
2 - Setting up bert (who is using the directory):
Execute the following commands in a Terminal on bert - Install the needed “NFS Common” Package nfs-common
sudo apt-get install nfs-common - Create your a music directory which will contain ernie’s directory and which is located at /var/music:
mkdir /var/music - Mount ernie’s shared music directory to /var/music:
sudo mount ernie:/media/music /var/music - Now you can access the files from ernie in your local direcotry
/var/music- Have Fun!
- If you wish to mount the Directory automatically each startup, just just need to modify
/etc/fstab:
Open the file usingsudo nano /etc/fstaband append
ernie:/media/music /var/music nfs r,hard 0 0
(Use rw,hard instead of r,hard in case you shared the File as “read write” or you won’t be able to change files!)
3 - We’re finished
Setting up basic File Sharing between Linux computers isn’t as hard as everybody is saying, and I really hope this will help some Linux Beginners out there to manage it on their own.
It’s just a couple of commands, if you experience any trouble or problems with this, please feel free to comment and I will try my best to help you
Did you Like this Post? Try these ones! :)
How can I define a static Network IP Address for eth0 and create a LAN Connection in Ubuntu Linux? on September 9th, 2007
How to install nmap on Ubuntu Linux on September 11th, 2008
Linux File System Structure merged into a Picture on September 25th, 2007
How to Create a Gigabyte Testfile with dd? on December 28th, 2007
Ubuntu HTML in front of Flash Video is hidden, why? on September 7th, 2008


October 20th, 2007 at 04:00
Tried twice all I got was “can’t get address for ernie”(in your example) off to try something new, thanks for the effort.
Cart
October 20th, 2007 at 04:30
OK my bad, great instructions! I just can’t type, thanks again, sharing music goes well now
Cart
October 20th, 2007 at 06:01
Yeah, and if you’ve configured static IP addresses for your network, you may - of course - use them instead of the hostnames “ernie” and “bert” :o)
Just 192.168.0.1 etc. I hope you get the point
Cheers Beni
November 29th, 2007 at 01:57
No, it’s not your bad typing. I got the same result as Cart: “can’t get address for ernie”. I can’t get this NFS to work. Also, I wouldn’t know how to configure a static IP address. I don’t think our service provider provides static IP addresses. With NFS my computers can’t find each other (though networked) and with Samba I can see all the files on the other computer alright, but am not allowed to open them or alter them in any way. Have tried many, many tutorials on setting up shares. None work with my system.
December 8th, 2007 at 04:20
Found this really useful. Used it to network my home PCs one on Ubuntu 7.10 the other on Slackware 12.0. I’m an uberN00B Sys0P and kinda thrown in the deep end, so this kind of information is incredibly useful for me. Thanks beNi!
January 18th, 2008 at 08:47
yes very good thank you, I had problem with permission and had to fix /etc/hosts.allow and /etc/exports, you might consider adding the tips for both in the guide, it will save time to others like me, anyway thanks a lot it worked well
January 28th, 2008 at 03:28
in /etc/fstab,
ro,hard
instead of r,hard
November 3rd, 2008 at 08:22
Can I do this folder share if the user name on both computer’s is the same?
For example:
Laptop username = john
Desktop username = john
November 24th, 2008 at 04:30
Gents,
ernie and bert are hostnames.
Your hostnames will of course, be different - and as he says above, you can use an IP instead of a hostname (or, add your machines as desired to /etc/hosts since presumably not everyone runs internal DNS).
@Warped0ne: realistically username should be irrelevant. It should just simply work, full stop, no auth required as I understand it.
This line:
====
/media/music bert(ro,async,all_squash)
====
says that hostname “bert” can access “/media/music” with the permissions/settings defined in parenthesis.
You could just as easily do:
====
/media/music 192.168.0.0/16(ro,async,all_squash)
====
Which would share the contents of /media/music with 192.168.0.0-192.168.255.255 (obv there are network/broadcast in there, but you get the idea).
Once you’ve set up the sharer, and have the nfs client tools loaded on the share-ee, it’s a simple mount command:
====
sudo mount ernie:/media/music /var/music
====
is his example, which would mount “/media/music” on hostname “ernie” onto local mountpoint “/var/music”
You could just as easily do:
====
sudo mount 192.168.1.100:/media/music /var/music
====
Hope this clarifies things. If you wish to bring in the authentication bits, that’s another topic entirely - this is just the easy “how to set up anon share” portion.
March 26th, 2009 at 03:57
Very nice tutorial. I just happened to run in to a bit of a problem. I’ve followed the tutorial and when I run command:
timo@timo-laptop:/media/lan$ sudo mount -v -t nfs timo-desktop:/media/musiikki /media/lan/musiikki
mount.nfs: timeout set for Thu Mar 26 11:56:47 2009
mount.nfs: text-based options: ‘addr=192.168.1.50′
mount.nfs: internal error
What might be the problem? Perhaps I need to open some ports? I tried to open some porst from firestarter for nfs, but it made no difference. Do I need to open some ports from my router as well?
March 26th, 2009 at 06:54
Ok. I got it working. Here’s what was the problem for me:
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
(not sure if all that is required)
And voilà: it works!
Ta tah: T
November 17th, 2009 at 10:28
[…] been updated for a while I’m posting it here, since I rather not loose it again. I hope that the original poster don’t […]