VLAN
![]() The information is outdated and is not suitable for systems using Ifupdown-ng. Installing the vlan package may prevent your network from being configured correctly (Discuss) |
This article shows how to configure a network interface as an IEEE 802.1q VLAN trunk.
Installation
First, install the vlan package. This will give you support for VLANs in the /etc/network/interfaces file.
apk add vlan

Configuration
Edit the /etc/network/interfaces file as follows:
Contents of /etc/network/interfaces
With the vlan package installed, ifup
will find the trailing .8 in eth0.8 and will create a VLAN interface with vid 8 over eth0.
Alternatively with vlan8 over eth0:
Contents of /etc/network/interfaces
A static IP address was used in the examples shown above, but DHCP can be used as well.
Example with bridges associated with VLANs over bonding with differing MTUs on the various VLANs
This serves as an example of some of the more complicated networking possible. Particularly, this would work well for a hypervisor attached to a dedicated storage VLAN. Less complicated implementations can be achieved by merely removing the non-applicable parts as follows:
Contents of /etc/network/interfaces
Example with two interfaces on the same adapter. One with VLAN and one without
Since Linux doesn't allow multiple default gateways we need to use a second routing table using iproute2:
apk add iproute2
Then we'll add two new routing tables to the config file. One for each network:
echo "1 rt1" >> /etc/iproute2/rt_tables;echo "2 rt2" >> /etc/iproute2/rt_tables;
Now we need to edit the file /etc/network/interfaces as follows
Contents of /etc/network/interfaces
Note that if you want to add a third interface this way, you'll have to add another routing table.