Virtual LANs give you the ability to sub-divide a LAN. Linux can accept '''VLAN''' tagged traffic and presents each '''VLAN ID''' as a different network interface (eg: {{ic|eth0.100}} for '''VLAN ID''' {{ic|100}})

{{Article summary start}}

{{Article summary start}}

−

{{Article summary text|Руководство по настройке VLAN}}

+

{{Article summary text|This article explains how to configure a VLAN using {{Pkg|iproute2}} and [[netcfg]]}}

{{Article summary heading|Related}}

{{Article summary heading|Related}}

{{Article summary wiki|Network}}

{{Article summary wiki|Network}}

+

{{Article summary wiki|Netcfg}}

{{Article summary end}}

{{Article summary end}}

+

+

==Configuration==

+

Previously Arch Linux used {{AUR|vconfig}} to setup VLANs. This had been superseded by the {{ic|ip}} command. Make sure you have {{Pkg|iproute2}} installed.

+

+

In the following examples, lets assume the '''interface''' is {{ic|eth0}}, the assigned '''name''' is {{ic|eth0.100}} and the '''vlan id''' is {{ic|100}}.

+

===Create the VLAN device===

+

+

Add the VLAN with the following command:

+

{{bc|# ip link add link eth0 name eth0.100 type vlan id 100}}

+

Run {{ic|ip link}} to confirm that it has been created.

+

+

This interface behaves like a normal interface. All traffic routed to it will go through the master interface (in this example, {{ic|eth0}}) but with a VLAN tag. Only VLAN aware devices can accept them if configured correctly else the traffic is dropped.

+

+

Using a '''name''' like {{ic|eth0.100}} is just convention and not enforced; you can alternatively use eth0_100 or something descriptive like IPTV

+

+

To see the VLAN ID on an interface, in case you used an unconventional name:

+

{{bc|# ip -d link show eth0.100}}

+

The {{ic|-d}} flag shows full details on an inteface.

+

+

===Add an IP===

+

Now add an IPv4 address to the just created vlan link, and activate the link:

+

{{bc|

+

# ip addr add 192.168.100.1/24 brd 192.168.100.255 dev eth0.100

+

# ip link set dev eth0.100 up

+

}}

+

===Turning down the device===

+

To cleanly shutdown the setting before you remove the link, you can do:

+

{{bc|# ip link set dev eth0.100 down}}

+

===Removing the device===

+

Removing a VLAN interface is significantly less convoluted

+

{{bc|# ip link delete eth0.100}}

+

+

===Starting at boot===

+

+

{{Out of date|''netcfg'' has been superseded by [[netctl]]}}

+

+

You can use the following parameters in [[netcfg]] profiles to have VLANs configured automatically:

+

+

{{hc|/etc/network.d/my-network|<nowiki>

+

# vlan specific part:

+

CONNECTION="vlan"

+

VLAN_PHYS_DEV="eth0"

+

VLAN_ID="100"

+

INTERFACE="eth0.100"

+

+

# general IP configuration:

+

IP="static"

+

ADDR="192.168.100.1"

+

NETMASK="255.255.255.0"

+

GATEWAY="192.168.100.254"

+

</nowiki>}}

+

+

Enable the daemon {{ic|netcfg@my-network}}. Read [[Daemons]] for more details.

+

+

==Troubleshooting==

+

===udev renames the virtual devices===

+

An annoyance is that [[udev]] may try to rename virtual devices as they are added, thus ignoring the '''name''' configured for them (in this case {{ic|eth0.100}}).

Contents

Configuration

Previously Arch Linux used vconfigAUR to setup VLANs. This had been superseded by the ip command. Make sure you have iproute2 installed.

In the following examples, lets assume the interface is eth0, the assigned name is eth0.100 and the vlan id is 100.

Create the VLAN device

Add the VLAN with the following command:

# ip link add link eth0 name eth0.100 type vlan id 100

Run ip link to confirm that it has been created.

This interface behaves like a normal interface. All traffic routed to it will go through the master interface (in this example, eth0) but with a VLAN tag. Only VLAN aware devices can accept them if configured correctly else the traffic is dropped.

Using a name like eth0.100 is just convention and not enforced; you can alternatively use eth0_100 or something descriptive like IPTV

To see the VLAN ID on an interface, in case you used an unconventional name:

# ip -d link show eth0.100

The -d flag shows full details on an inteface.

Add an IP

Now add an IPv4 address to the just created vlan link, and activate the link: