This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Monday, February 26, 2018

How to create VLAN interface by using comand line in RHEL7

By using nmcli command we can craete the VLAN interface in RHEL7.

VLANs are isolated broadcast domains that run over a single physical network. They allow you to segment a local network and also to "stretch" a LAN over multiple physical locations. Most enterprises implement this on their network switching environment, but in some cases, the tagged VLANs reach your server.

For this case, our physical network interface is called enp0s3. The VLAN's ID is 501, and the IPv4 address is 192.168.1.10, with a subnet mask of 255.255.255.0 and a default gateway of 192.168.1.1.

Create vlan
[root@nsk ~]# nmcli connection add type vlan dev enp0s3 id 501 ip4 192.168.1.10/24 gw4 192.168.1.1
Connection 'vlan' (a01bd6a3-a486-4c5b-83af-73d7344cc388) successfully added.

Activate the connection
[root@nsk ~]# nmcli connection up vlan
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)

Check the Connection
[root@nsk ~]# nmcli connection show
NAME     UUID                                                                 TYPE                   DEVICE
enp0s3  191fbaab-7ac3-4616-9368-3b006cba3574      802-3-ethernet     enp0s3
vlan        a01bd6a3-a486-4c5b-83af-73d7344cc388      vlan                      enp0s3.501

[root@nsk ~]# nmcli device status
DEVICE          TYPE           STATE         CONNECTION
enp0s3          ethernet       connected    enp0s3
enp0s3.501   vlan              connected    vlan
lo                  loopback       unmanaged   --

[root@nsk ~]# nmcli device show enp0s3.501
GENERAL.DEVICE                   :    enp0s3.501
GENERAL.TYPE                      :      vlan
GENERAL.HWADDR                :     08:00:27:93:16:4B
GENERAL.MTU                        :    1500
GENERAL.STATE                    :    100 (connected)
GENERAL.CONNECTION        :   vlan
GENERAL.CON-PATH             :    /org/freedesktop/NetworkManager/ActiveConnection/3
IP4.ADDRESS[1]                     :      192.168.1.10/24
IP4.GATEWAY                         :      192.168.1.1
IP6.ADDRESS[1]                     :       fe80::ecb7:3969:728f:a67b/64
IP6.GATEWAY                         :       --
[root@nsk ~]#

The command line to create a VLAN with nmcli is very basic as it uses default values.

Below command will full option to create detailed VLAN interface.
[root@nsk ~]# nmcli con add help

No comments:

Post a Comment