Aliasing NFS export path

3

2

Is there a way to define an alias for a NFS-exported directory directly inside /etc/exports (without using a symlink)?

For example, I want to access this export

/home/username/nfsdir 192.168.0.100(rw,sync,no_root_squash)

as `"hostname:/myalias" instead of "hostname:/home/username/nfsdir".

AndiDog

Posted 2010-02-08T08:11:13.487

Reputation: 438

Answers

2

You could use mount -t bind to create the "alias". ie

mount -t bind /home/username/nfsdir /myalias

and then export /myalias.

To make this permanent, add the following line to your /etc/fstab

/home/username/nfsdir /myalias bind bind 0 0

Convict

Posted 2010-02-08T08:11:13.487

Reputation: 694

3Right, but that is the same as creating a symlink. I'm searching for a way to do this using the /etc/exports file only. Something like the share names in Windows/Samba, which are mapped to real paths. – AndiDog – 2010-02-08T11:56:19.250

Which OS is your nfs server running? It appears that some nfs servers support a "refer" option which may do what you want. See "man exports" on your nfs server to see if it supports "refer". – Convict – 2010-02-08T12:45:34.483

It's a minimal Debian lenny. Thanks for the suggestion, I'll try that asap. – AndiDog – 2010-02-08T13:13:06.477

Tried /myalias 192.168.139.0/24(rw,sync,no_root_squash,refer=/real/directory@192.168.39.129) (.129 being the NFS server itself) with no success. It keeps showing me the empty directory /myalias instead of "forwarding" me to the files in /real/path. Can you give me a working example config? (note: I tried it with and without mount --bind /real/directory /real/directory as described in the man page) – AndiDog – 2010-02-08T15:22:19.770

Sorry, I haven't used the refer option before. :-( I saw it there and thought it might be useful to you. – Convict – 2010-02-09T01:31:23.047

I have a feeling that you can't do what you want from within /etc/exports. However, I can see how to achieve the result you're looking for using NFSv4 and mount -t bind. If you're interested, I can show you my NFSv4 configuration. – Convict – 2010-02-09T10:04:11.180

@Convict Yes, append it into your answer – Eugen Konkov – 2017-01-07T23:29:48.587