1

I would like to setup a laptop on Linux to use two different autofs config according to the network it is plugged. I have the two working autofs files (see below) and I would like to swap automatically between them.

I have considered tinkering with name resolutions (providing same logical name on two networks) or writing a ifup.d script (check ip or gateway addr, copy the right script and restart autofs). At this time I realized my need is not that exotic (not for autofs files, but for any configuration files) and I wonder if there is existing tools, or best practice, to achieve this kind of behavior1.

On network1:

foo -rw,intr,nfsvers=3 bar.network1:/export/baz/&

On network2:

foo -rw,intr,nfsvers=3 qux.network2:/export/baz/&


1. Quick googling with keywords swap|switch network configurations mainly raise answers about network configuration (ip, gateway, dns...).
  • It's not enough to put a `timeout` option? It seems you can put in `/etc/auto.master` a line similar to the one used for smb `/var/autofs/smb /etc/auto.smb --timeout=60`. What in that file `/etc/auto.smb` it is mounted only when needed and removed after the timeout. – Hastur Apr 27 '15 at 18:14
  • There is no problem with timeout and unmounting automatically mounted partition. The issue here is to use config file A on network AA and config file B on network BB. – FabienAndre Apr 29 '15 at 17:23
  • I've understood that. I should be more clear: the suggestion was *it is not enough to put both together, (at the same time) the two configurations with a timeout*? Two different mount point. I suppose you will not switch from one network to another each 60 (or less) seconds... – Hastur Apr 29 '15 at 21:31
  • OK I understand your suggestion, my constraint here is that I would like to use the same mount point to always have files reachable at the same place (the two nfs servers are synchronized). – FabienAndre Apr 29 '15 at 22:02
  • Since it is connected with the *changing of the network*, maybe it is a good idea to execute a script when you connect to the network. Look if you can find an hint [on `/etc/NetworkManager/dispatcher.d` here](http://askubuntu.com/a/14139/196535). You can directly mount the current right one to the desired mount point, or maybe better, you can put the 2 mounting point in `autofs` with a timeout and change only a symbolic link to the currently right one so that you will always find the directory following the symbolic link. – Hastur Apr 29 '15 at 23:37

0 Answers0