Perfect NFS On An Ubuntu Hardy Heron (8.04) Server System (amd64)

Want to support HowtoForge? Become a subscriber!
 
Submitted by sidh4u (Contact Author) (Forums) on Fri, 2008-07-11 16:51. :: Ubuntu

Perfect NFS On An Ubuntu Hardy Heron (8.04) Server System (amd64)

NFS, Network File System, is a file sharing protocol in a UNIX network. It is the de facto UNIX standard. It is strongly associated with UNIX systems, although it can be used on any platform such as Macintosh and Microsoft Windows operating systems. This tutorial shows how to set up an NFS server and client on Ubuntu 8.04 (AMD64).

 

NFS Advantages:

Local workstations use less disk space because commonly used data can be stored on a single machine and still remain accessible to others over the network.
There is no need for users to have separate home directories on every network machine. Home directories could be set up on the NFS server and made available throughout the network.
Storage devices such as floppy disks, CDROM drives, and Zip® drives can be used by other machines on the network. This may reduce the number of removable media drives throughout the network.

 

Install NFS Server:

apt-get install nfs-kernel-server nfs-common portmap

 

NFS Server Configuration:

NFS exports from a server are controlled by the file /etc/exports. Each line begins with the absolute path of a directory to be exported, followed by a space-seperated list of allowed clients.

You need to edit the exports file using the following command:

vi /etc/exports

Here are some quick examples of what you could add to your /etc/exports - For Full Read Write Permissions allowing any computer from 192.168.1.1 through 192.168.1.255:

/home 192.168.1.201/24(rw,no_root_squash,async)

Where 192.168.1.201 is the IP of the NFS server.

A client can be specified either by name or IP address. Wildcards (*) are allowed in names, as are netmasks (e.g. /24) following IP addresses, but should usually be avoided for security reasons.

A client specification may be followed by a set of options, in parenthesis. It is important not to leave any space between the last client specification character and the opening parenthesis, since spaces are intrepreted as client seperators.

Now you need to restart NFS server using the following command:

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

You can validate the exported filesystem by the command:

exportfs

If you make any changes to /etc/exports on a running NFS server, you can make these changes effective by issuing the command:

exportfs -a

 

Install NFS client support in Ubuntu:

apt-get install portmap nfs-common

This will install all the required packages for the nfs client.

 

Mounting manually:

Example to mount server.mydomain.com:/home to /home. In this example server.mydomain.com is the name of the server containing the nfs share, and /home is the name of the share on the nfs server.

The mount point /home must first exist on the client machine.

Create files directory using the following command:

mkdir /home

You need to mount the share using the following command:

mount server.mydomain.com:/home /home

Now you may need to restart services using the following command:

/etc/init.d/portmap restart
/etc/init.d/nfs-common restart

 

Mounting at boot time using /etc/fstab:

If you want to mount using the fstab file (by the way - in big infrastructures it’s always better to use the fstab file):

vi /etc/fstab

In this example my /etc/fstab was like this:

server.mydomain.com:/home /home nfs rsize=8192,wsize=8192,timeo=14,intr

Change server.mydomain.com:/home, and /home to match your server name, share name, and the name of the mount point you created.

 

Firewall Ports for NFS:

If you have a firewall you need to make sure that the ports 32771, 111 and 2049 are open.

 

Testing Your Configuration:

Use the following command in terminal to test:

mount /home

The mount point /home will be mounted from the server to the client and using the df command the output should look like:

192.168.1.201:/home     7672288    810144   6475488  12% /home

That’s all... Thanks.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Mon, 2009-06-15 15:41.

thanks heaps - made the job very easy. couple of possible improvements:

 - it would be good to have an explanation of the options used (no_root_squash?, rsize?, wsize?) and why you chose them. I will look into these but would have been handy to have them here.

- while on chosen preferences, is there a reason i'm not aware of for the 'async' approach? the commented examples in the export file all use 'sync' and i would think that would be better to prevent race conditions when giving write permissions to another machine(s)

- restarting  nfs on the server generated:

"exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.1.50:/mydir". Assuming default behaviour ('no_subtree_check')"

I'll look further into it to see how this effects operations but i set it to subtree_check for now as i'd like as much checking of everything as possible if multiple pc's are reading and writing to a single dir.

 

thanks again for the quick-start

Submitted by Anonymous (not registered) on Sun, 2008-09-21 22:12.
Awesome, worked like a charm. Thanks!
Submitted by JIm Lees (not registered) on Sat, 2009-02-07 18:42.

I installed portmap and nfs-common, and restarted both with "service portmap restart" and the same command for nfs-common.

 

When I tried to mount the remote file with "sudo mount server:/home/me /mnt/mntpoint" I get the following error:

"mount.nfs: mount to nf server 'rpcbind' failed: RPC error: Program not registered

mount.nfs: Internal error

 

Any help would be appreciated.

Submitted by TEO (not registered) on Sat, 2011-11-26 17:26.
I know this comes too late, but I have encountered a very rare scenario where I have virtual machines all using VMware with NAT enabled for the network adapters.

Slackware, RedHat, and Knoppix machines could all connect to a virtual Slackware NFS server, but Ubuntu clients could not. I had already checked the following file:
/etc/exports /etc/hosts.deny /etc/hosts.allow

And had already restarted NFS via:
sudo sh /etc/rc.d/rc.nfsd restart

I also checked that the mounts were available via:
showmount -e

I work on a large network, so I give access to the entire /16 subnet.
#[/etc/exports]
/mnt/my_shared_folder 192.168.0.0/255.255.0.0(rw,no_root_squash,no_subtree_check,sync)
#[/etc/hosts.deny]
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

#[/etc/hosts.deny]
portmap:192.168.0.0/255.255.0.0
lockd:192.168.0.0/255.255.0.0
mountd:192.168.0.0/255.255.0.0
rquotad:192.168.0.0/255.255.0.0
statd:192.168.0.0/255.255.0.0

This should have effectively allowed any host with an IP address beginning with 192.168.xxx.yyy to connect to my server. I have even tested this, yet for some reason, the Ubuntu client would not connect until I reduced my subnet from a Class B (/16) to a Class C (/24) range, like so:
#[/etc/exports]
/mnt/my_shared_folder 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,sync)

#[/etc/hosts.deny]
portmap:192.168.1.0/255.255.255.0
lockd:192.168.1.0/255.255.255.0
mountd:192.168.1.0/255.255.255.0
rquotad:192.168.1.0/255.255.255.0
statd:192.168.1.0/255.255.255.0

I don't know why it is only the Ubuntu VM that requires this obscure workaround, but at least it works.
Submitted by Green (not registered) on Fri, 2009-03-27 03:02.
Hello, please check whether your nfs is started on the server side. try to invoke "/etc/init.d/nfs restart"
Submitted by Leonel (not registered) on Fri, 2011-10-14 22:54.
That last tip saved me a lot .Thanks