Benjamin Flesch = definitely rocks.”> How to Share Files in a LAN (Local Area Network) on Ubuntu Linux or How to set up NFS (Network File System)? ~ mybeNi websecurity, web security and hack stuff.

web securitymybeNi websecurity

How to set up NFS and How to Share Files in a local network with Ubuntu Linux?

August 31st, 2007

In 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/exports and 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 ernie very fast, didn’t we? Now it’s bert’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 using sudo nano /etc/fstab and 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 :)




12 Responses to “How to set up NFS and How to Share Files in a local network with Ubuntu Linux?”:

  1. ecartman Says:

    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


  2. ecartman Says:

    OK my bad, great instructions! I just can’t type, thanks again, sharing music goes well now

    Cart


  3. beNi Says:

    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


  4. Kath Says:

    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.


  5. X-to-tha-t Says:

    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!


  6. toky Says:

    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 :)


  7. Anonymous Says:

    in /etc/fstab,
    ro,hard
    instead of r,hard


  8. Warped0ne Says:

    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


  9. cach0rr0 Says:

    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.


  10. Timo Says:

    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?


  11. Timo Says:

    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


  12. Ubuntu Network Share | woollypigs Says:

    […] 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 […]


Leave a Reply


Google Traffic (7 days)

550
500
450
400
350
300
250
200
150
100
50
473
476
460
510
536
515
477
38.107.191.85