
nfsd Command in Linux
The nfsd command in Unix and Linux is used to manage the NFS (Network File System) server. nfsd stands for NFS Daemon, which is responsible for handling requests from NFS clients.
- nfsd allows remote hosts to mount file systems over a network and interact with them as though they are mounted locally. The daemon interacts with the kernel module, which handles the lower-level operations.
- The nfsd is a user-level program that is part of the Network File System (NFS) service. It operates in the user space, which is the area where regular user processes run. Its main job is to start the NFS server processes. Specifically, it kicks off the required number of kernel threads that do the actual work of handling NFS requests.
- o is a part of the operating system kernel. Kernel modules operate in kernel space, which has higher privileges and can perform more critical operations than user space. The nfsd.o module handles the core functionality of NFS. It manages the actual data operations like reading and writing files on behalf of NFS clients.
rpc.mountd provides an additional (ancillary) service that helps with mounting file systems over NFS. When a client tries to mount an NFS share, rpc.mountd steps in to check access permissions and help set up the mount request.
Table of Contents
Here is a comprehensive guide to the options available with the nfsd command −
Syntax of nfsd command
The following is the general syntax for the nfsd command −
/usr/sbin/rpc.nfsd [options] nproc
nfsd command Options
The following is a list of different options that give you control over how the NFS server handles connections and manages its resources, allowing you to tailor it to your specific network and performance needs.
Options | Description |
---|---|
-H or --host hostname |
This option lets you specify a particular hostname or IP address that the NFS server will accept requests on. Without this option, rpc.nfsd will accept NFS requests on all known network addresses. The lockd service, which handles file locking for NFS, may still accept requests on all known network addresses regardless of this setting. This behavior might change in future Linux kernel releases. |
-p or --port port | This option allows you to specify a different port number for the NFS server to listen on. By default, rpc.nfsd listens on port 2049 |
-N or --no-nfs-version vers | This option can be used to request that rpc.nfsd does not offer certain versions of NFS. The current version of rpc.nfsd can support both NFS version 2,3 and the newer version 4. |
-T or --no-tcp | This option disables rpc.nfsd from accepting TCP connections from NFS clients. |
-U or --no-udp | This option disables rpc.nfsd from accepting UDP connections from NFS clients. |
nproc |
Specify the number of NFS server threads. By default, just one thread is started. However, for optimum performance several threads should be used. The actual figure depends on the number of and the work load created by the NFS clients, but a useful starting point is 8 threads. Effects of modifying that number can be checked using the nfsstat(8) program. |
Examples of nfsd Command in Linux
The following practical examples showcase how you can use the nfsd command with various options to configure the NFS server according to your needs.
Start NFS Daemon with 8 Threads
To start NFS daemon with 8 threads, you can run the following command −
sudo /usr/sbin/rpc.nfsd 8
This command starts the NFS daemon with 8 kernel threads, which allows it to handle multiple client requests simultaneously, improving performance.

Start NFS Daemon Listening on a Specific Hostname/IP Address
By default, rpc.nfsd listens on all network addresses. However, by specifying an IP address, you can restrict the server to listen only on the specified IP address.
In environments where network segmentation is crucial for security or organizational reasons, specifying an IP address ensures that only clients from a specific network can communicate with the NFS server.
In addition, limiting the NFS daemon to listen on a particular IP address can help reduce the attack surface by ensuring that only trusted network interfaces can handle NFS traffic.
To start NFS Daemon listening on a specific hostname/IP address, you can simply run the following command −
sudo /usr/sbin/rpc.nfsd -H 192.168.43.94 8
This command configures the NFS daemon to accept requests only on the IP address 192.168.43.94.

Start NFS Daemon on a Different Port
By default, NFS uses port 2049. However, you might want to change this for various reasons, such as avoiding conflicts with other services or adhering to network policies.
Imagine you're setting up an NFS server in a complex network where a firewall blocks the default port 2049 or is already being used by another application.
By configuring rpc.nfsd to listen on a different port, you ensure that NFS traffic is correctly routed and handled, avoiding any conflicts or firewall rules that might block the default port.
To start the NFS daemon on a different port, you can run the following command −
sudo /usr/sbin/rpc.nfsd -p 2050 8
This command sets the NFS daemon to listen on port 2050 instead of the default port 2049.

Check Supported NFS Versions
NFS version 2 is older and lacks many of the security improvements found in later versions. Later versions of NFS (like versions 3 and 4) provide better performance optimizations and additional features, such as improved error handling and more efficient data transfer methods.
To see which NFS versions are supported on your system, you can run the following command −
sudo cat /proc/fs/nfsd/versions
This command lists the supported versions, with positive numbers indicating enabled versions.

Disable TCP Connections
While TCP provides reliable connection-oriented service, UDP can be faster due to its connectionless nature, though it might be less reliable.
For certain applications where speed is more critical and occasional packet loss is acceptable, disabling TCP might be beneficial.
By disabling TCP connections for NFS and using UDP, you can potentially reduce overhead and increase transfer speeds, fitting well within your network's constraints.
To disable TCP connections, you can run the following command −
sudo /usr/sbin/rpc.nfsd -T 8
This command configures the NFS daemon to accept only UDP connections by disabling TCP connections.

Disable UDP Connections
TCP is a connection-oriented protocol that ensures reliable data transfer through error checking and data retransmission. By disabling UDP, you ensure that all NFS communications are handled using the more reliable TCP protocol.
For applications where data integrity is critical, using TCP can help prevent data loss and corruption, which might occur with the connectionless nature of UDP.
To disable UDP connections, you can run the following command −
sudo /usr/sbin/rpc.nfsd -U 8

Conclusion
The nfsd command is a vital tool in managing the NFS server on Unix and Linux systems. By enabling remote file system access over a network, it facilitates seamless file sharing across machines.
The command provides various options to fine-tune the server's behavior, from adjusting the number of threads for handling client requests to specifying network interfaces, ports, and protocol preferences.
By mastering the nfsd command, you can ensure efficient and secure operation of NFS servers, making them indispensable for networked file system management.