The official documentation for creating an NFS /etc/exports file for multiple networks and FSIDs is unclear and confusing. Here’s what you need to know.
If you need to specify multiple subnets that are allowed to mount a volume, you can either use separate lines in /etc/exports, like so:
/opt/dir1 192.168.1.0/24(rw,sync) /opt/dir1 10.10.0.0/22(rw,sync)
Or you can list each subnet on a single line, repeating all of the mount options for each subnet, like so:
/opt/dir1 192.168.1.0/24(rw,sync) 10.10.0.0/22(rw,sync)
These are both equivalent. They will allow clients in the
10.10.0.0/22 subnets to mount the
/opt/dir1 directory via NFS. A client in a different subnet will not be able to mount the filesystem.
When I’m setting up NFS servers I like to assign each exported volume with a unique FSID. If you don’t use FSID, there is a chance that when you reboot your NFS server the way that the server identifies the volume will change between reboots, and your NFS clients will hang with “stale file handle” errors. I say “a chance” because it depends on how your server stores volumes, what version of NFS it’s running, and if it’s a fault tolerant / high availability server, how that HA ability was implemented. Using a unique FSID ensures that the volume that the server presents is always identified the same way, and it makes it easier for NFS clients to reconnect and resume operations after an NFS server gets rebooted.
If you are using FSID to define a unique filesystem ID for each mount point you must include the same FSID in the export options for a single volume. It’s the “file system identifier”, so it needs to be the same each time a single filesystem is exported. If I want to identify
fsid=1 I have to include that declaration in the options every time that filesystem is exported. So for the examples above:
/opt/dir1 192.168.1.0/24(rw,sync,fsid=1) /opt/dir1 10.10.0.0/22(rw,sync,fsid=1)
/opt/dir1 192.168.1.0/24(rw,sync,fsid=1) 10.10.0.0/22(rw,sync,fsid=1)
If you use a different FSID for one of these entries, or if you declare the FSID for one subnet and not the other, your NFS server will slowly and mysteriously grind to a halt, sometimes over hours and sometimes over days.
For NFSv4, there is the concept of a “distinguished filesystem” which is the root of all exported filesystems. This is specified with
fsid=0, which both mean exactly the same thing. Unless you have a good reason to create a distinguished filesystem don’t use
fsid=0, it will just add unnecessary complexity to your NFS setup.
Hope you find this useful.