I was looking for a simple and easy way to view the NFS Clients connected to my NFS Server, there’s many guides on how to view the mounts available and people say to run various client side commands but that doesn’t help for the opposite way.
This is a little Linux bash script to show the currently connected NFS clients to your server; it uses a dig lookup to get the hostname, which may not work if you dont have rDNS for internal addressing.
#!/bin/bash # A little bash script to show currently connected NFS clients. # Adam Boutcher - Jul 2020 # IPPP, Durham University # Function to check that a binary exists function check_bin() { which $1 1>/dev/null 2>&1 if [[ $? -ne 0 ]]; then echo "$1 cannot be found. Please install it or add it to the path. Exiting." exit 1 fi } check_bin which check_bin netstat check_bin grep check_bin awk check_bin echo check_bin dig NCLIENTS=$(netstat -plna | grep 2049 | awk '{print $5}' | grep -v "*" | awk -F ":" '{print $1}') echo "" echo "NFS clients currently connected:" for CLIENT in ${NCLIENTS}; do CNAME=$(dig +short -x $CLIENT); echo - $CLIENT ($CNAME) done echo "" exit 0;
There are other tools available like nfstat to help show other NFS information, specifically for servers use:
nfsatst -s