How to check if a VLAN is set up in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if a VLAN is set up in Linux. You will explore three methods to verify VLAN configuration: listing VLAN interfaces using the ip link command to identify configured VLAN interfaces, examining the /etc/network/interfaces file to confirm VLAN settings, and checking the /proc/net/vlan file for detailed VLAN information. By completing these steps, you will gain practical skills in identifying and verifying VLAN setups on a Linux system.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/RemoteAccessandNetworkingGroup(["Remote Access and Networking"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("IP Managing") subgraph Lab Skills linux/cat -.-> lab-558777{{"How to check if a VLAN is set up in Linux"}} linux/ip -.-> lab-558777{{"How to check if a VLAN is set up in Linux"}} end

In this step, you will learn how to list VLAN interfaces using the ip link command. VLANs (Virtual Local Area Networks) are a way to segment a physical network into multiple logical networks. This is often used to improve network performance, security, and manageability.

The ip command is a powerful tool in Linux for managing network interfaces, routing, and tunnels. The link subcommand is used specifically for managing network interfaces.

To list all network interfaces on your system, including any configured VLAN interfaces, open your terminal and type the following command:

ip link show

Press Enter.

You will see output similar to this:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    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 fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
3: eth0.10@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff
4: eth0.20@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff

In this output:

  • lo is the loopback interface, used for communication within the system itself.
  • eth0 is your primary network interface.
  • eth0.10@eth0 and eth0.20@eth0 are VLAN interfaces. The format interface.vlan_id@parent_interface is commonly used to name VLAN interfaces. Here, eth0.10 is a VLAN interface with ID 10 on the parent interface eth0, and eth0.20 is a VLAN interface with ID 20 on the parent interface eth0.

The presence of interfaces like eth0.10 and eth0.20 indicates that VLANs are configured on your system.

You can also filter the output to show only specific interfaces or types of interfaces, but for now, ip link show is sufficient to see all interfaces, including VLANs.

Click Continue to proceed to the next step.

Verify VLAN config in /etc/network/interfaces

In this step, you will examine the network configuration file to see how the VLAN interfaces are defined. On many Debian-based systems like Ubuntu, network interfaces are configured in the /etc/network/interfaces file.

This file contains definitions for network interfaces, specifying how they should be configured when the system starts up. While modern systems often use netplan or NetworkManager, /etc/network/interfaces is still relevant and provides a clear way to see interface configurations, including VLANs.

To view the contents of this file, you can use the cat command, which is used to display the content of files.

Open your terminal and type the following command:

cat /etc/network/interfaces

Press Enter.

You will see output similar to this:

## interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth0.10
iface eth0.10 inet dhcp
    vlan-raw-device eth0

auto eth0.20
iface eth0.20 inet dhcp
    vlan-raw-device eth0

Let's break down the relevant parts for the VLAN interfaces:

  • auto eth0.10: This line tells the system to automatically bring up the eth0.10 interface during boot.
  • iface eth0.10 inet dhcp: This defines the eth0.10 interface and specifies that it should obtain an IP address using DHCP.
  • vlan-raw-device eth0: This is the crucial line that identifies eth0.10 as a VLAN interface and specifies that its parent device is eth0. The number after the dot (.10) is the VLAN ID.

You will see similar entries for eth0.20, indicating another VLAN interface with ID 20 on the same parent device eth0.

Examining this file helps you understand how the VLAN interfaces listed by ip link show are configured persistently on the system.

Click Continue to move on.

Check VLAN details with cat /proc/net/vlan

In this final step, you will look at another location in the Linux file system that provides information about configured VLANs: /proc/net/vlan.

The /proc file system is a virtual file system that provides information about processes and other system information. Files within /proc/net often contain details about the network stack. The /proc/net/vlan file specifically lists the configured 802.1q VLAN interfaces and their associated parent devices and VLAN IDs.

To view the contents of this file, use the cat command again.

Open your terminal and type the following command:

cat /proc/net/vlan

Press Enter.

You will see output similar to this:

VLAN  ID TYPE     REORDER DEVICE
eth0.10  10 8021Q      0 eth0
eth0.20  20 8021Q      0 eth0

This output provides a concise summary of the configured VLAN interfaces:

  • VLAN: The name of the VLAN interface (e.g., eth0.10).
  • ID: The VLAN ID (e.g., 10, 20).
  • TYPE: The VLAN protocol type (e.g., 8021Q).
  • REORDER: Indicates if VLAN frame reordering is enabled (usually 0).
  • DEVICE: The parent physical device the VLAN is associated with (e.g., eth0).

This file is a quick way to confirm which VLANs are active on the system and which physical interfaces they are linked to.

You have now successfully used three different methods (ip link show, cat /etc/network/interfaces, and cat /proc/net/vlan) to identify and verify VLAN configurations on a Linux system.

Click Continue to complete the lab.

Summary

In this lab, you learned how to check if VLANs are set up in Linux using several methods. First, you used the ip link show command to list all network interfaces and identify VLAN interfaces, which are typically named in the format interface.vlan_id@parent_interface. This command provides a quick overview of configured network links, including VLANs.

Next, you would typically verify the VLAN configuration by examining the /etc/network/interfaces file, which stores network interface configurations. Finally, you would use the cat /proc/net/vlan command to view detailed information about the configured VLANs, including their IDs and associated parent interfaces. These steps collectively provide a comprehensive way to determine if VLANs are set up and to inspect their configuration details on a Linux system.