How to get the list of clients connected to an NFS server within a local network?
You can find connected NFS clients by running the following on the NFS server:
netstat | grep :nfs
NFS works over both UDP and TCP, only open TCP connections will show in netstat
or ss
. Also, as a distributed filesystem, it has (historically) had its fair share of problemsPDF (state, cache, locking, notifications, security — some of which have solutions through extra RPC features, e.g. rpc.statd
).
On a Linux NFS server (see man rpc.mountd
) the client mount/unmount requests are recorded in /var/lib/nfs/rmtab
, just like /etc/mtab
, sothe answer should be:
cat /var/lib/nfs/rmtab
If it's empty, then you either have a problem with rpc.mountd
(so you should check the RPC services running), or all the clients are NFSv4 which doesn't use this feature.
On versions I've checked rmtab
is presented as:
10.1.2.0/24:/path/to/export1:0x000...flags
10.1.2.10:/path/to/export1:0x0000...flags
10.1.2.22:/path/to/export1:0x0000...flags
10.1.2.0/24:/path/to/export2:0x000...flags
10.1.2.22:/path/to/export2:0x0000...flags
10.1.2.99:/path/to/export2:0x0000...flags
i.e., each mount point is listed, followed by the clients using it.
Note the caveat in the man page:
However, this file is mostly ornamental. One, the client can continue to use the file handle even after calling rpc.mountd's UMOUNT procedure. And two, if a client reboots without notifying rpc.mountd, a stale entry will remain in rmtab.
The /proc/fs/nfsd/client
approach (@Vsevolod Gromov's answer) in newer kernels should be better in this respect, but because it only supports NFSv4 clients which should be better behaved.
Since Linux kernel 5.3 you can use special directory called /proc/fs/nfsd/clients
.
You can check Kernel version by uname -r
command
Since netstat
is not always available for it is to be replaced by ss
you also might use
ss -a|grep nfs