How to check if an NFS share is mounted in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to verify if an NFS (Network File System) share is successfully mounted on your Linux system. You will explore three common methods to achieve this.

First, you will use the mount command to list all currently mounted filesystems and identify any NFS entries. Next, you will examine the /etc/fstab file to check for persistent NFS mount configurations. Finally, you will utilize the showmount -e command to verify the NFS server and its exported directories. By completing these steps, you will gain practical skills in diagnosing NFS mount status on Linux.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/FileandDirectoryManagementGroup(["File and Directory Management"]) linux(("Linux")) -.-> linux/SystemInformationandMonitoringGroup(["System Information and Monitoring"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/FileandDirectoryManagementGroup -.-> linux/cd("Directory Changing") linux/SystemInformationandMonitoringGroup -.-> linux/mount("File System Mounting") subgraph Lab Skills linux/cat -.-> lab-558784{{"How to check if an NFS share is mounted in Linux"}} linux/cd -.-> lab-558784{{"How to check if an NFS share is mounted in Linux"}} linux/mount -.-> lab-558784{{"How to check if an NFS share is mounted in Linux"}} end

List NFS mounts with mount

In this step, you will learn how to identify Network File System (NFS) mounts on your Linux system using the mount command. NFS allows a system to share directories and files with others over a network.

The mount command is used to attach filesystems to a specific mount point in the file system hierarchy. When used without any arguments, it displays a list of all currently mounted filesystems, including NFS mounts.

Open your terminal. You are likely already in the ~/project directory.

Type the following command and press Enter:

mount

This command will output a lot of information about all the filesystems currently mounted on your system. Look for lines that include type nfs or mention a remote server path followed by a local mount point.

For example, you might see output similar to this (the exact output will vary depending on the system configuration):

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
udev on /dev type devtmpfs (rw,nosuid,relatime,size=999999k,nr_inodes=999999,mode=755,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,noexec,relatime,size=999999k,mode=755)
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
tmpfs on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,relatime,size=999999k,mode=755)
cgroup2 on /sys/fs/cgroup/unified type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate)
...
192.168.1.100:/shared_nfs on /mnt/nfs_share type nfs4 (rw,relatime,vers=4.2,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.200,local_lock=none,addr=192.168.1.100)
...

In the example output above, the line starting with 192.168.1.100:/shared_nfs indicates an NFS mount.

  • 192.168.1.100:/shared_nfs is the remote NFS server and the shared directory on that server.
  • /mnt/nfs_share is the local mount point on your system where the remote directory is accessible.
  • type nfs4 confirms it is an NFS version 4 mount.

By examining the output of the mount command, you can identify if any NFS shares are currently mounted on your system and where they are mounted.

Click Continue to proceed.

Check NFS in /etc/fstab

In the previous step, you learned how to see currently mounted filesystems using the mount command. However, the mount command only shows what is currently mounted. To see filesystems that are configured to be mounted automatically at boot time, you need to check the /etc/fstab file.

The /etc/fstab file (filesystem table) is a configuration file that contains information about various filesystems and how they should be mounted. This includes local filesystems, swap partitions, and network filesystems like NFS.

You can view the contents of this file using a command-line text viewer like cat or less, or a text editor like nano. Let's use cat to display the file's content directly in the terminal.

Make sure you are in the ~/project directory.

Type the following command and press Enter:

cat /etc/fstab

This command will print the entire content of the /etc/fstab file to your terminal.

You will see lines describing different filesystems. Each line typically follows a specific format:

<file system> <mount point> <type> <options> <dump> <pass>

Look for lines where the <type> field is nfs or nfs4. These lines indicate NFS shares that are configured to be mounted automatically.

For example, a line configuring an NFS mount might look like this:

192.168.1.100:/shared_nfs /mnt/nfs_share nfs defaults 0 0
  • 192.168.1.100:/shared_nfs: The remote NFS server and shared directory.
  • /mnt/nfs_share: The local mount point.
  • nfs: The filesystem type (NFS).
  • defaults: Standard mount options (like rw, suid, dev, exec, auto, nouser, async).
  • 0: The dump option (usually 0 for NFS).
  • 0: The pass option (usually 0 for NFS, meaning no filesystem check at boot).

By examining /etc/fstab, you can determine which NFS shares are configured for automatic mounting, even if they are not currently mounted.

Click Continue to move to the next step.

Verify NFS server with showmount -e

In the previous steps, you learned how to identify currently mounted NFS shares using mount and how to check for automatically configured NFS mounts in /etc/fstab. Now, let's verify what directories an NFS server is exporting (making available) for clients to mount.

The showmount command is a client-side tool that queries the mount daemon on a remote host to show the NFS shares exported by that host. The -e option tells showmount to show the host's export list.

To use showmount, you need to specify the hostname or IP address of the NFS server. For this lab, we will assume there is an NFS server available at the IP address 192.168.1.100.

Make sure you are in the ~/project directory.

Type the following command, replacing 192.168.1.100 with the actual IP address or hostname of the NFS server you want to check, and press Enter:

showmount -e 192.168.1.100

If the command is successful and the server is exporting shares, you will see output similar to this:

Export list for 192.168.1.100:
/shared_nfs *
/another_share 192.168.1.0/24
  • The first column lists the directories being exported from the NFS server.
  • The second column indicates which clients are allowed to mount that directory. * means any client can mount it. An IP address or network range (like 192.168.1.0/24) restricts access to specific clients.

If the command fails or shows no output, it could mean:

  • The NFS server is not running or is unreachable.
  • The server is not exporting any shares.
  • A firewall is blocking the connection.

Using showmount -e is a crucial step in troubleshooting NFS client issues, as it confirms whether the server is correctly configured to export the desired directories.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check if an NFS share is mounted in Linux. You started by using the mount command to list all currently mounted filesystems and identify any entries of type nfs.

You also explored how to check the /etc/fstab file to see if the NFS share is configured to be mounted automatically at boot time. Finally, you learned how to use the showmount -e command to verify the NFS server and list the directories it is exporting.