autobridge
FreeBSD
How to automatically add interfaces to a bridge when FreeBSD boots
You can configure FreeBSD's /etc/rc.conf with autobridge_interfaces which will populate the defined if_bridge(4) interfaces with physical or virtual network adapters of your choice. In the below example the following applies:
- Your if_bridge(4) interfaces rather than the bridge members are assigned with IP addresses to communicate with the L3 networks.
- You wish to have static and predictable MAC addresses on L2. This can be accomplished by adding net.link.bridge.inherit_mac=1 to /etc/sysctl.conf which will make the bridge inherit the first bridge member's MAC address.
- An ixl(4) network adapter carries VLAN 23 (internet access) and VLAN 42 (internal network without internet access).
- You wish to prepare one bridge per VLAN when the FreeBSD system boots, ready to accept additional network interfaces of FreeBSD bhyve virtual machines or FreeBSD jail containers.
# gateway to the internet
defaultrouter="192.0.2.1"
# network adapter ixl0 remains without configuration but needs to be up
ifconfig_ixl0="up"
# NOTE: there are multiple ways to create and name VLAN adapters
# create bridges and VLANs with an intuitive naming convention
cloned_interfaces="bridge23 bridge42 ixl0.23 ixl0.42"
# define bridges to be auto-populated with interfaces
autobridge_interfaces="bridge23 bridge42"
# define which interface is supposed to become a member of which bridge
# NOTE: there is wildcard support
# e.g. vlan* would add any interface name starting with "vlan" to the bridge
autobridge_bridge23="vlan23"
autobridge_bridge42="vlan42"
# rename VLAN interfaces to match your chosen naming convention
# ensure interfaces are up
ifconfig_ixl0_23="name vlan23 up"
ifconfig_ixl0_42="name vlan42 up"
# assign IP addresses to the bridge interfaces, not the bridge members
ifconfig_bridge23="inet 192.0.2.23/24" # network with internet access
ifconfig_bridge100="inet 10.0.2.42/16" # IP address in internal network