Skip to content

Instantly share code, notes, and snippets.

@codeedog
Last active January 4, 2025 17:00
Show Gist options
  • Save codeedog/902794ba8f34f45745d7325a46d488b7 to your computer and use it in GitHub Desktop.
Save codeedog/902794ba8f34f45745d7325a46d488b7 to your computer and use it in GitHub Desktop.
VLAN creation in FreeBSD

How to configure VLANs in FreeBSD

Assume we have a switchport with an untagged (native) VLAN 10, plus two tagged VLANs 20 & 30 (see attached switch config). The device connected to that switchport has an internal interface eth0. Use this in /etc/rc.conf:

# SYNCDHCP makes the boot process wait for address assignment
ifconfig_eth0="SYNCDHCP"

vlans_eth0="20 30"
ifconfig_eth0_20="SYNCDHCP"
ifconfig_eth0_30="inet 192.168.35.15/24"

This creates two VLAN interfaces eth0.20 & eth0.30. eth0 is untagged for the device, although in the switchport configuration the port is marked as native vlan 10. Note the use of SYNCDHCP in the base interface definition and the one for VLAN 20. Using DHCP often results in no attached address. The DHCP request/repsonse cycle takes too long and gets lost.

If you don't want to delay your system startup waiting on DHCP addresses (for example, because you're coding a router or server), change all of the interfaces to static IPs like VLAN 30. Statically defined interfaces come up fast and are ready almost immediately.

That's it. It's that simple.


There's a lot of misinformaton out there. The above configuration started with info from /etc/defaults/rc.conf and the RC.CONF(5) Man Page. I found that defaults file in a 13 year old post that had the correct information in it. Thank you bboard hero!

# Sample Switchport Configuration
interface GigabitEthernet0/7
switchport trunk native vlan 10
switchport trunk allowed vlan 20,30
switchport mode trunk
# /etc/defaults/rc.conf
vlans_em0="101 vlan0" # vlan(4) interfaces for em0 device
create_args_vlan0="vlan 102" # vlan tag for vlan0 device
autobridge_interfaces="bridge0" # List of bridges to check
autobridge_bridge0="tap* vlan0" # Interface glob to automatically add to the bridge
Excerpt from RC.CONF(5) man page:
To create a vlan device named em0.101 on em0 with the vlan
tag 101 and the optional IPv4 address 192.0.2.1/24:
vlans_em0="101"
ifconfig_em0_101="inet 192.0.2.1/24"
To create a vlan device named myvlan on em0 with the vlan
tag 102:
vlans_em0="myvlan"
create_args_myvlan="vlan 102"
DO NOT USE THESE. THEY DON'T WORK, AT LEAST THEY DIDN'T WORK FOR ME.
When I was using:
#######################################################################
# DOES NOT WORK
cloned_interfaces="vlan20"
ifconfig_vlan20="inet ##.##.##.##/24 vlan 20 vlandev eth0"
#######################################################################
I kept getting this error:
ifconfig: SIOCSETVLAN: Device busy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment