• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
OpenTechTips

OpenTechTips

Comprehensive IT Guides for Pros and Enthusiasts

MENUMENU
  • HOME
  • ALL TOPICS
    • Exchange
    • InfoSec
    • Linux
    • Networking
    • Scripting
      • PowerShell
    • SSL
    • Tools
    • Virtualization
    • Web
    • Windows
  • ABOUT
  • SUBSCRIBE
Home » One Interface, multiple VLAN IPs on Linux

One Interface, multiple VLAN IPs on Linux

March 29, 2020 - by Zsolt Agoston - last edited on April 18, 2020

To make use of a trunk interface connected to our linux box with a single interface we can configure subinterfaces accessing specific VLAN segments, here we will use Debian and RHEL, assigning two subinterfaces, to each, on will use DHCP to get an IP in the specific subnet, we configure a static address on the other one.

Debian, Ubuntu

Interface

VLAN

subnet

IP

ens18

1 (native, untagged)

192.168.0.0/24

192.168.0.8

ens18.100

100

10.0.0.0/24

10.0.0.2

ens18.101

101

10.0.1.0/24

10.0.1.5

First we install the vlan package with

apt install vlan
One Interface, multiple VLAN IPs on Linux

Now we edit the /etc/network/interfaces config file. Opening it we see that our existing interface is called ens18. So to add the subinterfaces we append the following:

…
 Create a subinterface on VLAN100, using DHCP
 auto ens18.100
 iface ens18.100 inet dhcp
 Create a subinterface on VLAN101, assigning static IP
 auto ens18.101
 iface ens18.101 inet dhcp
   address 10.0.1.5/24
 …
One Interface, multiple VLAN IPs on Linux

After a reboot we check if the interfaces are active:

One Interface, multiple VLAN IPs on Linux

RHEL, CentOS 

Interface

VLAN

subnet

IP

ens18

1 (native, untagged)

192.168.0.0/24

192.168.0.9

ens18.100

100

10.0.0.0/24

10.0.0.3

ens18.101

101

10.0.1.0/24

10.0.1.6

In RHEL and CentOS 7 and 8 the vlan module (called 8021q) should be loaded by default, we can verify it:

modinfo 8021q

If it is loaded, we proceed by listing the available network interface in the system.

ls -l /etc/sysconfig/network-scripts

In our example we have ens18 just like the Debian box had

One Interface, multiple VLAN IPs on Linux

We simply create the corresponding configuration files for both subinterfaces:

vi /etc/sysconfig/network-scripts/ifcfg-ens18.100

DEVICE=ens18.100
BOOTPROTO=dhcp
ONBOOT=yes
VLAN=yes

vi /etc/sysconfig/network-scripts/ifcfg-ens18.101

DEVICE=ens18.101
BOOTPROTO=none
ONBOOT=yes
IPADDR=10.0.1.6
PREFIX=24
NETWORK=10.0.1.0
VLAN=yes
One Interface, multiple VLAN IPs on Linux

Reader Interactions

Comments Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tools

Secondary Sidebar

CONTENTS

  • Debian, Ubuntu
  • RHEL, CentOS 

  • Terms of Use
  • Disclaimer
  • Privacy Policy
Manage your privacy

To provide the best experiences, we and our partners use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us and our partners to process personal data such as browsing behavior or unique IDs on this site and show (non-) personalized ads. Not consenting or withdrawing consent, may adversely affect certain features and functions.

Click below to consent to the above or make granular choices. Your choices will be applied to this site only. You can change your settings at any time, including withdrawing your consent, by using the toggles on the Cookie Policy, or by clicking on the manage consent button at the bottom of the screen.

Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}
Manage your privacy
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Statistics

Marketing

Features
Always active

Always active
Manage options Manage services Manage {vendor_count} vendors Read more about these purposes
Manage options
{title} {title} {title}