mount.nfs: access denied by server while mounting on Ubuntu machines?

exportfs

When you create a /etc/exports file on a server you need to make sure that you export it. Typically you'll want to run this command:

$ exportfs -a

This will export all the entries in the exports file.

showmount

The other thing I'll often do is from other machines I'll check any machine that's exporting NFS shares to the network using the showmount command.

$ showmount -e <NFS server name>

Example

Say for example I'm logged into scully.

$ showmount -e mulder
Export list for mulder:
/export/raid1/isos     192.168.1.0/24
/export/raid1/proj     192.168.1.0/24
/export/raid1/data     192.168.1.0/24
/export/raid1/home     192.168.1.0/24
/export/raid1/packages 192.168.1.0/24

fstab

To mount these upon boots you'd add this line to your client machines that want to consume the NFS mounts.

server:/shared/dir /opt/mounted/dir nfs rsize=8192,wsize=8192,timeo=14,intr

automounting

If you're going to be rebooting these servers then I highly suggest you look into setting up automounting (autofs) instead of adding these entries to /etc/fstab. It's a bit more work but is well worth the effort.

Doing so will allow you to reboot the servers more independently from one another and also will only create the NFS mount when it's actually needed and/or being used. When it goes idle it will get unmounted.

References

  • 18.2. NFS Client Configuration - CentOS 5 Deployment Guide

I saw the same error (mount.nfs: access denied by server while mounting...) and the issue was fixed by -o v3 option as follows:

$ sudo mount -o v3 a-nfs-server:/path/to/export /path/to/mount
  • Server is Ubuntu 14.04 64bit LTS.
  • Client is CentOS 6.5 64bit.

In my case works using nfs4 doing:

$ sudo mount -t nfs4 server-name:/ /path/to/mount

In the /etc/export file on server

/Path/to/export 192.168.1.0/24(rw,sync,fsid=0,no_root_squash,crossmnt,no_subtree_check,no_acl)

fsid=0 makes the /Path/to/export the root directory when you mount the share.

crossmnt, because I have some others drives in the exported file system that I want to access also.

no_root_squash, because I want to access as root user (su) from the client side. I'm pretty sure that I'm the only one that can do that in my local network.

Server and clients are Ubuntu 14.04 64bit.

If you want to use nfs3, the answer of @fumisky-wells works for me as well.