0% found this document useful (0 votes)
4 views

How to configure a VLAN in Linux _ Enable Sysadmin

Uploaded by

krishnanor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

How to configure a VLAN in Linux _ Enable Sysadmin

Uploaded by

krishnanor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

Search

How to configure a VLAN in Linux


These VLAN configuration examples can help you get your Red Hat
Enterprise Linux networks set up correctly.

Posted: November 21, 2019 | 4 min read | Anthony Critelli (Sudoer)

"Red Hat" by liber is licensed under CC BY-SA 2.0

All but the smallest networks are typically split into Virtual Local Area Networks (VLANs, for
short), and I discussed VLAN basics a the previous article. Understanding how to properly
configure and troubleshoot VLANs can save you hours of back-and-forth with your network
team. In this article, cover VLAN configuration in Red Hat Enterprise Linux (RHEL) systems.
By the end of this article, you should be pretty comfortable configuring VLANs on RHEL.

Great Linux resources


Advanced Linux commands
cheat sheet

https://www.redhat.com/sysadmin/vlans-configuration 1/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

Download RHEL 9 at no charge


through the Red Hat Developer
program
A guide to installing
applications on Linux
Linux system administration
skills assessment
How well do you know Linux?
Take a quiz and get a badge

With the background knowledge out of the way, It's time to get your hands dirty with
configuration. I’ll start with the most basic VLAN configuration: no VLAN.

Simple example
One of the most common topologies that you will encounter as a sysadmin is a host
connected to a switch’s access port. VLAN configuration is handled on the switch, and you
configure the interface without any regard for the underlying network topology.

In the simple topology without VLANs that I discussed previously, your hosts are on the same
VLAN and IP subnet. The interface configuration is a simple, static IP address:

Network symbols provided by the LibreOffice VRT Network Equipment extension.

https://www.redhat.com/sysadmin/vlans-configuration 2/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP
group default qlen 1000
link/ether 52:54:00:82:d6:6e brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe82:d66e/64 scope link
valid_lft forever preferred_lft forever

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0
UUID=04cb4fa6-f820-45c0-b847-df94e9628bc5
DEVICE=eth0
ONBOOT=yes
GATEWAY=192.168.1.254
IPADDR=192.168.1.100
NETMASK=255.255.255.0

The above configuration is probably familiar to most who have administered a Linux server.
There isn’t any VLAN configuration on the host, but the switch is likely configured to place the
host on a particular VLAN.

Complex example
Next, take a look at a more complex topology. In the topology below, you can see a host (A
KVM hypervisor, for example) connected to a switch’s trunk port with three VLANs involved.
The first is VLAN 100, which is carried untagged across the port because it’s the native VLAN.
The second and third VLAN (200 and 300) are carried across the trunk with an 802.1Q tag.
Therefore, you need to configure your host to recognize that VLANs are involved here:

https://www.redhat.com/sysadmin/vlans-configuration 3/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

Network symbols provided by the LibreOffice VRT Network Equipment extension.

First, ensure that the 802.1Q kernel module is loaded. In practice, this module is automatically
loaded if you configure a VLAN subinterface. However, I’ll manually enable it for the sake of
demonstration:

# lsmod | grep 8021q

# modprobe 8021q

# lsmod | grep 8021q


8021q 33208 0
garp 14384 1 8021q
mrp 18542 1 8021q

Like most network configurations, you set up VLANs in the appropriate


/etc/sysconfig/network-scripts interface configuration file. This network configuration
looks like any other interface with a few important distinctions. First, specify the interface
name in the form of parentInterface.vlanID. This practice associates the VLAN with the
appropriate parent interface. Second, use the VLAN=yes directive to configure this
subinterface as a VLAN.

You already saw the configuration necessary for the untagged (native) VLAN: It’s the same
configuration that used above for eth0. The output below shows the configuration that is
needed for VLANs 200 and 300:
https://www.redhat.com/sysadmin/vlans-configuration 4/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.200
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0.200
UUID=04cb4fa6-f820-45c0-b847-df94e9628bc5
DEVICE=eth0.200
ONBOOT=yes
IPADDR=192.168.2.100
NETMASK=255.255.255.0
VLAN=yes

