NFS firewall rules: which ports to open for NFSv3 and NFSv4

Version 1.1.0

Pick your NFS version, which host you're protecting, and your firewall to get the inbound ports to open and the firewalld, ufw, or nftables rules for them.

Have the network your clients connect from, such as 192.168.1.0/24. For NFSv3, also have the helper ports from the server. It runs in your browser and doesn't change any firewall.

NFS version
Protected host
Firewall
Address family

What to enter

Protected host is the machine whose firewall you're changing. Plan the server and the client separately.

The allowed CIDR is the network the other side connects from. Keep it as small as you can, such as your home network instead of 0.0.0.0/0.

For firewalld, enter the zone your network interface is in. firewall-cmd --get-active-zones shows it.

Why NFSv3 asks for verified ports

NFSv3 helpers such as mountd, statd, and lockd pick ports when they start, unless you pin them. On the server, run rpcinfo -p to see the ports in use, and enter only those. Until you do, the planner shows the fixed ports and lists what's missing, without firewall commands.

NFSv4.1 server with ufw

Example

NFS version NFSv4.1+, protected host NFS server, firewall UFW, allowed client CIDR 192.168.1.0/24.

The result is Allow 1 listener rule on the NFS server. The command is:

bash
ufw allow in proto tcp from 192.168.1.0/24 to any port 2049 comment 'NFS nfs'

Which ports does NFS need?

It depends on the version. NFSv4 needs one port, and NFSv3 needs several.

SetupOpen on the serverOpen on the client
NFSv4.1 or laterTCP 2049Nothing new
NFSv4.0TCP 2049The callback port
NFSv3TCP 111 and 2049, plus mountd, statd, and lockdTCP 111, plus statd and lockd

NFSv4 uses the registered port 2049, so clients don't need the RPC port mapper on 111. RFC 7530 explains why that lets NFS cross firewalls.

Should I use NFSv3 or NFSv4 through a firewall?

Use NFSv4.1 or later when both sides support it. It's one TCP port on the server and nothing on the client. In NFSv4.1, the server sends callbacks over the connection the client already opened, as RFC 8881 describes.

NFSv4.0 is the odd one out. The server opens a new connection back to the client for callbacks, so the client needs an open port too.

How do I pin the NFSv3 ports?

Set fixed ports in /etc/nfs.conf on the host, then restart the NFS services. Without this, the ports can change after a reboot and your rules stop matching.

ini
[mountd]
port = 20048

[statd]
port = 662

[lockd]
port = 32803
udp-port = 32769

These numbers are only examples. Pick free ports, then check them with rpcinfo -p. The nfs.conf manual lists the keys for each section.

Why don't my firewalld rules work?

Rules added with --permanent change only the saved config. They take effect after firewall-cmd --reload or a restart, as the firewall-cmd manual says.

Also check the zone. A rule in public does nothing if your interface is in another zone.

My firewall is open but the mount still fails. What now?

Test from the client with mount -t nfs -o vers=4.1 server:/export /mnt, then findmnt to see the version it used. Change vers=4.1 to vers=3 for an NFSv3 setup.

access denied comes from the export, not the firewall. Check /etc/exports on the server and that the client's address is allowed.

If the mount works but files show the wrong owner, the user IDs differ between client and server. If the share goes into an LXC container, the LXC ID mapping checker shows how container IDs map to the host.