NFS, an acronym for Network File System is a distributed file system protocol originally developed by Sun Microsystems. It is one of the most prominent network services using Remote Procedure Call (RPC) to route requests between clients and servers and shares the file system over the network.
NFS refers to a network abstraction over a file system that permits a remote client to access it over a network in the same manner to a local file system.
It happens by a mixture of kernel functionality on the client side and an NFS server on the server side.
The client uses the remote file system, and the NFS server provides the file data. This file access is entirely transparent to the client and works across a variety of server and host architectures.
In this article, we will understand the working of NFS and the associated services. We will also explore in brief about the history of NFS, and how it has evolved.
What is Network File System (NFS)? – Further Explained
NFS is a distributed, client/server file system that allows local users to access remote data and files across a network in the same way they will obtain them locally.
For instance, if you are working on a computer having a connection to a second computer via NFS, you can access files on the second computer as if they are present in a directory on the first computer.
NFS accomplishes this through the processes of exporting and mounting.
Exporting is the process by which an NFS server provides remote clients with access to its files. Mounting is the process by which file systems are made available to the operating system and the user.
What are the different versions of NFS? – Evolution of NFS
Network File System was the first modern network file system built over the IP protocol. It began as an experimental filesystem developed at Sun Microsystems.
Due to the growing popularity, the NFS protocol was documented as a Request for Comments (RFC) specification and evolved into NFSv2.
NFSv2 has been around for several years, is widely supported by various operating systems.
As a standard, NFS became famous due to its capability to interoperate with other clients and servers.
Next came the third version as NFSv3, defined by RFC 1813. Comparatively, this version was much more scalable, supporting large files (larger than 2GB), asynchronous writes, and TCP as the transport protocol.
NFSv3 simply made way for file systems over wide area networks. It is also more robust at error handling than NFSv2.
Today, NFSv4.1 exists as defined by RFC 5661. It adds protocol support for parallel access across distributed servers, i.e., parallel NFS (pNFS) for higher scaling and higher performance.
How does NFS work?
NFS follows the client-server computing model.
The computers that make their file systems, or directories, and other resources available for remote access are called servers. The act of making file systems available is called exporting.
The computers, or the processes they run, that use a server’s resources are considered clients.
NFS transactions are atomic, i.e., a single NFS transaction corresponds to an individual, complete file operation. NFS requires the client to remember any information needed for later NFS use.
The server would execute NFS daemon processes to make data available to clients and ensures it can recognize validated clients.
From the client’s side, the machine requests access to exported data, generally by releasing a mount command. If it is successful, the client machine can then view and communicate with the file systems within the decided parameters.
NFS Services and Processes
NFS relies on Remote Procedure Calls (RPC) to route requests between clients and servers. The portmap service controls RPC services under Linux.
The following services work together to share or mount NFS file systems, depending on the NFS version in use:
nfs starts the NFS server and the appropriate RPC processes to service requests for shared NFS file systems.
nfslock is a mandatory service that starts the appropriate RPC processes to enable NFS clients to lock files on the server.
rpcbind service accepts port reservations from local RPC services and makes them available so that the corresponding remote RPC services access them.
rpcbind answers to requests for RPC services and sets up connections to the requested RPC service. It is not applicable to NFSv4.
The below-mentioned RPC processes enable NFS services.
The rpc.mountd process gets mount requests from NFS clients and verifies the export of the requested file system.
nfs service automatically starts this process as it does not require user configuration. It is not applicable to NFSv4.
The rpc.nfsd process permits explicit NFS versions and protocols, the server advertises to be defined. Working with the Linux kernel, it meets the dynamic demands of NFS clients, like server threads each time an NFS client connects.
The rpc.lockd process allows NFS clients to lock files on the server. If rpc.lockd does not start, file locking fails. It implements the Network Lock Manager (NLM) protocol and corresponds to the nfslock service.
It is not applicable to NSFv4.
rpc.statd process implements the Network Status Monitor (NSM) protocol which notifies NFS clients when an NFS server restarts without being gracefully brought down.
nfslock service automatically starts this process and does not require user configuration.
It is not applicable to NFSv4.
The rpc.rquotad process provides user quota information for remote users. nfs service automatically starts this process and does not require user configuration.
NFS service does not require all of these programs. Only rpc.mountd, rpc.nfsd, and portmap services must be enabled.
The other daemons provide additional functionality, and you can use them if your server environment requires them.
Typical Implementation of Network File System
In the below steps, we will see a typical implementation of the Network File System.
- First, the server implements NFS daemon processes, running by default as nfsd. By this, the server makes its data generically available to clients.
- Next, the server administrator decides what to make available, exporting the names and parameters of directories, typically employing the /etc/exports configuration file and the exportfs command.
- After determining the data, the server security-administration ensures that it can acknowledge and approve validated clients.
- Then, the server network configuration ensures that applicable clients can negotiate with it through any firewall system.
- The client machine issues a mount command to request access to exported data. The client interrogates the server (rpcbind) which port the NFS server is using, the client links to the NFS server (nfsd), and lastly, nfsd passes the request to mountd).
- After successful completion, users on the client machine can then view and interact with mounted filesystems on the server within the parameters permitted.
TCP or UDP – Which protocol is used by NFS?
Network file system works on all IP-based networks. It uses Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) for data access and delivery, depending on the version in use.
NFSv2 employs the UDP providing a stateless network connection between the client and server. NFSv3 can use UDP or TCP running over an IP whereas NFSv4 requires the use of TCP.
Under normal conditions, the stateless UDP connection has less protocol overhead than TCP. It can translate into better performance on very clean, non-congested networks.
However, as UDP is stateless if the server goes down unexpectedly, UDP clients continue to saturate the network with requests for the server.
Also, if a frame gets lost with UDP, the entire RPC request must be retransmitted.
In the case of TCP, only the lost frame has to be resent. Due to these reasons, TCP is the preferred protocol when establishing a connection to an NFS server.
Why is NFS used? What are its advantages?
NFS has many practical uses and offers many useful features. Let’s take a closer look.
One significant advantage that NFS provides is central management.
Data accessed by all users can be made available on a central host, with clients mounting this directory at boot time.
On large networks, configuring a central NFS server on which all user home directories exist is often more convenient.
By this, users can log into a client anywhere on the network and have access to their home directories.
Using a centrally managed server also decreases the workload for the administrator concerning back-ups, adding shared software and computer repair.
Reduce Removable media
Other machines on the network can use removable media storage devices such as floppy disks, CDROM drives, and USB Thumb drives.
It may reduce the number of removable media drives throughout the network by providing a centralized location to control their security.
Installing software on multiple machines from a centralized installation media is often more convenient.
Another advantage of NFS is the granularity that can be used to give access to files. File access can take place via IP addresses, groups, users, etc.
NFS enables for a user to log into any server and have access to their files transparently.
Are there any limitations of NFS?
Probably the most significant disadvantage of using NFS is the issue of security.
As NFS uses RPC, it is inherently insecure, and you should only use it on a trusted network behind a firewall. Although you can take preventive steps to secure NFS, it still will be vulnerable to internet threats.
Also, you will not want a root account to access an exported file system due to the potential damage.
Therefore, the system by default activates “root squashing” to prevent a root account accessing an exported file system. The “root squashing” can be changed, however.
The other disadvantage that may become evident is the performance limitations of the network. NFS will slow down during heavy network traffic
Are there any alternatives to NFS?
Although NFS is one of the widely popular network file systems on UNIX and Linux systems, it is indeed not the only choice.
On Windows systems, Common Internet File System (CIFS) is the most widely used option, though Windows also supports NFS.
Another alternative is Ceph, the latest distributed file systems, also supported in LinuxCeph.
It was created from the ground up as a fault-tolerant distributed file system with Portable Operating System Interface for UNIX (POSIX) compatibility.
Other examples include OpenAFS, GlusterFS and Lustre. All of these are open source software solutions for distributed storage.
The NFS protocol is an open standard defined in Request for Comments (RFC), allowing anyone to implement the protocol.
It permits sharing of a typical file system among a multitude of users and provides the benefit of centralizing data to reduce required storage.
NFS has grown and continues to evolve into the most potent and widely used network file system. It depicts a highly stable and portable networked file system that is scalable, high performing, and enterprise quality.
NFS also supports the latest computing models to optimize virtualized infrastructures. It is designed to be independent of the computer, operating system, network architecture, and transport protocol.
With the increase in network speeds and the decrease in latencies, NFS continues to be a favorable choice for serving a file system over a network.