# cat /etc/sysconfig/network-scripts/ifcfg-eth0.300
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=eth0.300
UUID=04cb4fa6-f820-45c0-b847-df94e9628bc5
DEVICE=eth0.300
ONBOOT=yes
IPADDR=192.168.3.100
NETMASK=255.255.255.0
VLAN=yes

Once your VLANs have been configured, perform a quick restart of the network service to
bring up the interfaces. You should then be able to see your new VLAN interfaces:

# systemctl restart network

# ip --br link show


lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
eth0 UP 52:54:00:82:d6:6e
<BROADCAST,MULTICAST,UP,LOWER_UP>
eth0.200@eth0 UP 52:54:00:82:d6:6e
<BROADCAST,MULTICAST,UP,LOWER_UP>
eth0.300@eth0 UP 52:54:00:82:d6:6e
<BROADCAST,MULTICAST,UP,LOWER_UP>

# ip --br addr sh
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.168.1.100/24 fe80::5054:ff:fe82:d66e/64
eth0.200@eth0 UP 192.168.2.100/24 fe80::5054:ff:fe82:d66e/64
eth0.300@eth0 UP 192.168.3.100/24 fe80::5054:ff:fe82:d66e/64

https://www.redhat.com/sysadmin/vlans-configuration 5/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

The output above clearly shows that you have two new interfaces: eth0.200 and eth0.300.
These interfaces correspond to the VLANs that you configured, and any packets sent out of
these interfaces will be tagged with the appropriate VLAN ID on the trunk.

Recall that trunks add an 802.1Q field to the Ethernet header to provide the upstream device
with the appropriate VLAN ID. Now that you have some VLANs configured, you can see the
802.1Q field in a packet capture, as shown below. Notice that the VLAN ID of 200 corresponds
to your configured VLAN subinterface:

Network symbols provided by the LibreOffice VRT Network Equipment extension.

Wrapping up
That’s really all there is to configuring VLANs in Red Hat Enterprise Linux, at least on the
server side. Your network team also needs to create the VLANs on the upstream switch and
ensure that the port is correctly configured for trunking. If you need more VLANs (and you
probably will), then you can create additional interface files.

[Want to try out Red Hat Enterprise Linux? Download it now for free.]
Topics: Networking Linux

Anthony Critelli
Anthony Critelli is a Linux systems engineer with interests in automation, containerization,
tracing, and performance. He started his professional career as a network engineer and
eventually made the switch to the Linux systems side of IT. He holds a B.S. and an M.S.
More about me

https://www.redhat.com/sysadmin/vlans-configuration 6/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

Try Red Hat Enterprise Linux


Download it at no charge from the Red Hat Developer program.

Download now

Related Content

Test TCP ports with Python Stop using Telnet to test ports
and Scapy Make life simpler by automating network
Get greater control over TCP port checks with tools like Expect, Bash,
checking with a DIY, customizable Netcat, and Nmap instead.
approach using Python and Scapy.

Posted: April 19, 2023 Posted: April 18, 2023


Author: Jose Vicente Nunez (Sudoer) Author: Jose Vicente Nunez (Sudoer)

8 open source 'Easter eggs' to


have fun with your Linux
terminal
Hunt these 8 hidden or surprising features
to make your Linux experience more
entertaining.

https://www.redhat.com/sysadmin/vlans-configuration 7/8
6/6/23, 12:29 PM How to configure a VLAN in Linux | Enable Sysadmin

Posted: April 10, 2023


Author: Ricardo Gerardi (Editorial Team, Sudoer
alumni, Red Hat)

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. The content
published on this site are community contributions and are for informational purpose only AND ARE NOT, AND ARE NOT
INTENDED TO BE, RED HAT DOCUMENTATION, SUPPORT, OR ADVICE.

Red Hat and the Red Hat logo are trademarks of Red Hat, Inc., registered in the United States and other countries.

About Red Hat


Jobs
Events
Locations
Contact Red Hat
Red Hat Blog
Diversity, equity, and inclusion
Cool Stuff Store
Red Hat Summit

© 2023 Red Hat, Inc.


Privacy statement
Terms of use
All policies and guidelines
Digital accessibility
Cookie Preferences

https://www.redhat.com/sysadmin/vlans-configuration 8/8

You might also like