NFS: mount, showmount, rpcinfo, nfsstat, exportfs, mountstats, nfsiostat, nfsd (1/2)
NFS (Network File System) lets a server export a folder that clients mount like a local folder; it is the standard way to share files between Unix/Linux machines. Part 1 shows what an NFSv3 mount sends on the network, then rpcinfo, showmount and mount.nfs on Linux, the Windows Client/Server for NFS tools and the macOS showmount and mount_nfs options.
160.1 Why is it used?
- Share home folders, build outputs or media between Linux/Unix servers as if they were local.
- rpcinfo checks which RPC services (rpcbind, mountd, nfs) a server offers and on which ports.
- showmount lists a server's exports and which clients mounted what.
- Where: Linux nfs-utils / nfs-common (mount.nfs, showmount); macOS built in (mount_nfs, showmount, nfsstat); Windows Client for NFS (mount, nfsadmin, nfsstat) and Server for NFS (nfsshare).
160.2 How an NFSv3 mount works
- Lab: Linux client 192.168.180.20, server nfssrv 192.168.180.10 running the userspace unfs3 (unfsd).
- The client asks rpcbind (port 111) which port mountd uses.
- It sends MNT to mountd and receives a file handle for the export.
- All READ/WRITE calls then go to nfsd on 2049 using that file handle.
- In this lab both mountd and nfs answer on 2049.
- Step 1
1.Client -> 192.168.180.10:111: GETPORT MOUNT(100005) V3
- Step 2
2.rpcbind reply: Port 2049
- Step 3
3.Client -> mountd: MNT /srv/nfs
- Step 4
4.MNT Reply: OK + file handle
- Step 5
5.Client -> 192.168.180.10:2049: NFS V3 READ release.txt
NFSv4 skips rpcbind and mountd: everything goes to 2049
- Step 1
1.showmount -e: MOUNT V3 EXPORT call
- Step 2
2.Reply: /srv/nfs 192.168.180.0/24, /srv/build 192.168.180.20
- Step 3
3.showmount -a / -d: MOUNT V3 DUMP call
- Step 4
4.Reply: the list mountd remembered after each MNT (client:/srv/nfs, client:/srv/build)
160.3 Kernel check (no mount in the lab)
- The Docker VM kernel has NFS client and nfsd as modules (not loaded); only sunrpc is loaded.
- mount -t nfs would auto-load the nfs module, so the lab does not mount; mount.nfs options are shown as syntax.
$ uname -r6.18.54.1-microsoft-standard-WSL2$ zcat /proc/config.gz | grep -E ...CONFIG_NFS_FS=mCONFIG_NFS_V3=mCONFIG_NFS_V4=mCONFIG_NFSD=m$ grep -E "^(nfs|...|sunrpc) " /proc/modulessunrpc 610304 1 - Live 0x0000000000000000$ grep nfs /proc/filesystems(no nfs filesystem registered)160.4 rpcinfo -p
- /etc/exports: /srv/nfs read-only for the subnet, /srv/build read-write only for 192.168.180.20.
- Server starts rpcbind and unfsd.
- rpcinfo -p lists programs: 100000 rpcbind (111), 100003 NFS v3 (2049), 100005 mountd (2049).
cat /etc/exports # serverrpcbind -w; unfsd -t -e /etc/exportsrpcinfo -p 192.168.180.10 # client[client]$ rpcinfo -p 192.168.180.10 program vers proto port service 100000 4 tcp 111 100000 2 udp 111 100003 3 tcp 2049 100005 1 tcp 2049 100005 3 tcp 2049160.5 Linux showmount
- -e: export list with allowed clients; --no-headers for scripts.
- showmount host (no flag): clients that mounted; -a: client:folder pairs; -d: only folders.
- The list starts empty; nfs-ls (libnfs) made userspace MNT calls, then the entries appeared.
- ::ffff: prefix comes from unfsd's IPv6 socket (IPv4-mapped address).
- -v version (2.6.4), -h usage.
showmount -e 192.168.180.10showmount --exports --no-headers \ 192.168.180.10nfs-ls nfs://192.168.180.10/srv/nfsnfs-ls nfs://192.168.180.10/srv/buildshowmount -a 192.168.180.10showmount -d 192.168.180.10$ showmount -a 192.168.180.10All mount points on 192.168.180.10:::ffff:192.168.180.20:/srv/build::ffff:192.168.180.20:/srv/nfs$ showmount -d 192.168.180.10Directories on 192.168.180.10:/srv/build/srv/nfs$ showmount -vshowmount for 2.6.4160.6 Linux mount.nfs / mount.nfs4
- mount.nfs is a setuid helper; mount.nfs4 is a symlink to it.
- mount -t nfs calls mount.nfs; -t nfs4 forces NFSv4.
- -r / -w read-only / read-write, -f fake mount, -n no /etc/mtab entry, -s sloppy (ignore unknown options), -o NFS options (vers=4.2,rw,hard; see nfs(5)).
ls -l /sbin/mount.nfs /sbin/mount.nfs4mount.nfs -Vmount.nfs -h# syntax only (NOT run, would load nfs):# mount -t nfs4 192.168.180.10:/srv/nfs /mnt/nfs -o vers=4.2,rw,hard$ mount.nfs -husage: mount.nfs remotetarget dir [-rvVwfnsh] [-o nfsoptions]options: -r Mount file system readonly -v Verbose -V Print version -w Mount file system read-write -f Fake mount, do not actually mount -n Do not update /etc/mtab -s Tolerate sloppy mount options rather than fail -h Print this help nfsoptions Refer to mount.nfs(8) or nfs(5)160.7 Windows: Client for NFS mount
- On the office PC 'where' found no mount/nfsadmin/nfsshare/nfsstat (Client for NFS not installed); only mountvol.exe exists.
- mount mounts a share on a drive letter: \\server\share or server:/share, * picks the first free letter.
- In PowerShell mount is an alias, so use mount.exe from CMD.
- Default mtype is soft; Microsoft recommends hard for server reboots.
C:\> where %windir%\System32:mount nfsadmin nfsshare nfsstatINFO: Could not find files for the given pattern(s).(exit 1)C:\> where %windir%\System32:mount*.exeC:\Windows\System32\mountvol.exemount -o anon \\ServerIP\ShareName Z:mount -o nolock \\ServerIP\ShareName Z:mount -o fileaccess=764 mtype=hard \\ServerIP\ShareName Z:mount -u:alice -p:* server:/share *| Option | Meaning |
|---|---|
| rsize= / wsize= | Buffer in KB (default 32) |
| timeout= | RPC timeout 0.8-60 s (default 0.8) |
| retry= | Soft retries 1-10 (default 1) |
| mtype=soft | hard | Soft times out quickly (default); hard keeps retrying |
| fileaccess=764 | Mode for new files (owner/group/world) |
| anon / nolock | Mount as anonymous / disable locking |
| casesensitive | Case-sensitive lookups |
| sec=sys | krb5 | krb5i | krb5p | No auth / Kerberos / + integrity / + encryption |
| lang= | Encoding: euc-jp, shift-jis, Big5, Ansi... |
160.8 Windows nfsadmin, nfsshare, nfsstat
- nfsadmin server|client [computername] [-u user [-p pass]]: config shows/sets settings; no -p gives a prompt.
- Server: -l lists client locks, -r client|all releases them, start/stop, client groups (creategroup, addmembers, listmembers...).
- Server config: audit and auditlocation, lockperiod, per-protocol transports (TCP+UDP default), enableV3, dotfileshidden, casesensitivelookups, ntfscase.
- Client config: mtype, retry, timeout, protocol, rsize/wsize, fileaccess, perf=default resets.
- nfsshare NAME=drive:path -o rw=hosts ro=hosts root=host anon=yes; nfsshare * /delete removes all.
- nfsstat -c client, -s server, -n NFS, -r RPC, -m mount flags, -z reset (admin).
nfsadmin server confignfsadmin server -r 192.168.1.50nfsadmin server creategroup webhostsnfsadmin client config mtype=hard retry=5nfsshare projects=D:\projects -o rw=web01:webfarm ro=backup01nfsshare projects /deletenfsstat -cnnfsstat -m160.9 macOS showmount and mount_nfs
- showmount -e / -a / -d work like Linux; -A finds NFS servers via Bonjour; -p -3 host pings with the NULL procedure; -6 IPv6 only.
- Use mount -t nfs rather than calling mount_nfs directly.
- Default tries TCP first, then UDP; bg retries in the background; proto=tcp|udp|tcp6|udp6; resvport uses a reserved source port.
- vers=3 / vers=4.1 / vers=4-3 (range, highest first); sec=sys|krb5|krb5i|krb5p.
- Calls hang on a dead server by default: soft / intr make them fail; deadtimeout=60 marks the mount dead.
showmount -e hostshowmount -Ashowmount -p -3 hostmount -t nfs -o vers=3,tcp remotehost:/filesystem /localmountpointmount_nfs -o vers=4-3,sec=krb5p,soft,retrans=5 server:/path ~/mnt/nfsmount_nfs -o bg,retrycnt=5,resvport server:/path ~/mnt/nfs160.10 Comparison: hard vs soft mount
| Point | Hard | Soft |
|---|---|---|
| Server down | Client retries the RPC until the server returns | Returns an error after the retries |
| Application | Waits (hangs) | Gets an I/O error quickly |
| Data safety | Safe: writes complete later | Writes can be left incomplete |
| Use for | Read-write data, databases, builds | Read-only or non-critical data |
160.11 Common mistakes
- Treating showmount -a as live connections: mountd only remembers MNT entries, NFS itself is stateless, so old clients stay listed.
- Thinking an empty -a list means the server is broken: -e shows exports, -a only shows clients that did MNT.
- Using soft mounts for read-write data.
- Firewalls that open only 2049 for NFSv3: rpcbind 111 (and mountd) are also needed.
- Typing mount in PowerShell (an alias) instead of mount.exe.
-rw-r--r-- 1 0 0 14 release.txt$ showmount -a 192.168.180.10All mount points on 192.168.180.10:::ffff:192.168.180.20:/srv/build::ffff:192.168.180.20:/srv/nfs160.12 Interview tips
- NFSv3 mount: rpcbind 111 -> mountd MNT -> file handle -> nfsd 2049. NFSv4 uses only 2049.
- Hard mount = retry until server returns (safe); soft = error after retries (fast, risky).
- showmount -e = exports, -a = MNT history (not reliable for live mounts).
- rpcinfo -p shows program numbers: 100000 rpcbind, 100003 nfs, 100005 mountd.