Friday, September 23, 2011

Share file & folders in Ubuntu with NFS


NFS stands for (take a guess…) Network File System. NFS is a protocol developed by Sun Microsystems in 1984 to allow computers to share files and folders over a network. NFS is an open standard, defined in RFCs, and allows any to implement the protocol.
Although many prefer to employ Samba for network folder sharing, NFS still has a lot of good uses and some even prefer it over the more flexible Samba.

Installation

Both client and server will need the package nfs-common. On the server machine you will need to install the package nfs-kernel-server. To install these packages follow these steps:
  1. Open up Synaptic (or your favorite Add/Remove Program utility).
  2. Search for “nfs” (no quotes).
  3. Mark nfs-common (for the client) and nsf-common and nfs-kernel-server (for the server).
  4. Click Apply to install.
In Command line Mode, You used :
# apt-get update
# apt-get install nfs-common nfs-kernel-server
That’s it. Now it’s time for a little configuration.

Configuration

For example’s sake, the two machines we are using are addressed as such:
Server: 192.168.1.100
Client: 192.168.1.10
On the client we will create a directory which the NFS server share will mounted to. We’ll create the folder ~/UBUNTU_NFS with the command mkdir ~/UBUNTU_NFS. Now let’s move over to the server.
The first thing to be done on the server machine is to create folder that will be shared out. Let’s call that folder ~/SHARE and we’ll create it with the command mkdir ~/SHARE.
Now we have to create an entry in the /etc/exports folder. This entry will tell NFS what to share and who to share with. The entry will look like:
/home/USERNAME/SHARE     192.168.1.10(rw)
Where USERNAME is the actual name of the user. NOTE: You could share a folder in /opt if you like.
Now nfs-kernel-server has to be restarted with the command:
# /etc/init.d/nfs-kernel-server restart

Mounting

Hop back on to the client machine and issue the command:
#  mount 192.168.1.100:/home/USER/SHARE /home/USER/UBUNTU_NFS
Where USER is the actual user name.
You should get no errors. Now let’s test this out. Hop on back to the server and create a file within ~/SHARE. After you create that file, check the ~/UBUNTU_NFS directory on the client to make sure the file shows up. Try to delete that file. Now create a file in the ~/UBUNTU_NFS directory on the client. You should have no problems creating a file.

Automounting

Say you want this share to always be mounted upon boot of the client machine. This, of course would require the server machine to be on. To do this add an entry on the client machine’s /etc/fstab that looks like:
192.168.1.100:/home/jlwallen/ELIVE  /home/jlwallen/UBUNTU  nfs rsize=1024,wsize=1024,noauto 0 0
NOTE: The above fstab entry is all one line.
Now that NFS share will mount even when the machine is rebooted.
As you can see, NFS has become much easier than it was in the old days. Now, armed with NFS and Samba, you can be sharing files and folders with anyone and everyone.

No comments:

Post a Comment