VLAN Subinterface (802.1q)

This example configures a VLAN subinterface (IEEE 802.1q):

  • rename the base interface to trunk
  • set the base interface link to up
  • create a VLAN subinterface for VLAN ID 42
  • make device state not to track the base interface's device state
  • set the subinterface link state to up
  • add an ipv4 address on the subinterface
interfaces:
  trunk:
    link:
      kind: physical
      state: up
    identify:
      perm_address: 8c:16:45:dc:b1:ad
  outside:
    addresses:
      - 192.0.2.1/24
    link:
      kind: vlan
      link: trunk
      vlan_id: 42
      vlan_flags:
        loose_binding: true
      state: up
{
  networking.ifstate = {
    enable = true;
    settings = {
      interfaces = {
        trunk = {
          link = {
            kind = "physical";
            state = "up";
          };
          identify.perm_address = "8c:16:45:dc:b1:ad";
        };
        outside = {
          addresses = [ "192.0.2.1/24" ];
          link = {
            kind = "vlan";
            link = "trunk";
            vlan_id = 42;
            vlan_flags = {
              loose_binding = true;
            }
            state = "up";
          };
        };
      };
    };
  };
}
ip link dev eth0 set down
ip link set dev eth0 name trunk up
ip link add name outside link trunk type vlan id 42 loose_binding on
ip link set dev outside up
ip address add 192.0.2.1/24 dev outside