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.

Ensure the following line is uncommented:

+dir:/etc/auto.master.d

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:

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:

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

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:

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.

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.



Categories: System Administration

Tags: , , , , , , , , , , , , , , , ,

Leave a Reply

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

%d bloggers like this: