AutoFS with DHCP Classless Static Route Option

My FreeNAS server is a virtual machine (VM) on my Dell r710 server. I mount my NFS and CIFS Shares using AutoFS and configure my static routes to the NAS using the DHCP Server on my pfSense Appliance.
AutoFS is software that uses the automounter of the Linux kernel to dynamically mount file systems on demand. When not in use they are unmounted, freeing up resources.

Slackware Linux comes with autofs installed so I only need to configure it for my use case. The first order of business is to verify the Master Map File located at /etc/auto.master has acceptable defaults properly configured.

# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#/misc	/etc/auto.misc
# NOTE: mounts done from a hosts map will be mounted with the
#	"nosuid" and "nodev" options unless the "suid" and "dev"
#	options are explicitly given.
#/net	-hosts
# Include /etc/auto.master.d/*.autofs
# Include central master map if it can be found using
# nsswitch sources.
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.

Ensure the following line is uncommented:


This directory is where some of our configuration files are placed. You do not need to edit this file unless it contains incompatible defaults. When you update your system, default files tend to get overwritten.

Now that I have verified where to place my files, I created shares.autofs and added the following contents:

mech@mainz(tmp):$ sudo cat /etc/auto.master.d/shares.autofs 
/nas/nfs /etc/freenas.nfs
/nas/smb /etc/freenas.smb

Each line in shares.autofs identifies a mount point and the associated map, which is a separate configuration file located outside of the auto.master.d directory.

Note: You will have to create the directories and files:

mech@mainz(tmp):$ sudo mkdir -p /nas/{nfs,smb} ; tree /nas
├── nfs
└── smb
mech@mainz(tmp):$ sudo touch /etc/{freenas.nfs,freenas.smb} ; ls -l /etc/freenas.*
-rw------- 1 root root 22 Jan  1 16:55 /etc/freenas.nfs
-rw------- 1 root root 85 Jan  2 15:01 /etc/freenas.smb 

freenas.nfs is my configuration for any NFS shares that I want autofs to handle:

mech@mainz(tmp):$ sudo cat /etc/freenas.nfs 
*	-rw	nas:/mnt/NAS0/&

The above configuration will dynamically mount any NFS Share on my NAS and give it the same name under my local mount point. Remember from above I configured /nas/nfs for my local mount. So for example, if there is a share on my NAS called Photos, it will be mounted automatically when I access /nas/nfs/Photos. This flexibility means new shares can be created in the future and the same will hold true.

Note: Using a wild card (*) is only available with indirect maps.

freenas.smb is my configuration for any CIFS shares that I want autofs to handle:

mech@mainz(tmp):$ sudo cat /etc/freenas.smb 
WinFiles	-fstype=cifs,vers=3.0,credentials=/etc/cifs.passwd,uid=1000,gid=100	://nas/WinFiles

WinFiles is my local mount point under /nas/smb that will be dynamically created and mounted when accessed. //nas/WinFiles is the remote share.

Once all of that is complete,  enable and start the service:

sudo chmod 755 /etc/rc.d/rc.autofs
sudo /etc/rc.d/rc.autofs start

Currently, whenever I try to access anything on my Dell Server from my home office, the traffic traverses a redundant hop to my Cisco 3560G and back to the office unless I add a static route for the pfSense gateway also a VM on the server. A few solutions were:

1. Buy another layer 3 switch
2. Manually add the route to each device and then remove it when appropriate.
3. Make use of the DHCP Classless Static Route Option (RFC 3442).

I went with option three. The pfSense Web UI for the configuration setting is below.

The RFC outlines how to create the hex string needed for the value field. A quick read and I was able to write a python script that calculates the value based on the IP/CIDR and Gateway command line arguments.

$ ./ --subnet  --gateway

The output is the format for the DHCP Service on pfSense, other software may have their respective formats. However, it is trivial to modify the script to get the output you need.

Thanks for reading.

Start a discussion or ask a question.

This site uses Akismet to reduce spam. Learn how your comment data is processed.