How to Check NFS Mounts in Linux
Network File System (NFS) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. This can be useful for sharing files and data across machines.
If you have NFS set up on your Linux machines, you may want to check on the status of your NFS mounts to understand what is currently mounted, confirm connectivity, and troubleshoot any issues. Checking NFS mounts in Linux is easy to do with just a few simple commands.
Use the mount
Command
The most straightforward way to check NFS mounts on Linux is by using the mount
command.
To see all mounts, including NFS mounts:
mount
This will display all mounts in the standard mount output format:
nfs-server:/export/directories on /mount/point type nfs (rw,relatime,vers=3,rsize=32768,wsize=32768,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.10,mountvers=3,mountport=20048,mountproto=udp,local_lock=none,addr=192.168.1.10)
The key pieces here are:
nfs-server:/export/directories
- The NFS export on the server/mount/point
- Where the share is mounted locallytype nfs
- Identifies this as an NFS mount
You can also filter mount
output to show only NFS mounts using grep
:
mount | grep nfs
This can help simplify the output and focus only on the NFS mounts.
Use the df
Command
The df
(disk free) command can also display NFS mount information in Linux. The -T
option can be used to specify the filesystem type:
df -T | grep nfs
Much like the filtered mount
output, this will only show filesystems mounted via NFS, verifying your remote shares.
Check Mounts in /etc/mtab
The /etc/mtab
file records mounted filesystems and can be checked manually:
cat /etc/mtab
Here you would again look for shares mounted with nfs
as the filesystem type.
Identify Mount Issues
If you see any issues indicating a mount failure or connectivity problems to the NFS share, there are a few things you can try.
Unmount and remount:
sudo umount /mountpoint
sudo mount /mountpoint
Check NFS server and port connectivity:
telnet nfs-server 2049
Verify NFS exports on the server:
showmount -e nfs-server
Restart the NFS server service if needed.
Be sure to check your network and firewall rules as well if you see persistent mount issues.
Automate with a Monitoring Script
To simplify monitoring your NFS mounts, you can create a script to output status. For example:
#!/bin/bash
SERVER="nfs-server"
MOUNTPOINT="/mountpoint"
if ! mount | grep $MOUNTPOINT > /dev/null; then
echo "$MOUNTPOINT not mounted" >&2
exit 1
fi
if ! showmount -e $SERVER>$MOUNTPOINT; then
echo "$SERVER not responding" >&2
exit 1
fi
echo "$SERVER mounted on $MOUNTPOINT"
This will output an error if the mount directory is not actually mounted or if the NFS server is not reachable, making problems clear. Otherwise, it reports the mount as active.
NFS Mount Tips
Here are some additional tips for working with and checking NFS mounts in Linux:
Check the contents of
/etc/fstab
to see which NFS mounts are configured to mount automatically at boot time.The
findmnt
command can provide output similar tomount
if you prefer an alternate view.After making changes to NFS mounts, always double-check with
df
ormount
to validate the expected status.Monitor free disk space on mounted NFS shares with
df -h
to catch capacity issues before they become problems.Configure test clients to automount shares from a central NFS server to test connectivity before deploying changes across your environment.
Key Advantages of NFS Mounts
There are good reasons to consider using NFS mounts on Linux systems:
File system sharing - Centralize data and access across mixed OS environments.
User transparent access - Access shared directories seamlessly as local mounts.
Easy administration - Add, move, and replicate data easily on the server side.
Read/write support - Mounts support full read and write permissions.
Industry-standard - Backed by a proven, widely adopted protocol.
With proper configuration and occasional monitoring, you can unlock excellent file sharing with your Linux hosts via NFS while keeping tabs on its status.
Summary
NFS mounting provides an easy way to share storage on a network. By mounting network exports to local directories, users can seamlessly access these remote directories as needed.
There are a few simple commands on Linux to check the status of your NFS mounts:
Use
mount
and filter withgrep
to see only NFS mountsCheck
df -T
output for shares mounted with NFSView local mount records in
/etc/mtab
Verify server exports and connectivity to identify issues
Consider writing a script to monitor mounts automatically
NFS can facilitate very convenient centralized file storage for Linux users if monitored closely. Hopefully, these commands give you easy ways to keep an eye on your NFS mounts.
Also read -
How to Check NTP Sync in Linux
Troubleshooting When Kali Linux Network Manager is Not Running