How to use NFS with IP address and hostname mapping?

Published on Aug. 22, 2023, 12:20 p.m.

To use NFS with IP address and hostname mapping, you can create a name-mapping rule on the NFS server that maps the IP address of the client machine to its hostname, and vice versa. Here are the general steps:

  1. Edit the /etc/idmapd.conf file on the NFS server.
  2. Add the following lines:
[Mapping]
Nobody-User = nobody
Nobody-Group = nobody
[Translation]
Method = nsswitch

This sets up the mapping rules.

  1. Map the client machine’s IP address to its hostname, and vice versa, by adding the following lines to the /etc/hosts file:
client_ip_address client_hostname

and

client_hostname client_ip_address

Note that you may need to configure DNS on your network in order to ensure that the hosts file is updated correctly.

  1. Modify the /etc/exports file to use the hostname instead of the IP address in the export line:
/path/to/share client_hostname(rw)
  1. Save the file and restart the NFS service on the server.
  2. On the client machine, mount the NFS share using the hostname instead of the IP address:
sudo mount -t nfs server_hostname:/path/to/share /mnt/nfs

This will mount the NFS share using the hostname mapping rule that you specified on the server.

Tags:

nfs