Configure VLANs on FreeBSD

If you have a switch, access point or other piece of network hardware that supports 802.1q VLAN tagging, and you’d like to your FreeBSD system to recognize them, it’s a pretty straight-forward configuration.  I’ll use examples from my network to illustrate.  My goal in this case, which I may write about in a separate post, was to create two segmented wifi networks – one for my main network and one for guests to connect to.  I wanted the guest network to have access to the internet, but not to any of my other systems on the network.

I have a wireless access point that supports multiple SSIDs, and each SSID can be tagged as a VLAN.  Let’s say my two SSIDs are “Main” and “Guest.”  My access point is configured to tag everything on Main with VLAN ID 101, and everything on Guest with VLAN ID 102.  All the systems on Main will be on the subnet and everything on Guest will be on the subnet.

This access point is connected to the main switch on the network, which the FreeBSD box is also connected to – it’s not a managed switch, but it does support large packet sizes, which is required as 802.1q tagging adds data to packet headers, and that makes the packets bigger than the standard size.  One of my older hubs ended up dropping the tagged packets silently.

All of the configuration is in /etc/rc.conf.

The first thing to do is to list the VLANs that will be on the lan0 adapter:

This will cause FreeBSD to create new “virtual” network adapters called lan0.101 and lan0.102 – and these seem to function much like any other network card, you can use ifconfig on them.

Then, configure the actual addresses for the new virtual adapters:

Now reboot your system or run /etc/rc.d/netif restart – you should now see something like this in your ifconfig output:

At this point, any packets coming in that are tagged in VLANs 101 or 102 will be recognized.  Note that it clearly shows the vlan tag and the physical parent adapter.  At this point, you may need to set up routing and firewall rules for these subnets.

Rate this post
Scroll to Top