Difference between revisions of "VLAN"

From ArchWiki
Jump to: navigation, search
(Fixing style and using wiki templates)
(Starting at boot: Fixing style of daemons)
Line 53: Line 53:
Enable the service:
[[Daemon|Enable the daemon]] {{ic|netcfg@my-network}}.
{{bc|# systemctl enable netcfg@my-network}}

Revision as of 00:19, 22 December 2012

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:VLAN#)

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

Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end


Previously Arch Linux used vconfig 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 vid 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

Add an IP

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

# ip addr add brd 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:

# ip link set dev eth0.100 down

Removing the device

Removing a VLAN interface is significantly less convoluted

# ip link delete eth0.100

Starting at boot

You can use a netcfg profile and put POST_UP, PRE_DOWN command to do above action. (Similar thing as done here: [1])

For example, a eth0 interface that is both multi-home (DHCP to the modem, and local subnet, and VLAN 112 as well. Here is an extract of the configuration:

DESCRIPTION='modem cable connection'
POST_UP='ip addr add brd dev eth0; ip link add link eth0 name eth0.112 type vlan id 112; ip addr add brd dev eth0.112; ip link set dev eth0.112 up'
PRE_DOWN='ip link set dev eth0.112 down; ip link delete eth0.112; ip addr del dev eth0'

Enable the daemon netcfg@my-network.


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 eth0.100).

For instance, if the following commands are issued:

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

This could generate the following output:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff
3: rename1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state DOWN 
    link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ff

udev has ignored the configured virtual interface name eth0.100 and autonamed it rename1.

The solution is to edit /etc/udev/rules.d/network_persistent.rules and append DRIVERS=="?*" to the end of the physical interface's configuration line.

For example, for the interface aa:bb:cc:dd:ee:ff (eth0):

SUBSYSTEM=="net", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="eth0", DRIVERS=="?*"

A reboot should mean that VLANs configure correctly with the names assigned to them.