How to Rename NFS Exports for Client-Side Mount Points


2 views

When configuring NFS shares, the export path shown in showmount -e directly reflects the server's filesystem path. By default, if you export /opt/target, clients will see and mount this exact path. However, NFS provides mechanisms to present different paths to clients.

The key is using the -o nohide and fsid options in your /etc/exports file:

# /etc/exports configuration
/opt/target *(rw,sync,no_subtree_check,fsid=0,no_root_squash)
/target *(rw,sync,no_subtree_check,nohide)

1. First, ensure both directories exist on the server:

sudo mkdir -p /opt/target /target
sudo mount --bind /opt/target /target

2. Add the following line to /etc/fstab to make the bind mount persistent:

/opt/target /target none bind 0 0

After making changes, export the shares and verify:

sudo exportfs -rav
showmount -e localhost

Clients should now see both /target and /opt/target, but can mount using the cleaner /target path.

Remember to:

  • Restrict exports to specific client IPs/subnets
  • Use appropriate squashing options
  • Consider adding secure option for port restrictions

When configuring NFS shares, the exported path on the server directly corresponds to what clients see when running showmount -e. In your case, exporting /opt/target means clients must mount this exact path, which isn't always ideal for maintaining clean filesystem structures.

The most reliable method involves creating a bind mount before exporting. This creates a virtual mapping at your desired path without moving actual data:

# On the NFS server:
sudo mkdir /target
sudo mount --bind /opt/target /target

Add this to /etc/fstab to survive reboots:

/opt/target  /target  none  bind  0  0

Now export the new path in /etc/exports:

/target *(rw,sync,no_subtree_check)

After modifying, always run:

sudo exportfs -ra

For temporary solutions without bind mounts, you can use exportfs with the -o flag:

sudo exportfs -o rw,sync,no_root_squash,fsid=0 *:/opt/target=/target

Note this approach has limitations and isn't persistent across reboots.

Clients can now mount the cleaner path:

mount server:/target /mnt/target

Check the export list on server:

showmount -e localhost

Should display /target instead of /opt/target.

1. Ensure proper permissions on both original and bind-mounted directories

2. The fsid=0 option may be needed when exporting from non-root paths

3. SELinux contexts may need adjustment with chcon

4. For large deployments, consider automounter configurations