Mounting NFS shares on Mac OS X

I've recently decided to give Mac OS X a try. For the past week or so I've been spending a good few hours a day working in Snow Leopard installed on a MacBook Pro borrowed from a friend.

While Mac OS is unlike any Unix-like operating system I've managed so far, there are certainly some of similarities. I can honestly say that I'm enjoying the Mac Book Pro so far, and hope to discover most of the differences compared to my previous Unix-like desktop which is Ubuntu 9.10.

Mounting NFS on MAC OS X

One thing which I noticed immediately was that out of the box it was impossible to mount any NFS shares from my Ubuntu NAS server. Any attempt to mount a remote filesystem would give me an error like this:

mbp:~ root# mount nasbox:/try /mnt
mount_nfs: /mnt: Operation not permitted

This error was happening for a relatively simple NFS share on the Ubuntu box:

nasbox# cat /etc/exports
/try            (rw)

… so I started looking around and realized that the reason for this strange problem is quite simple.

Mac OS X uses non-standard port for outgoing NFS connections

That's right – apparently, Mac OS X uses a non-privileged port (2049) for TCP and UDP connections serving the NFS transport. What this means is that most likely attempts to mount remote filesystems will fail, because most NFS servers don't really like connections from insecure ports.

There are two ways to approach this problem:

  1. Fix it on the client side (probably makes more sense)
  2. Fix it on the NFS server side (if you manage both systems)

Using reserved NFS port number on Mac OS X

There's a mount option supported by the mount_nfs command, which allows you to force the NFS client connections to originate from a privileged port. This will magically make your attempts to mount remote filesystems successful. The option is called resvport.

First we double-check that default mounts still don't work:

mbp:~ root# mount nasbox:/try /mnt
mount_nfs: /mnt: Operation not permitted

… and now let's use the resvport option:

mbp:~ root# mount -o resvport nasbox:/try /mnt

… and make sure we're actually looking at a mounted filesystem:

mbp:~ root# df -h /mnt
Filesystem   Size   Used  Avail Capacity  Mounted on
nasbox:/try    61Gi   56Gi  2.6Gi    96%    /mnt

Allowing connections from non-privileged ports on NFS server

Like I said, if you manage both the Mac OS based client and the NFS server, perhaps it makes more sense to relax the default NFS server security and allow the connections from non-privileged ports.

Just to remind you about the validity of such a decision, the option to allow non-privileged connections is called insecure.

Here's how you use it:

nasbox# cat /etc/exports
/try            (rw,insecure)

After making this change to the /etc/exports file, you'll have to restart your NFS server. On my Ubuntu NAS box, it's done like this:

nasbox# /etc/init.d/nfs-kernel-server restart
* Stopping NFS kernel daemon
…done.
* Unexporting directories for NFS kernel daemon…
…done.
* Exporting directories for NFS kernel daemon…
…done.
* Starting NFS kernel daemon
…done.

We know are ready to attempt the default mount of the same filesystem on the Mac OS X client:

mbp:~ root# mount nasbox:/try /mnt

That's it! I won't promise any Mac OS posts just yet, but if there is enough interest – I'd love to do the research and to post all the discoveries on the Unix Tutorial pages.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
  • http://www.twitter.com/jchiarelli Joe

    Great post. Love more unix on Mac os posts, keep em coming.

    Ive got Redhat, ubunto and Solaris (and Mac Os) and love your posts. Mac OS hides everything so well under the hood..

  • Dan The Man

    I had the same problem. Without access to the server I had to solve it client side.

    The mount_nfs option resvport did the trick!!!

    mount -o resvport …

    worked like a charm ! Thanks.

  • gray

    Did you try just:
    # cd /net/nasbox

  • Peter

    Hi!

    This did point me in the right direction, many thanks!

    Remaining problem is that I only get read access to the NFS share from the Mac. Any clue?

    My exports file on the Ubuntu server is:
    /home/user_name 192.168.100.0/24(rw,sync,no_subtree_check,insecure,anonuid=1001)
    … where anonuid is the id of the Linux user

    I used the following command on the mac to mount the share:
    mount -r -t nfs linuxbox:/home/user_name /Users/user_name/share

    Works just fine; but I only have read access. Any clue?

  • Ash

    Thank you for your post, it helped me out :)

  • Paul

    You can also mount NFS shares using Disk Utility, as described here:
    http://kampmeier.com/chris/blog/?p=43

  • Steve

    After changing /etc/exports on Linux, it is not necessary to restart the NFS server. Just say "exportfs -r".

  • http://www.glebreys.com Gleb Reys

    Thanks for sharing this tip Steve, I did not know about it in Mac OS X (don't own any Apple device yet), and it seems that exportfs -r is not found in most other Unix-like operating systems.

  • http://www.glebreys.com Gleb Reys

    Hi Peter,

    the reason it's read-only is because you're telling the mount command to only mount filesystem in read-only mode: -r parameter means read-only.
    Try this:

    mount -t nfs linuxbox:/home/user_name /Users/user_name/share

    Should work.

  • http://jm.marino.free.fr JM Marino

    This is a good topic but have you try to use AutomountMaker ?

    http://jm.marino.free.fr/index.php?switch=sw_&title=AutomountMaker

  • T Tessier

    How about the UID/GID matching? I am trying to run in a combined Linux, Windows and MacOS environment. Windows is managed by Samba changing the users UID but if doing NFS to the MacOS shouldn't I be using the same UID/GID of the Linux system to properly share the data?

  • Pingback: Mount NFS shares on OSX « 0ddn1x: tricks with *nix

  • Pingback: Mount NFS shares on OSX « 0ddn1x: tricks with *nix

  • JP

    Port 2049 is used for nfs on Solaris 10.
    Since Sun invented nfs I would say 2049 is the standard port and this appears to be so for all unixes.
    Your Ubuntu is non-standard.