≡ Menu

Ubuntu Linux: NFS Client Configuration To Mount NFS Share

NFS (Network File System) client allows you to access shared directory from Linux client. The computer sharing the directory is called the NFS server (it can be NAS server too) and the computers or devices connecting to that server are called clients. The clients need to use the mount command to access the shared directory.

Ubuntu NFS

You need to install nfs-command package as follows (open terminal and type the following command):
$ sudo apt-get update
$ sudo apt-get install nfs-common

Sample outputs:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  libgssglue1 libnfsidmap2 librpcsecgss3 portmap
The following NEW packages will be installed:
  libgssglue1 libnfsidmap2 librpcsecgss3 nfs-common portmap
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 333kB of archives.
After this operation, 1,126kB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://archive.ubuntu.com/ubuntu/ lucid/main libgssglue1 0.1-4 [22.4kB]
Get:2 http://archive.ubuntu.com/ubuntu/ lucid/main libnfsidmap2 0.23-2 [29.1kB]
Get:3 http://archive.ubuntu.com/ubuntu/ lucid/main librpcsecgss3 0.19-2 [33.1kB]
Get:4 http://archive.ubuntu.com/ubuntu/ lucid/main portmap 6.0.0-1ubuntu2 [37.2kB]
Get:5 http://archive.ubuntu.com/ubuntu/ lucid/main nfs-common 1:1.2.0-4ubuntu4 [212kB]
Fetched 333kB in 3s (95.3kB/s)
Preconfiguring packages ...
Selecting previously deselected package libgssglue1.
(Reading database ... 161647 files and directories currently installed.)
Unpacking libgssglue1 (from .../libgssglue1_0.1-4_i386.deb) ...
Selecting previously deselected package libnfsidmap2.
Unpacking libnfsidmap2 (from .../libnfsidmap2_0.23-2_i386.deb) ...
Selecting previously deselected package librpcsecgss3.
Unpacking librpcsecgss3 (from .../librpcsecgss3_0.19-2_i386.deb) ...
Selecting previously deselected package portmap.
Unpacking portmap (from .../portmap_6.0.0-1ubuntu2_i386.deb) ...
Selecting previously deselected package nfs-common.
Unpacking nfs-common (from .../nfs-common_1%3a1.2.0-4ubuntu4_i386.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
Setting up libgssglue1 (0.1-4) ...
Setting up libnfsidmap2 (0.23-2) ...
Setting up librpcsecgss3 (0.19-2) ...
Setting up portmap (6.0.0-1ubuntu2) ...
portmap start/running, process 4193
Setting up nfs-common (1:1.2.0-4ubuntu4) ...
Creating config file /etc/idmapd.conf with new version
Creating config file /etc/default/nfs-common with new version
Adding system user `statd' (UID 116) ...
Adding new user `statd' (UID 116) with group `nogroup' ...
Not creating home directory `/var/lib/nfs'.
statd start/running, process 4416
gssd stop/pre-start, process 4441
idmapd stop/pre-start, process 4469
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

Task: See The List Of All Shared Directories

Type the following command:
$ showmount -e server-Ip-address
$ showmount -e 192.168.1.1

Sample outputs from my 192.168.1.1 NFS server:

Export list for 192.168.1.1:
/viveks
/Web
/Usb
/Recordings
/Public
/Network Recycle Bin 1
/Multimedia
/Download

Task: Mount Shared Directory

Now mount /viveks directory as follows>:
$ sudo mkdir /nfs
$ sudo mount -o soft,intr,rsize=8192,wsize=8192 192.168.1.1:/viveks /nfs
$ df -h

Sample outputs:

/dev/sda5              477G    25G   428G   6% /
none                   4.2G   398k   4.2G   1% /dev
none                   4.2G   377k   4.2G   1% /dev/shm
none                   4.2G   230k   4.2G   1% /var/run
none                   4.2G      0   4.2G   0% /var/lock
none                   4.2G      0   4.2G   0% /lib/init/rw
192.168.1.1:/viveks    491G   208M   491G   1% /nfs

How do I Access My Files Using NFS?

Just go to mount point i.e. /nfs directory with the cd command:
cd /nfs
ls
gedit file.c

How Do I Mount NFS Automatically After Reboot?

Edit /etc/fstab, enter:
$ sudo vi /etc/fstab
OR use gui text editor such as gedit:
$ sudo gedit /etc/fstab
Append the following line:

192.168.1.1:/viveks  /nfs  nfs   soft,intr,rsize=8192,wsize=8192

Save and close the file.

How Do I Remove Mounted NFS Directory (unmount NFS)?

Type the following command:
$ cd
$ sudo umount /nfs
$ df -H

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 36 comments… add one }

  • Someone Else June 27, 2006, 2:32 am

    Thanks. You made it really simple for me. I am new to Ubuntu and hoping to get away from Microsoft, so long as help is around. Thanks!

  • Ryan August 19, 2006, 4:56 pm

    I get permission denied when changing to the nounted directory, yet it works fine as root?

  • nixCraft August 19, 2006, 6:10 pm

    This is a permission problem. Setup a correct permission using chmod command on exported directory. Or map user id using map_static option.

  • Jeffala November 4, 2006, 9:29 pm

    Thanks for sharing. SuSE has a gui wizard to handle NFS client and server config. I thought I was going to have give up some features.

    Thanks again.

  • shanmugam October 11, 2007, 11:33 am

    hi
    I need of the linux advance server and trubleshooting book in pdf format ver urgent.please send me in my mail id is shanmugam.jayapal@gmail.com

  • Selva May 13, 2009, 7:16 am

    thx, dude, u saved my day.

    – :)

  • Junior June 3, 2009, 8:09 am

    Hi,

    Installing nfs-common didn’t work for me. Instead i installed the
    sudo apt-get install portmap nfs-kernel-server

    That did it for me!!
    Grtz

  • Tobbs June 18, 2009, 11:53 am

    Too complicated. All problems with different ports, processes, firewall, SELinux, etc is just too much. Compared to SSH, I cant help wondering why NFS isn’t more easy to install and use. Think fileserver functionality should have been easier that opening programs remote!? Sorry folks…

  • matt mcinvale July 18, 2009, 9:39 pm

    might want to include some info on /etc/fstab here too.

  • cheeky October 15, 2009, 3:04 am

    Oh thanxs very much u save my money and of course my time…

  • pgngp October 23, 2009, 8:58 pm

    Thanks! This tutorial saved me so much time and effort!

  • Manish February 15, 2010, 8:32 am

    Thanks. You made it really simple for me. I am new to Ubuntu and hoping to get away from Microsoft, so long as help is around. Thanks!

  • junior April 6, 2010, 3:12 am

    how can i access in share folder in ubuntu in client pc
    pls check it
    ok

  • dano September 1, 2010, 6:21 am

    the same problem as Junior: the nfs-common is not installing at:
    #apt-get install nfs-common
    i’ve tried to make un upgrade:
    #apt-get upgrade
    and the result is the same . the message for installing is:
    nfs-common is already the newest version but when it doesn’t create
    /etc/init.d/nfs-common.
    what should i do?

  • Jose H November 22, 2010, 7:15 pm

    Hi, the tutorial was great, got my nfs shares mounted atomatically at start on my netbook :D

    One thing I did notice was that my boot time has been made much longer. Is there a way to delay the mounting of the nfs shares?

    Thank you :D

  • Gregor December 25, 2010, 7:45 pm

    This tutorial work, thanks for writing it.

    Greetings from Denmark
    Gregor

  • Thomas December 28, 2010, 6:37 pm

    I have a debian machine as client, and a synology NAS as NFS server.

    The folders on the NAS are protected by user/pass.

    I cannot find anything on the web that tells me how i should send the user/pass along with the mount command :(

    in windows i would just do \\ip\share and then enter user/pass when promted. seems much easier

  • Zaf December 31, 2010, 9:11 am

    Note worked for me:
    rpcbind: server localhost not responding, timed out
    Z.

  • Rodney Beede March 1, 2011, 10:08 pm

    In some cases even though you put an entry in /etc/fstab the share may fail to load. The networking must all be setup before it will work.

    Using _netdev does not always work either. The boot process with nfs4 and newer distros does not wait.

    You have to setup an rc script to mount nfs shares after network setup.

    • bigj January 1, 2012, 6:34 am

      Had same problem.

      I know its not ideal but for starters I have put the mount command in rc.local and had to add a ‘sleep 20’ command in the line above. Which gives me enough time to login and for wifi to connect. But fails if I don’t login straight away.

      Am looking at some sort of pinging/loop script which doesn’t mount the share until it receives a reply from return ping from NASBox

      • bigj January 1, 2012, 7:29 am

        Ok I think I’ve solved it, for those of you that are having problems getting it to mount at boot etc. Please let me know though if this is right as I’m no expert but mashed a few different ideas/scipts together including the above steps!

        Setup: I have a small mini-tower running FreeNAS 0.7* with nfs shares enabled – path = /mnt/share1
        static IP = 192.168.1.250

        I also have a laptop running Ubuntu 10.04 LTS connecting to the same network using wifi with a folder created to mount the share into:
        /media/share1

        Initially as above had a mount command in /etc/rc.local but because of the delay in logging in and connecting to the wifi, the script failed. I added the sleep command which worked but only if i logged in straight away.

        I then found a few scripts which involved pinging the NASBox and once a reply ping was recieved then it mounted the command. So with a few tweaks and with help from friends more in the know than me we came with this script:

        #!/bin/sh

        while true;
        do
        ping -c1 192.168.1.250 > /dev/null &&
        break;
        done

        mount -t nfs 192.168.1.250:/mnt/share1 /media/share1

        Called it sharemount.sh and made the script executable and ran it in terminal (as sudo of course) and it worked! So, the next step was to have it run at boot. For this I copied it into /etc/init.d and ensured it was still executable. Then I had to update-rc.d (not sure f thats the right way to say it!) the script and make sure it had the correct run-levels. I wanted it to run after network had started so:

        sudo update-rc.d sharemount.sh start 99 2 3 4 5 .

        Rebooted the laptop and the share appeared. It even showed up on the desktop before the wifi login display appeared!

        N.B. I know alot of the scripts are being slowly moved to upstart(?) but this worked for me so feel free to use it obviously because I know I’m not the only one with this problem. But also feel free to let me know if I have done anything wrong as I am still learning too!

  • C. Mahalingam April 6, 2011, 11:30 am

    in ubuntu I cannot able to install nfs-common
    #apt-get install nfs-common
    nfs-common is already the newest version but when it doesn’t create
    /etc/init.d/nfs-common.
    I have tried even after removing nfs-common
    #apt-get remove nfs-common

    how to solve this problem.

    • Matt January 9, 2013, 1:41 pm

      Hey C. Mahalingam
      try these steps:
      sudo -i (enter credentials)
      apt-get purge nfs-common
      apt-get autoremove
      apt-get update
      apt-get upgrade
      apt-get install nfs-common
      apt-get update
      apt-get upgrade
      then try mounting again

      Matt.

  • Ahmed May 7, 2011, 10:40 pm

    This is by far the best HowTo I ever seen for mounting NFS shares on ubuntu.
    Thanks dude :)

  • burak July 30, 2011, 3:21 pm

    Terminal produced this:

    tvin@tvin-Macmini ~ $ showmount -e 192.168.2.149
    Export list for 192.168.2.149:
    /DataVolume/tvin *
    /DataVolume/Public *
    /DataVolume/Download *
    /DataVolume/acarburak *
    tvin@tvin-Macmini ~ $ sudo mkdir /nfs
    mkdir: cannot create directory `/nfs’: File exists
    tvin@tvin-Macmini ~ $ sudo mount -o soft,intr,rsize=8192,wsize=192.168.2.149:/DataVolume/public /nfs
    mount: can’t find /nfs in /etc/fstab or /etc/mtab
    tvin@tvin-Macmini ~ $ df -h

    Can anyone help?

    • TryMe July 30, 2011, 6:58 pm

      /nfs seems like a file. Try it as follows:

      sudo mkdir /nfs2
      sudo mount -o soft,intr,rsize=8192,wsize=192.168.2.149:/DataVolume/Public /nfs2
      
      • burak July 30, 2011, 8:22 pm

        Thank you, but Terminal doesn’t accept my passwd anymore, all of a sudden (I guess).

        • TryMe July 30, 2011, 8:29 pm

          sudo will prompt for password once in every 5 mintues. Run the df command to verify that nfs is mounted at /nfs2

          • burak July 30, 2011, 8:35 pm

            No, it’s not.

            • burak July 30, 2011, 8:36 pm

              tvin@tvin-Macmini ~ $ df
              Filesystem 1K-blocks Used Available Use% Mounted on
              /dev/sda3 18263168 4084516 13250920 24% /
              none 484552 700 483852 1% /dev
              none 495360 248 495112 1% /dev/shm
              none 495360 372 494988 1% /var/run
              none 495360 0 495360 0% /var/lock
              /dev/sdb3 692358132 614644 691743488 1% /media/MEDYA
              /dev/sdb2 39062500 26080056 12982444 67% /media/OS X
              /dev/sda2 57617188 26519600 31097588 47% /media/NOSI
              tvin@tvin-Macmini ~ $

  • Mohsen Miran September 7, 2011, 7:08 pm

    Thank You Very Much :))))

  • kk November 13, 2011, 11:35 am

    Hi ,
    I Created a NFS share in windows 2008 and i tried to mount it as in tutorial, everything went fine but when i access the directory it says “bash: cd: /nfs: Permission denied”
    I am able to see that mount using df -h.
    Please help..
    Thanks in advance

  • randomguy May 6, 2012, 10:28 am

    bigj, your sharemount script works great! I’m running lubuntu w/wifi and NFS shares. I had some .bash login/logout scripts on 11.10, but it wouldn’t allow my pc to sleep/suspend.

  • jane August 18, 2012, 5:01 am

    how can one browse the contents of an NFS share without mounting it? [ubuntu nfs client]

    • Matt January 9, 2013, 1:47 pm

      Try this
      showmount -e

      This displays all of the nfs shares on that server/computer

      Matt.

  • Eoin August 15, 2015, 5:59 am

    Thanks for this helpful tutorial! I’ve gone through about ten tutorials and this is the one that finally solved it for me. I didn’t realise that I had the NFS share name incorrect, but your step above to list that share fixed that for me.

    Fantastic article, still helping people 9 years after you wrote it!

Leave a Comment