Linux Tactic

Navigating NFS Ports and Services: A Guide to File Sharing

Introduction to NFS

Network File System (NFS) is a protocol that enables file sharing between different operating systems over a network. It allows you to access files and directories shared by other network users, regardless of what operating system or architecture they are using.

NFS is widely used in enterprise environments to facilitate collaboration and improve productivity. In this article, we will explore the basics of NFS and its comparison with Samba, along with key aspects of NFS ports.

Comparison of NFS with Samba

Samba and NFS are both file sharing protocols with their unique features. NFS is mostly used in Unix-like environments, while Samba is used in Windows environments.

Unlike Samba, NFS does not support encryption for data transfers, making it a less secure option. However, NFS supports various authentication methods, such as Kerberos, that provides secure and reliable authentication.

NFS also offers better performance than Samba in terms of file sharing speed and low latency.

Understanding NFS Ports

NFS has three versions, including NFS v2, NFS v3, and NFS v4. Each version has specific port requirements for different components.

NFS v2 and NFS v3 mostly use portmapper on the server, which assigns dynamic ports to the other components such as mountd, nfsd, lockd, and statd to listen and communicate. In contrast, NFS v4 uses TCP for communicating with the client and, therefore, requires explicit port numbers for each component.

NFS v4 server requires port 2049 and supports minor version 1 with an alternate port of 2051. In comparison, mountd, lockd, statd, and rpc-bind require port 20048, 20049, 20050, and 111, respectively.

Additionally, NFS v4.1 has incremental features like P.NFS (Parallel NFS), which is a new technology that delivers increased scalability and throughput.

Differences between NFS v3 and NFS v4

NFS v3 and NFS v4 are different in a variety of aspects, ranging from protocol changes to transport protocol, permission handling, personality, and semantics. Firstly, NFS v4 supports both TCP and UDP while NFS v3 only supports UDP.

TCP is more reliable than UDP when transferring data over a network since it handles packet losses more effectively. Secondly, permission handling in NFS v4 is more nuanced than in NFS v3, allowing users to define permission for specific files or directories.

NFS v4 supports advanced file attributes while NFS v3 does not. Thirdly, NFS v4 supports multiple authentication methods such as Kerberos and SPKM, while NFS v3 has a weaker authentication mechanism with only two options.

In terms of personality, NFS v4 is more flexible than NFS v3. It supports a broader range of architectures, allowing clients not to require the same architecture as servers.

Finally, NFS v4 semantics are more expressive than in NFS v3, providing better support for file locking and share reservations.


In conclusion, NFS is a reliable file-sharing protocol that offers flexibility and better performance than its counterparts. It’s essential to understand NFS ports and the differences between NFS v3 and v4 before implementing it in your network environment.

While NFS v4 offers significant improvements over NFS v3, it’s essential to assess your network requirements adequately before making a decision.

Services Required for NFS v2 and v3

NFS v2 and v3 use the portmap service to manage RPC (Remote Procedure Call) communication between the server and the client. The portmap service listens on port 111 and maps the RPC services to the respective static ports defined by the NFS server.

This allows the client to know the port number for contacting the different NFS services on the server. To implement NFS v2 and v3 sharing, we need to configure the following services on the server: portmapper, mountd, nfsd, lockd, and statd.

1. Portmapper

The portmap service listens on the well-known port number 111 and maps the RPC services to the respective port numbers defined by other services.

The NFS server uses the portmapper to allocate a unique and dynamic port number to each NFS client connecting to the server, allowing them to communicate with the correct NFS service. 2.


Mountd service is responsible for handling file system mounting requests and managing the mount table on the server. The mountd service uses a static port, which must be specified in the server’s configuration file.

By default, mountd listens on port 20048. 3.


The nfsd service is the core NFS service responsible for handling file read/write requests from the client. It uses a static port number, which must be defined in the server’s configuration file.

By default, nfsd listens on port 2049. 4.


The lockd service is responsible for managing file locking between NFS clients. When an NFS client requests a read or write, a file lock is placed to prevent other clients from overwriting the file simultaneously.

Lockd service uses a static port which should be defined in the server’s configuration file. By default, lockd listens on port 4045.

5. Statd

The statd service is responsible for managing NFS daemon state information, such as client crashes and server reboots.

It uses a static port number which must be defined in the server’s configuration file. By default, statd listens on port 4050.

Static Port Configuration Options

The static port numbers in NFS v2 and v3 can be configured by editing the /etc/sysconfig/nfs configuration file on the NFS server. The following options can be set to specific port numbers:

– MOUNTD_PORT: sets the static port for mountd service

– STATD_PORT: sets the static port for statd service

– STATD_OUTGOING_PORT: sets the outgoing port for statd service

– LOCKD_TCPPORT: sets the TCP port for lockd service

– LOCKD_UDPPORT: sets the UDP port for lockd service

Quick Recap and Example Config

In summary, to configure NFS v2, v3, and v4 shares, we need to configure the necessary services on the server, define the shared directories in the /etc/exports file, and manage the firewall and SELinux settings on the server. Let’s take a look at an example configuration of NFS server on CentOS 8.

1. Install the NFS server package by running the following command:

$ sudo dnf install nfs-utils


Create a directory to be shared with NFS clients. In this example, we will create a directory /var/nfs/share.

$ sudo mkdir -p /var/nfs/share

3. Configure the shared directories in the /etc/exports file.

In this example, we will allow all clients to access the /var/nfs/share directory. $ sudo nano /etc/exports

/var/nfs/share *(ro,sync,no_subtree_check)

The above line defines the /var/nfs/share directory as read-only.

The options ro (read-only), sync (synchronize), and no_subtree_check are self-explanatory. 4.

Reload the NFS configuration

$ sudo exportfs -a

5. Start the NFS services

$ sudo systemctl start nfs-server rpcbind


Adjust the firewall settings

$ sudo firewall-cmd –add-service=nfs

$ sudo firewall-cmd –add-service=rpc-bind (for NFS v4)

$ sudo firewall-cmd –permanent –add-service=nfs

$ sudo firewall-cmd –reload

7. Adjust the SELinux settings

$ sudo setsebool -P nfs_export_all_rw on


Test the NFS server by connecting from an NFS client. $ sudo mount server:/var/nfs/share /mnt/nfs_share

Command to Check Running Ports using rpcinfo

To check the running ports of NFS services, you can use the rpcinfo command on the server. This command displays information about the RPC services registered on a host.

To check if the NFS services are running on the server, run the following command:

$ sudo rpcinfo -p server

This command will display a list of all the RPC services on the server, along with the port numbers associated with them. In conclusion, understanding the services and port requirements for NFS v2 and v3 is crucial in implementing NFS file sharing.

By following the necessary configuration steps and managing firewall and SELinux settings, you can ensure a smooth operation of NFS shares. In conclusion, NFS is a reliable protocol for sharing files between different operating systems over a network.

We have discussed the necessary services for implementing NFS v2 and v3, including the portmap service, mountd, nfsd, lockd, and statd. It’s essential to understand these requirements and configure them on the server to achieve a smooth operation of NFS shares.

Additionally, we have provided an example configuration for an NFS server on CentOS 8 and a command to check running ports using rpcinfo. By following these steps, organizations can enjoy improved collaboration and productivity through file sharing.

Popular Posts