NFS HowTo
Table of Contents
- Introduction
- Acknowledgements
- How To Use This Document
- Requirements
- Create The Share
- Step 01 – Write down your information
- Step 02 – Create the mount point
- Step 03 – Install some software
- Step 04 – Reconfigure the portmap
- Step 05 – Edit the hosts.deny file
- Step 06 – Edit the hosts.allow file
- Step 07 – Edit the exports file
- Step 08 – Edit the fstab file
- Step 09 – Export your share
- Step 10 – Restart the portmap
- Step 11 – Restart nfs-common
- Step 12 – Restart nfs-kernel-server
- Work with the share
- Connect to the share automatically
- Connect to the share manually
- Use the share
- Disconnect from the share
- Maintain the share
- Appendix
- Obligatory Happy Ending
Introduction
- Impatient? Don’t want to read a bunch of stuff? Get right to it!
- The purpose of this document is to help you set up NFS to connect two Kubuntu or Ubuntu machines together with each machine being able to access the other.
- These instructions were tested on a desktop running Kubuntu Feisty Fawn, a laptop running Kubuntu Feisty Fawn, a desktop running Kubuntu Gutsy Gibbon, and two desktops running Kubuntu Hardy Heron LTS. The computers have a wired ethernet connection and are behind a hardware router.
- New! A use case example page has been created as a sister page to this one. You can find it here. The steps on that page coincide with the steps on this one, so you can watch the steps being put into use.
Acknowledgements
This document would not have been possible without a lot of help from some of the members of the alt.os.linux.ubuntu newsgroup.
How To Use This Document
- Make sure you meet the requirements in the Requirements section of this document.
- Follow the steps in the Create The Share section.
- Refer to the Maintain the share section of this document to maintain your NFS setup if you decide to tinker with the configuration files.
- Refer to the Troubleshooting section if you’ve followed the instructions on this page and you need to figure out why it’s not working.
- Refer to the Further Information section for links to some pages on the internet that provide more detailed information than is available here.
- Refer to the Questions and answers section for the answers to questions that commonly come up.
- Refer to the Examples section to compare your files with those shown here.
- Refer to the Advanced section if you’re an expert.
Requirements
- Kubuntu or Ubuntu.
- A hardware router. This is not an absolute requirement, but you should use a hardware router between your local network and the internet. For more information on why and how to set one up, see the Further Information section.
- An understanding of sudo, kdesu and gksudo. For more information, see the Further Information section.
- A static LAN IP. You must have a static LAN IP to use the instructions in this document. Otherwise, each time your IP address changes, you will need to edit the information in the configuration files on both computers to reflect the change. It’s important to choose a valid static IP which won’t conflict with the router’s settings. To learn how to choose and assign a static IP, see the Further Information section.
Create The Share
Step 01 – Write down your information
- You have two computers you’d like to connect together locally using NFS.
- For each of your computers, write down:
- the LAN IP address
- the path to the folder you’d like to share
- the path to the folder you’d like to click to visit the other computer
- In these instructions, Sally represents computer #1 and Dave represents computer #2.
- Follow Sally’s steps for one of your computers and Dave’s steps for the other computer.
- With computer #1, substitute its information for Sally’s and follow Sally’s steps.
- With computer #2, substitute its information for Dave’s and follow Dave’s steps.
- When both computers have completed all the steps, both will be able to use the shares.
![]() |
| ||||||||
![]() |
|
||||||||
Step 02 – Create the mount point
A mountpoint is a directory on your computer that you can use as a “doorway” to somewhere else. When you open this directory on your computer, the shared files and folders from the other computer will be inside it waiting for you.
![]() |
SALLY, create the mount point by typing this command in a terminal window:
|
![]() |
DAVE, create the mount point by typing this command in a terminal window:
|
Step 03 – Install some software
These are the packages needed to follow the instructions in this guide.
- The nfs-kernel-server package is the NFS server itself.
- The nfs-common package includes packages used by NFS for the client and/or the server.
- The portmap package maps requests from other computers to specific ports (kind of like an operator directing calls).
- The tcpd package provides the two files used by NFS to determine who’s allowed access to your computer.
![]() |
SALLY, install some software by typing this command in a terminal window:
|
![]() |
DAVE, install some software by typing this command in a terminal window:
|
Step 04 – Reconfigure the portmap
By default, portmap is set to work only on the Loopback Interface, which is your local machine. To tell it to work on the network, you must reconfigure it.
![]() |
SALLY, reconfigure the portmap by typing this command in a terminal window:
When asked if you’d like Portmap to bind to Loopback Interface, say NO and exit the program. |
![]() |
DAVE, reconfigure the portmap by typing this command in a terminal window:
When asked if you’d like Portmap to bind to Loopback Interface, say NO and exit the program. |
Whoops!
![]() |
SALLY, if you said YES in Step 04 by mistake, edit the portmap file with one of these commands:
Make sure the OPTIONS line is identical to this one (change it if it’s not):
Save the file and exit the editor. |
![]() |
DAVE, if you said YES in Step 04 by mistake, edit the portmap file with one of these commands:
Make sure the OPTIONS line is identical to this one (change it if it’s not):
Save the file and exit the editor. |
Step 05 – Edit the hosts.deny file
This file defines who/what will be denied access to your computer. Access will be denied to any daemon or client listed in this file. A blanket denial of all makes it so that only those you specify in the hosts.allow file (see Step 06) will be granted access.
![]() |
SALLY, edit the hosts.deny file with one of these commands:
Add this line to the bottom of the file:
Save the file and exit the editor. |
![]() |
DAVE, edit the hosts.deny file with one of these commands:
Add this line to the bottom of the file:
Save the file and exit the editor. |
Step 06 – Edit the hosts.allow file
This file defines who/what will be granted access to your computer. Access will be granted to any daemon or client listed in this file. An entry needs to contain the daemon or client followed by a colon followed by a space followed by the IP of the computer you want to grant access to. Additional IPs can be added by putting a space between each one and the one before it. The daemons and clients shown in the examples below are used by NFS.
![]() |
SALLY, edit the hosts.allow file with one of these commands:
Add these lines to the bottom of the file:
Save the file and exit the editor. |
![]() |
DAVE, edit the hosts.allow file with one of these commands:
Add these lines to the bottom of the file:
Save the file and exit the editor. |
Step 07 – Edit the exports file
This file defines what you’re willing to share and who you’re willing to share it with. Each line of the file is a share. An NFS entry needs to contain the location of the directory you want to share followed by the IP of the computer you wish to share it with followed by rules (in parentheses) of what the computer at that IP can and cannot do. To share a folder with more than one computer, place the IPs and the rules for each one on the same line as the directory you want to share, separating them from one another with a space. In the examples below:
- rw means the other computer can read and write to your shared directory and its subdirectories.
- sync basically means your computer must be finished processing any changes made to files or directories in your shared directory before it proceeds with any further action on those files or folders.
- no_subtree_check means NFS doesn’t have to check the location of files every time the other computer accesses them, which makes it possible for you to rename a file the other computer has open.
See the exports man page to make different choices for what the other computer can and cannot do.
![]() |
SALLY, edit the exports file with one of these commands:
Add this line to the bottom of the file:
Save the file and exit the editor. |
![]() |
DAVE, edit the exports file with one of these commands:
Add this line to the bottom of the file:
Save the file and exit the editor. |
Step 08 – Edit the fstab file
This file defines the file systems your computer mounts when you boot the computer. Examples of file systems are entire drives or parts of drives (partitions), CD or DVD drives, or NFS shares. Your fstab file will already have entries in it. An NFS entry needs to contain the other computer’s IP followed by the path to the directory the other computer wants to share with you followed by the directory on your computer that you want to use as a “doorway” to the other computer (your mountpoint) followed by the type of file system that is being mounted followed by a list of options that define how NFS is allowed to behave in the shared directory. In the examples below:
- nfs is the type of file system that is being mounted.
- hard tells NFS to keep retrying if a request times out.
- intr does its best to protect your data from corruption by allowing signals to interrupt file operations in the shared directory.
- noexec forbids direct execution of binary files on the mounted file system.
- 0 0 (the two zeros at the end of the line) are for file system backup and file system checks on certain file system types. Since NFS doesn’t use either of these things, the value of each is zero, which means that the directory shared by the other computer won’t be included in a file system backup or a file system check.
See the nfs, fstab and mounts man pages to make different choices for how NFS should be allowed to behave.
![]() |
SALLY, edit the fstab file with one of these commands:
Add this line to the bottom of the file:
Save the file and exit the editor. |
![]() |
DAVE, edit the fstab file with one of these commands:
Add this line to the bottom of the file:
Save the file and exit the editor. |
Step 09 – Export your share
This command lets your computer know about any changes you’ve made in your /etc/exports file.
![]() |
SALLY, export your share by typing this command in a terminal window:
|
![]() |
DAVE, export your share by typing this command in a terminal window:
|
Step 10 – Restart the portmap
This command restarts the portmap. This makes sure the portmap is aware of any changes you’ve made to the configuration files mentioned above.
![]() |
SALLY, restart the portmap by typing this command in a terminal window:
|
![]() |
DAVE, restart the portmap by typing this command in a terminal window:
|
Step 11 – Restart nfs-common
This command restarts the programs used by NFS for the client and/or the server. This makes sure these programs are aware of any changes you’ve made to the configuration files mentioned above.
![]() |
SALLY, restart nfs-common by typing this command in a terminal window:
|
![]() |
DAVE, restart nfs-common by typing this command in a terminal window:
|
Step 12 – Restart nfs-kernel-server
This command restarts the NFS server. This makes sure the server is aware of any changes you’ve made to the configuration files mentioned above.
![]() |
SALLY, restart nfs-kernel-server by typing this command in a terminal window:
|
![]() |
DAVE, restart nfs-kernel-server by typing this command in a terminal window:
|
Work with the share
Connect to the share automatically
![]() |
SALLY, reboot your computer. If Dave booted his computer before you booted yours, you will automatically be connected to his share. |
![]() |
DAVE, reboot your computer. If Sally booted her computer before you booted yours, you will automatically be connected to her share. |
Connect to the share manually
To manually connect to the share, you need to mount the directory on your computer that you are using as a “doorway” to the shared files from the other computer.
![]() |
SALLY, If Dave booted his computer after you booted yours, you’ll need to manually connect to his share. To do so, type this command in a terminal window:
|
![]() |
DAVE, if Sally booted her computer after you booted yours, you’ll need to manually connect to her share. To do so, type this command in a terminal window:
|
Use the share
The share is treated just like any other part of your computer, other than any restrictions set by you or the other computer when setting it up. You, and the programs on your computer, can access the files and folders in the share normally.
![]() |
SALLY, open your file manager and you’ll find the shared folder you created inside your /home/sally folder. Clicking on this shared folder will put you on Dave’s computer. You can also open files on Dave’s computer by browsing to them from within various programs you run on your computer. If you prefer to access Dave’s computer using the command line, use /home/sally/shared to get to it. |
![]() |
DAVE, open your file manager and you’ll find the shared folder you created inside your /home/dave folder. Clicking on this shared folder will put you on Sally’s computer. You can also open files on Sally’s computer by browsing to them from within various programs you run on your computer. If you prefer to access Sally’s computer using the command line, use /home/dave/shared to get to it. |
Disconnect from the share
To disconnect from the share, you need to unmount the directory on your computer that you are using as a “doorway” to the shared files from the other computer.
![]() |
SALLY, if you wish to disconnect the shared folder from Dave’s computer, in a terminal window type:
|
![]() |
DAVE, if you wish to disconnect the shared folder from Sally’s computer, in a terminal window type:
|
Maintain the share
SALLY and DAVE, if you tinker with your configuration files by making changes in them, you’ll need to either restart NFS or restart the network. Sometimes both will be necessary. Here’s how:
Restart NFS
- Type these commands in a terminal window one by one:
-
sudo exportfs -ar
-
sudo /etc/init.d/portmap restart
-
sudo /etc/init.d/nfs-common restart
-
sudo /etc/init.d/nfs-kernel-server restart
Restart the network
- Type this command in a terminal window:
sudo /etc/init.d/networking restart
Appendix
Examples
These examples show only the relevant information that pertains to NFS. Some files on your computer (like the /etc/fstab file, for instance) may contain more than what is shown here.
/etc/network/interfaces
![]() |
SALLY’S /etc/network/interfaces file:
|
![]() |
DAVE’S /etc/network/interfaces file:
|
/etc/default/portmap
![]() |
SALLY’S /etc/default/portmap file:
|
![]() |
DAVE’S /etc/default/portmap file:
|
/etc/hosts.deny
![]() |
SALLY’S /etc/hosts.deny file:
|
![]() |
DAVE’S /etc/hosts.deny file:
|
/etc/hosts.allow
![]() |
SALLY’S /etc/hosts.allow file:
|
![]() |
DAVE’S /etc/hosts.allow file:
|
/etc/exports
![]() |
SALLY’S /etc/exports file:
|
![]() |
DAVE’S /etc/exports file:
|
/etc/fstab
![]() |
SALLY’S /etc/fstab file:
|
![]() |
DAVE’S /etc/fstab file:
|
Advanced
- Alternate way of installing hosts.allow and hosts.deny
- As part of the instructions in this document, tcpd is installed so that the /etc/hosts.allow and /etc/hosts.deny files are created automatically. The tcpd package is not required for these instructions to work. You advanced users can use the touch command to create both of these files instead of installing tcpd.
- Why I chose sync instead of async in /etc/exports
- In the /etc/exports file I have chosen to use sync instead of async. I realize this causes a performance hit, but I feel that protecting the stability and reducing the likelihood of file corruption is worth it. Feel free to change the command if you prefer the performance increase and are aware of the risks.
- Why I used noexec in /etc/fstab
- In the /etc/fstab file I have chosen to use noexec to prevent direct execution of binaries on the mounted file system. This is being done for security purposes. If your use of NFS requires execution of binaries, you’ll want to remove the noexec portion of the command.
- For those who don’t use a hardware router
- For you experts who don’t use a hardware router and have your reasons for making this choice, I’m confident that the process by which you came to that decision makes it so that you’ll know how to work around the router information in this document.
- Using these instructions for more than two computers
- These instructions can be applied to more than two computers by repeating either Sally’s or Dave’s steps for the newly added computer, adding the information for each additional computer when editing the files, and editing the files on the other computer(s) that have already been set up with NFS to include the new computer(s) on the network. See my NFSUseCase page for an example with three computers.
Further information
- To learn how to set up a hardware router, the page at http://www.smallnetbuilder.com/content/view/26383/44/ seems to have thorough, detailed information.
- To learn how sudo, kdesdu and gksudo work, see https://help.ubuntu.com/community/RootSudo and http://www.psychocats.net/ubuntu/graphicalsudo for detailed information.
- To learn how to choose and assign a static IP, see my StaticIP page.
- To learn a lot more about NFS, http://nfs.sourceforge.net/nfs-howto/ is a great starting point.
Questions and answers
- I followed Sally’s steps and can’t connect to my other (Dave’s) computer. Why?
- Since each computer must grant access to the other, both computers must follow the steps for the shares to work. If you’ve only set up one computer so far, this could explain the difficulty. If you’ve done that and still can’t connect, go through all the files in the Examples section one by one, viewing the files on each of your computers to make sure the information in each has the correct information for that machine, no typos, etc.
- I have a question that hasn’t been asked here. How do I ask it?
- If you use the contact address at the top of this document, you will receive a reply via email and your question may be added to this section.
Troubleshooting
Most troubleshooting can be done by:
- Making sure that you meet the requirements in the Requirements section.
- Verifying that you have completed the steps to set up NFS.
- Comparing your computer’s files against those in the Examples section.
- Checking that your servers are running. In a terminal window type each of these:
- sudo /etc/init.d/portmap status
- sudo /etc/init.d/nfs-common status
- sudo /etc/init.d/nfs-kernel-server status
If any of them aren’t reported as running, repeat the steps in the Maintain the share section of this document.
There’s always the possibility that something outside the scope of this document is causing trouble for you. For example, I haven’t covered wireless networking. I highly recommend that you check out the Further Information and Questions and answers sections for further troubleshooting.
If you need more help than is available here, see my GettingHelp page.
Obligatory Happy Ending
And they all lived happily ever after. The end.
![]() |
Except where otherwise noted, content on http://mostlylinux.wordpress.com is Copyright © 2007 – 2009 by Little Girl, licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License, and offered free of charge without warranty of any kind, either expressed or implied. |




I want to thank you for providing such awonderfully clear and detailed instructions! It is so nice to work with this information instead of the usual scrounging through bulletin boards. I’m not knocking them -
Comment by fitzhugh — July 14, 2009 @ 11:20 am
oops, hit return…,
just saying bulletin boards are great, nearly always find the answer eventually, but it is so much easier when someone takes the time to collect all the info, especially when that person knows how to present information to their audience as well as you.
Thanks!
Comment by fitzhugh — July 14, 2009 @ 11:25 am
Thanks for the kind words! This particular page is one of my pet projects since I had such a tough time with it when I first set it up. I couldn’t get it working no matter what I tried, resulting in an all-consuming epic battle that must be overcome. When I finally got it, it was like a personal epiphany, so NFS has become a deeply loved adopted child. (:
Comment by mostlylinux — July 14, 2009 @ 1:40 pm