Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

How do I enable NFS mounts/shares with iptables with DROP policy?

NFS uses dynamically assigned ports, thus it is difficult to use with firewalls. I have an NFS server and a few clients. I would like to accept traffic ONLY on ports that are required for NFS to work. I have configured the NFS server to use static ports (4000-4004).

The problem, however, is that the clients still selects a random port -- and because it is UDP I can only make it work if I accept all UDP traffic from the server.

I found some documentation that describes setting a /sys variable that would limit the client to use a static range of ports for NFS, however, I cannot seem to make it work. The /sys variables mentioned are:


I have not been able to make this work. Maybe I am approaching this the wrong way? It seems unnecessarily complicated for what I thought would be a simple task.

I use NFS on Debian and Ubuntu.

share|improve this question
NFS uses port 2049, at least with NFS v3. –  Janne Pikkarainen Jan 10 '12 at 8:42
An NFS server uses multiple ports / port ranges. It's not sufficient to just allow one single port/range. –  basic6 May 24 at 15:26

2 Answers 2

The fact that the client port is ephemeral isn't a problem, though as you say the mutability of the server-side port is.

Assuming you have successfully instructed the server to use only ports 4000-4004 for nfsd, you have three issues: clients must be able to talk to the RPC portmapper, the mount daemon, and the NFS service, on the server.

For the NFS service

Assuming you're right about having modified the NFS service to listen on 4000-4004, clients should add

iptables -A INPUT  -d se.rv.er.ip -p udp --dport 4000:4004 -j ACCEPT
iptables -A OUTPUT -s se.rv.er.ip -p udp --sport 4000:4004 -j ACCEPT

while the server should add

iptables -A INPUT  -p udp --dport 4000:4004 -j ACCEPT
iptables -A OUTPUT -p udp --sport 4000:4004 -j ACCEPT

If you want to permit NFS over TCP, repeat those rules with -p tcp instead of -p udp.

For the portmapper

Clients should add

iptables -A INPUT  -d se.rv.er.ip -p udp --dport 111 -j ACCEPT
iptables -A OUTPUT -s se.rv.er.ip -p udp --sport 111 -j ACCEPT

while the server should add

iptables -A INPUT  -p udp --dport 111 -j ACCEPT
iptables -A OUTPUT -p udp --sport 111 -j ACCEPT

You may need to add pairs of rules for -p tcp as well, as the portmapper usually supports TCP as well. Check your rejection logs to see what's being DROPped and adjust accordingly.

For the mount daemon

You need to find out what port it's running on on the server, with server% rpcinfo -p | grep mount; on my server it's UDP/32775 and TCP/32769. To allow those, clients should add

iptables -A INPUT  -d se.rv.er.ip -p udp --dport 32775 -j ACCEPT
iptables -A OUTPUT -s se.rv.er.ip -p udp --sport 32775 -j ACCEPT

while the server should add

iptables -A INPUT  -p udp --dport 32775 -j ACCEPT
iptables -A OUTPUT -p udp --sport 32775 -j ACCEPT

and two similar pairs with -p tcp --[ds]port 32769.

It is your responsibility to get those lines in the right place in your INPUT and OUTPUT chains; near the beginning is probably a good idea.

Edit: in the light of your answer below, I have updated the rules above.

share|improve this answer
The firewall is running on both the NFS server and the NFS clients. –  ervingsb Jan 10 '12 at 12:02
How to configure those ports (mountd) on Debian: wiki.debian.org/SecuringNFS –  basic6 May 24 at 15:58

I found this page which shows several iptables rules on how to open NFS ports.

Also, this page suggests that you can choose the protocol/port when mounting the NFS share using the command (NFS v4):

# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/data /mnt/data

Several other pages are talking about opening these three ports: 32771, 111 and 2049.

You can try that and if it did not work for you, you can try to open all UDP ports from your clients IPs only given that you trust them and see if it will work.

share|improve this answer
111 is what rpcbind uses by default, 2049 is the default nfsd port, so opening those might be a good start. But 32771 probably belongs to one of the other ports/ranges (on the computer of whoever wrote that page that you found). It wouldn't make much sense to just open that particular port, especially if that's not even used by your NFS server. –  basic6 May 24 at 15:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.