Score:2

Make NFS server listen only on a specific interface

ru flag
mat

I am trying to run a NFS server (nfs-kernel-server package) on a Ubuntu 20.04 machine and want to make it only acessible via VPN.

I have set the appropriate IP address in the /etc/exports file and my firewall. Nevertheless, the rpc.mountd daemon is still listening on all interfaces (0.0.0.0 and ::). As a defense-in-depth measurement, I would like to restrict it further to only listen to connections on the VPN-network device.

How can I configure that?

djdomi avatar
za flag
I did not find any way to do so, however maybe you can also see here the similarly question to your one [on stackexchange](https://unix.stackexchange.com/questions/210772/nfs-share-with-custom-interface)
Score:2
cn flag

In Ubuntu 22.04 (and possibly earlier), the way to do this is by dropping a configuration file in /etc/nfs.conf.d/:

# /etc/nfs.conf.d/interfaces.conf
[nfsd]
host=hostname-or-ip-to-listen-on

The nfs.conf(5) man page documents this.

Score:2
gh flag

Ubuntu and Debian have the configuration in

/etc/default/nfs-kernel-server

You can restrict it using

RPCNFSDOPTS="-H 10.0.40.72"
Score:2
cm flag

Quoting nfsd(8):

OPTIONS
       -d  or  --debug
              enable logging of debugging messages

       -H  or  --host hostname
              specify a particular hostname (or address) that NFS requests will be accepted on. By default, rpc.nfsd will accept NFS requests on all known network addresses.  Note that lockd (which performs file locking services for NFS) may still accept request on all known network addresses.  This may change
              in future releases of the Linux Kernel. This option can be used multiple time to listen to more than one interface.

       -p  or  --port port
              specify a different port to listen on for NFS requests. By default, rpc.nfsd will listen on port 2049.
ru flag
mat
Do you also happen to know the configuration while where this can be configured?
de flag
this can be defined in **/etc/nfs.conf** file under `[nfsd]` section
ru flag
mat
Are you sure this is supposed to work in Ubuntu? I found that tip in the Arch-Wiki, too, but it didn't do anything on my machine.
Score:1
bw flag

Neither the configuration in /etc/nfs.conf / /etc/nfs.conf.d/* nor the RPCNFSDOPTS specified in /etc/default/nfs-kernel-server affect the interfaces, on which rpc.mountd will listen on. So none of the other answers here actually answer the original question, which was about restricting access to rpc.mountd to a specific interface.

The man page of rpc.mountd does NOT list an option, that performs the required restriction. Instead, it recommends to use either the tcp_wrapper library or the kernel firewall iptables for that purpose.

However, with most systems having migrated already to NFS protocol version 4, there is an easier solution: NFSv4 does not need rpc.mountd anymore. An explanation how to do that can be found towards the bottom of this page: https://wiki.debian.org/NFSServerSetup

So, to restrict to NFS access to NFSv4 on a local interface, do the following on recent Ubuntu / Debian servers:

systemctl stop nfs-kernel-server.service
systemctl stop rpcbind.service
systemctl mask rpcbind.service
systemctl mask rpcbind.socket

vi /etc/default/nfs-common
    NEED_STATD="no"
    NEED_IDMAPD="yes"

vi /etc/default/nfs-kernel-server
    RPCNFSDOPTS="-H YOUR-LOCAL-IP-YOU-WANT-TO-BIND-TO -N 2 -N 3"
    RPCMOUNTDOPTS="--manage-gids -N 2 -N 3"

systemctl start nfs-kernel-server.service 

Of the four configuration options listed here (NEED_STATD, NEED_IDMAPD, RPCNFSDOPTS and RPCMOUNTDOPTS) you will find only the last one already defined in the default versions of those files as shipped with Debian or Ubuntu. Make sure to edit RPCMOUNTDOPTS apropriately and to add the other three. Of course, you may freely choose another editor instead of vi.

Before masking rpcbind.service with systemctl (which pretends, that it is started, though it is not), make sure, that no other service on your machine needs that it.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.