Copy From:http://linuxconfig.org/how-to-configure-nfs-on-linuxhow to configure NFS on Linux 1. Introduction
The Network File System is certainly one of the most widely used Network services. Network file System (NFS) is based on the Remote procedure call which allows the client to automatically mount Remote file Systems and therefore transparently provide an access to it as if the file system is local.
If you still has some questions after reading this article please try our new Linuxcareer Forum.
2. Scenario
In this scenario we is going to export the file system from the IP address 10.1.1.50 (NFS server) host and mount it On a host with an IP address 10.1.1.55 (NFS Client). Both NFS Server and NFS client would be running Ubuntu Linux.
3. Prerequisites
At this point, we assume the NFS service daemon are already installed on your system, including Portmap daemon on whic H NFS Setup depends.
If you are not doing so yet simply the install Nfs-common package on both NFS Client and NFS server using using Apt-get tool.
# Apt-get Install Nfs-common
The command above'll fetch and install all support files common to NFS client and NFS server including Portmap.
Additionally we need to install the extra package on our NFS server side.
Apt-get Install Nfs-kernel-server
This are the actual NFS daemon listenning on both UDP and TCP 2049 ports.
Execute rpcinfo-p to check correctness of your NFS installation and to actually confirm, NFS server is indeed running and accepting calls on a port 2049:
# Rpcinfo-p | grep NFS 100003 2 UDP 2049 NFS 100003 3 UDP 2049 NFS 100003 4 UDP 2049 NFS 100003 2 TCP 2049 NFS 100003 3 TCP 2049 NFS 100003 4 TCP 2049 NFS
Furthermore, before we start exporting and mounting NFS directories, your system needs to actually support network file Sy Stem. To check the whether your system supports NFS Grep/proc/filesystems and search for NFS.
# Cat/proc/filesystems | grep nfsnodev Nfsnodev nfs4
If you don't see any output it means this NFS is not supported or the NFS module has not been loaded into your kernel. To load NFS module execute:
# modprobe NFS
When installed correctly, the NFS daemon should is now listening on both UDP and TCP 2049 ports and Portmap should be Waiti ng for instructions on a port 111.
At the should has portmap listening on both NFS Server and NFS client:
Rpcinfo-p | grep portmap 100000 2 TCP 111 portmapper 100000 2 UDP 111 portmapper
4. Server Export File
All directories we want to share through the network using NFS need to being defined on the server side of this communication an D more specifically they need to be defind with/etc/exports file. The next section, you'll see most common NFS exports:
4.1. Most common exports options
Here is the most common NFS export techniques and options:
/home/nfs/10.1.1.55 (Rw,sync) |
Export/home/nfs directory for host with a IP address 10.1.1.55 with read, write permissions, and synchronized mode |
/HOME/NFS/10.1.1.0/24 (Ro,sync) |
Export/home/nfs directory for network 10.1.1.0 with netmask 255.255.255.0 with Read only permissions and synchronized mod E |
/home/nfs/10.1.1.55 (Rw,sync) 10.1.1.10 (Ro,sync) |
Export/home/nfs directory for host with IP 10.1.1.55with read, write permissions, synchronized mode, and also Export/hom E/nfs directory for another host with a IP address 10.1.1.10 with Read only permissions and synchronized mode |
/home/nfs/10.1.1.55 (Rw,sync,no_root_squash) |
Export/home/nfs directory for host with a IP address 10.1.1.55with read, write permissions, synchronized mode and the RE Mote root user would be treated as a root and would be able to the change any file and directory. |
/home/nfs/* (Ro,sync) |
Export/home/nfs directory for any host with Read only permissions and synchronized mode |
/home/nfs/*.linuxcareer.com (Ro,sync) |
Export/home/nfs directory for any host within linuxconfig.org domain with a read only permission and synchronized mode |
/home/nfs/foobar (Rw,sync) |
Export/home/nfs directory for hostname foobar with read, write permissions and synchronized mode |
4.2. Edit exports file
Now, we have familiarized our selfs with some NFS ' s export options we can define our first NFS export. Open up your favorite text editor, for example, vim and Edit/etc/exports file by adding a line/home/nfs/* (Ro,sync) whic H would export/home/nfs directory for any host with read-only permissions. Instead of text Editor you can simply insert your NFS export line into/etc/exports file using echo command:
# echo '/home/nfs/* (ro,sync) ' >/etc/exports # tail-1/etc/exports/home/nfs/* (Ro,sync)
Be sure this directory is about-to-export by NFS exists. You can also create a file inside The/home/nfs directory which would help you troubleshoot once you Mount/home/nfs/remot Ely.
# Touch/home/nfs/nfs-test-file
Note: The default behavior of NFS kernel daemon is for include additional option to your export line which is "No_subtree_check". Is aware of this fact when you attempt to configure your NFS exports further.
4.3. Restart NFS Daemon
Once You has edited/etc/exports file you need to restart your NFS daemon to apply any changes. Depending on your Linux distribution The restarting procedure for NFS may differ. Ubuntu and Debian Users:
Redhat and Fedora users
If you later decide to add more NFS exports to The/etc/exports file, you'll need to either restart NFS daemon or run Co Mmand Exportfs:
5. Mount remote File system on client
First we need to create a mount point:
If You is sure that the NFS client and mount point is ready, you can run the Mount command to mount exported NFS remote File system:
In the case, you need to specify a filesystem type of you can does this by:
Also get and an error message:
This may mean the your server supports higher NFS version and therefore you need to pass one extra argument to your NFS C Lient mount command. In the example we use NFS version 3:
In should is able to access a REMOTE/HOME/NFS directory locally on your NFS client.
# ls/home/nfs_local/nfs-test-file# cd/home/nfs_local/# lsnfs-test-file# Touch testtouch:cannot Touch ' test ': Read-only File system
The above output proves that a remote NFS export is mounted and so we can access it by navigating to a local/home/nfs_l Ocal/directory. Please notice this touch command reports that the filesystem is mounted as read-only which were exactly our intention.
How to configure NFS on Linux