Network File System formally knows as NFS is a distributed files system protocol, which allow a linux server to share directories and files with the linux clients over the network. With NFS, users and program can access files on remote systems as if they were stored locally.
NFS was developed by SUN MicroSystems in 1984, and there has been many version’s released for it.
- Version 1 of NFS was only released in development phase for doing in-house experiment purpose.
- NFSv2 supports only 32 bit.
- File size limitation in NFSv2 is only 2GB i.e. only first 2 GB of a file is readable.
- NFSv2 operated only over UDP network.
- NFSv3 supports 64 bit file system.
- NFSv3 can handle files larger than 2 GB.
- NFSv3 supports asynchronous writes on the server. asynchronous writes improve write performance.
- NFSv3 supports additional file attributes in many replies, to avoid the need to re-fetch them.
- NFSv3 supports READDIRPLUS operation. READDIRPLUS operation get file handles and attributes along with file names when scanning a directory.
- NFSv3 supports TCP. Using TCP as a transport made NFS over a WAN more feasible.
- NFSv4 retains all NFSv3 advantages.
- NFSv4 supports ACLs.
- NFSv4 uses the virtual file system to present the server’s export.
- NFSv4 supports Pseudo file system. Pseudo File System provide maximum flexibility. Exports Pathname on servers can be changed transparently to clients.
- NFSv4 have locking operations as the part of protocol which keep track of open files and delegations.
- NFSv4 works through firewalls and on the Internet.
NFS architecture consists of a server and one or many clients. The clients remotely accesses the data that is stored on the server machine. In order for this to function properly, a few processes have to be configured and running.
These daemons must be running on the server:
- nfsd : The NFS daemon which services requests from NFS clients.
- mountd : The NFS mount daemon which carries out requests received from nfsd.
- rpcbind : This deamon allow NFS clients to discover which port the NFS Server is using.
In this blog we will configure the NFS Server on RHEL 6 machine and access the same through any linux client ( in this blog we will be using RHEL ).
First we need to install necessary RPM’s on the server machine. There are mainly two rpm’s required for the NFS Server.
- nfs-utils : Main RPM which provides the nfsd daemon.
- rpcbind : NFS service doesn’t have a designated TCP/IP port to work with. It depends on REMOTE PROCEDURE CALLS(rpc) to route requests between clients and servers.
Check whether the packages are already installed on your server or not. If not installed, install the same with rpm or yum command ( See here for RPM and YUM package management ) :
[root@ap2v ~]# rpm -qa | grep rpcbind rpcbind-0.2.0-9.el6.x86_64 [root@ap2v ~]# rpm -qa | grep nfs-utils nfs-utils-1.2.3-26.el6.x86_64 nfs-utils-lib-1.1.5-4.el6.x86_64 [root@ap2v ~]#
Follow the steps in above link to install the packages in your machine if not installed already. Mentioned below are some services associated with NFS and will be available /etc/init.d directory:
1. /etc/init.d/nfs Controller script for NFS Daemon
2. /etc/init.d/nfslock Script used for locking and providing status of files currently used or accessed.
3. /etc/init.d/rpcbind Controller script to provide dynamic ports to RPC services.
4. /etc/init.d/rpcgssd Script for RPC-related security services.
5. /etc/init.d/rpcidmapd Scripting for mapping NFS with centralized authentication servers like LDAP & Kerberos
6. /etc/init.d/rpcsvcgssd Control Script for managing server side security for RPC services.
Configure NFS Server
Now when you have the required packages installed in the machine, it’s time to configure NFS server for sharing files & directories.
On Server machine, create the directory to share:
[root@ap2v ~]# mkdir /shared_data [root@ap2v ~]#
The configuration file for NFS is /etc/exports which contains the entry for share’s available for clients. The share entry exists in the files should have following syntax:
[shared_dir] [clients_list][ Permissions/Options] [root@ap2v ~]# cat /etc/exports /shared_data *(ro,sync) [root@ap2v ~]#
Note: There is no space between client and permission/options parameters. If you include a space, you will receive syntax error.
There are many mount options available with NFS which you can search and understand using man pages for “exports”, some commonly used ones are explained below:
1. ro Read-Only Permissions on shared directory 2. rw Both Read and Write Permissions on shared directory. 3. Root_squash Denies root access on NFS Share on NFS Server, Used by default 4. sync All changes must be written to disk before a command completes.
There are also more than one method to define the client_list who will be able to access the nfs share.
Some of them is explained below :
- you can use the hostname for hosts within your domain.
- you need fully qualified domain name for outside hosts.
- you can reference all the hosts within a specific domain.
- You can use the * for the host segment, followed by the domain name for the network, such as *.example.com for all the hosts in the example.com network.
- Instead of host name, You can also use single host’s ip address.
- you can use IP network addresses with a CNDR format
- You can also use an NIS netgroup name to reference a collection of hosts. The NIS netgroup name is preceded by an @ sign.
For example following are the valid example for hosts entries
Directory client_lists( Mount options ) /shared_data *(rw,sync) /shared_data *.ap2v.com(rw,sync) /shared_data 192.168.1.10(rw,sync) /shared_data 192.168.1.0/255.255.255.0(rw,sync) /shared_data 192.168.1.0/24(rw,sync) /shared_data @netgroup(rw,sync)
Now that you have configured a Shared_folder via nfs, it’s time to start the nfs service to make this share available to the desired clients.
You can use either service command or can start the service by going into init.d directory in etc.
Make sure you start the rpcbind service first to make your nfs service work properly
[root@ap2v ~]# service rpcbind start Starting rpcbind: [ OK ] [root@ap2v ~]# service nfs start Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Stopping RPC idmapd: [ OK ] Starting RPC idmapd: [ OK ] Starting NFS daemon: [ OK ] [root@ap2v ~]#
Once all service started properly, you can check the share list on your NFS Server by using showmount command.
[root@ap2v ~]# showmount -e 192.168.171.134 Export list for 192.168.171.134: /shared_data * [root@ap2v ~]#
There you goo !!!! The NFS Server is successfully created and directory is also shared properly to the desired clients.