VLAN: Difference between revisions
(Add warning about information being outdated) |
Prabuanand (talk | contribs) (changed wikitags, added links to alternates) |
||
Line 1: | Line 1: | ||
{{Obsolete|The information is outdated and is not suitable for systems using | {{Obsolete|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}} | ||
This article shows how to configure a network interface as an IEEE 802.1q VLAN trunk. | This article shows how to configure a network interface as an IEEE 802.1q VLAN trunk. | ||
Line 6: | Line 6: | ||
==Installation== | ==Installation== | ||
{{Warning|Installing the vlan package may result in | First, install the {{pkg|vlan|arch=}} package. This will give you support for VLANs in the {{path|/etc/network/interfaces}} file.{{Cmd|apk add {{pkg|vlan|arch=}}}} | ||
{{Warning|Installing the vlan package may result in [[Ifupdown-ng]] being replaced by busybox-ifupdown. If you use ifupdown-ng specific config, this may prevent your network from being configured properly.}} | |||
==Configuration== | ==Configuration== | ||
Edit the {{path|/etc/network/interfaces}} file: | |||
Edit the {{path|/etc/network/interfaces}} file as follows:{{Cat|/etc/network/interfaces|auto eth0.8 | |||
auto eth0.8 | |||
iface eth0.8 inet static | iface eth0.8 inet static | ||
address 192.168.0.2 | address 192.168.0.2 | ||
Line 19: | Line 19: | ||
gateway 192.168.0.1 | gateway 192.168.0.1 | ||
vlan-raw-device eth0 | vlan-raw-device eth0 | ||
vlan_id 8 | vlan_id 8}} | ||
With the ''vlan'' package installed, {{ic|ifup}} will find the trailing .8 in eth0.8 and will create a VLAN interface with vid 8 over eth0. | With the ''vlan'' package installed, {{ic|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: | Alternatively with vlan8 over eth0:{{Cat|/etc/network/interfaces|auto vlan8 | ||
auto vlan8 | |||
iface vlan8 inet static | iface vlan8 inet static | ||
address 192.168.0.2 | address 192.168.0.2 | ||
netmask 255.255.255.0 | netmask 255.255.255.0 | ||
gateway 192.168.0.1 | gateway 192.168.0.1 | ||
vlan-raw-device eth0 | vlan-raw-device eth0}} | ||
A static IP address was used in the examples shown above, but DHCP can be used as well. | 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 == | == 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 | 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:{{Cat|/etc/network/interfaces|auto lo | ||
auto lo | |||
iface lo inet loopback | iface lo inet loopback | ||
Line 68: | Line 62: | ||
bridge_ports bond0.10 | bridge_ports bond0.10 | ||
bridge_stp off | bridge_stp off | ||
bridge_fd 0.0 | bridge_fd 0.0}} | ||
== Example with two interfaces on the same adapter. One with VLAN and one without == | == 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 | Since Linux doesn't allow multiple default gateways we need to use a second routing table using iproute2:{{Cmd|apk add {{pkg|iproute2|arch=}}}} | ||
{{Cmd| | Then we'll add two new routing tables to the config file. One for each network:{{Cmd|echo "1 rt1" >> /etc/iproute2/rt_tables;echo "2 rt2" >> /etc/iproute2/rt_tables;}} | ||
Now we need to edit the file {{path|/etc/network/interfaces}} as follows {{Cat|/etc/network/interfaces|auto lo | |||
{{ | |||
auto lo | |||
iface lo inet loopback | iface lo inet loopback | ||
Line 94: | Line 81: | ||
gateway 192.168.1.1 | gateway 192.168.1.1 | ||
post-up ip route add 192.168.1.0/24 dev eth0 src 192.168.1.100 table rt1 | post-up ip route add 192.168.1.0/24 dev eth0 src 192.168.1.100 table rt1 | ||
post-up ip route add default via 192.168.1.1 dev eth0 table rt1 # | post-up ip route add default via 192.168.1.1 dev eth0 table rt1 # actual gateway for this interface | ||
post-up ip rule add from 192.168.1.100/32 table rt1 | post-up ip rule add from 192.168.1.100/32 table rt1 | ||
post-up ip rule add to 192.168.1.100/32 table rt1 | post-up ip rule add to 192.168.1.100/32 table rt1 | ||
Line 103: | Line 90: | ||
address 192.168.5.100/24 | address 192.168.5.100/24 | ||
post-up ip route add 192.168.5.0/24 dev eth0.5 src 192.168.5.100 table rt2 | post-up ip route add 192.168.5.0/24 dev eth0.5 src 192.168.5.100 table rt2 | ||
post-up ip route add default via 192.168.5.1 dev eth0.5 table rt2 # | post-up ip route add default via 192.168.5.1 dev eth0.5 table rt2 # actual gateway for this interface | ||
post-up ip rule add from 192.168.5.100/32 table rt2 | post-up ip rule add from 192.168.5.100/32 table rt2 | ||
post-up ip rule add to 192.168.5.100/32 table rt2 | post-up ip rule add to 192.168.5.100/32 table rt2}} | ||
Note that if you want to add a third interface this way, you'll have to add another routing table. | |||
== See also == | |||
*[https://github.com/ifupdown-ng/ifupdown-ng/blob/main/doc/interfaces-vxlan.scd VXLAN manual for Ifupdown-ng] | |||
*[[Configure Networking|Main Networking page]] | |||
[[Category:Networking]] | [[Category:Networking]] |
Latest revision as of 04:26, 25 March 2025
![]() 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.