We would like to move away from sshfs to nfs.

The last thing holding us back is the fact that rpcbind (which I assume is required for nfs to work) does not allow you to specify the TCP (not UDP) IP that it binds to.

There is the -h flag, but this is only for the UDP ports it opens up. this does not affect the TCP ports, they still open on

Does anyone know how we can secure rpcbind by not exposing it to our public interface?

Or even better, is there a way to use nfs without rpcbind?



The rpcbind is required to map RPC service to network ( read TCP or UDP ) address and port. NFS versions 2 and 3 require an additional service mountd to allow clients to get initial file handle. While nfs has a well know port number 2049, mountd doesn't. IOW, if you want to use NFSv3 you will need to run rpcbind as well (well, there are probably some mount options to tell where mound is running). In opposite to v3, NFSv4 requires only single port 2049 and does not need mountd at all. This makes rpcbind free NFS setup possible. Just be aware, that some (old) clients may still try to talk to rpcbind even for v4.

Now, about rpcbind. Why you want to protect it? If it's not available to clients, then they cant mount? The only reason to protect is to limit number of clients which can do updates. But this is already in place as rpcbind uses unix domain socket and disallow any remote client perform updates. Even on a local host you need to be root for that. If you want to protect from some clients only, then iptables is your friend (or what ever firewall your OS has):

# iptables -A INPUT -s -p tcp --dport 111 -j ACCEPT
# iptables -A INPUT -s -p udp --dport 111 -j ACCEPT
# iptables -A INPUT -p tcp --dport 111 -j DROP
# iptables -A INPUT -p udp --dport 111 -j DROP
  • 2
    "Why you want to protect it? If it's not available to clients, then they cant mount?" Listening on an internal, private network's interface is very different than listening on a public interface. – Ivan Vučica Jan 29 at 22:54

The lookup for the service port is baked into the RPC protocol, so you'd have to do something quite exotic to avoid rpcbind when running NFS.

You could block connections from particular addresses or interfaces using iptables; with tcpwrappers (/etc/hosts.allow, /etc/hosts.deny); or - for the adventurous - with SELinux.

tcpwrappers is available natively if "ldd /sbin/rpcbind" shows a link to libwrap, otherwise you'd need to suppress the usual startup and instead run it out of inetd/xinetd through tcpd. I haven't tried that myself.


For anyone looking for answer in 2019. rpcbind takes -h [IP] option. Add to /etc/sysconfig/(Red Hat, Fedora) or /etc/defaults (Debian, Ubuntu) and you are sorted.

  • 2
    The OP noted that -h only applied to UDP ports, not TCP ports. When did this change? – Michael Hampton Feb 3 at 4:41
  • Also, if you're only using NFSv4 (not NFSv2 or NFSv3), you can use the -H option to rpc.nfsd to bind to one particular IP. For example, in /etc/default/nfs-kernel-server on Debian or Ubuntu: RPCNFSDOPTS="-N 2 -N 3 -H" – Daniel Lo Nigro Jun 27 at 5:52
  • @DanielLoNigro It would be cool if you could extend on that in a dedicated answer as I am struggling to find a solution for this, too. – wedi Nov 24 at 13:52

No need to set up firewall rules anymore. With recents Linux distribution where /etc/hosts.deny/allow are available, you can simply do the following:

echo "portmap:" >> /etc/hosts.allow
echo "rpcbind:" >> /etc/hosts.allow
echo "portmap: ALL" >> /etc/hosts.deny
echo "rpcbind: ALL" >> /etc/hosts.deny

(Assuming is your private network).

Recents versions of NFS uses rpcbind, but older uses portmap, so it will depends on your OS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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