how to use vlans on freebsd interfaces

this example assumes:

  • physical device em0

  • vlan 1

  • cisco switch running ios

manual configuration:

configure the physical interface:
ifconfig em0 up
create the vlan interface:
ifconfig vlan0 vlan 1 vlandev em0
assign the vlan interface its ip address:
ifconfig vlan0 inet 192.168.0.2 netmask 255.255.255.0
/etc/rc.conf:
cloned_interfaces="vlan0"
ifconfig_em0="up"
ifconfig_vlan0="inet 192.168.0.2 netmask 255.255.255.0 vlan 1 vlandev em0"
configure the switch:
interface Gi/1/1
switchport trunk encapsulation dot1q
switchport trunk allowed vlan 1
switchport mode trunk