RHEL7: How to configure vlans.

Share this link

Presentation of Vlans

If you’ve got a switch with vlan capabilities, at one point or another, you will want to add vlans to your network. Vlan stands for virtual local area network. It is a way to create separate virtual networks from a single physical one (see wikipedia for an in-depth explanation). In a typical production environment, you’ve got several vlans: one for console management, one for storage, one for backup, one for application flows, etc.

Vlans receive a number for identification between 0 and 4095. Avoid 0, 1 and 4095.

Normally, the number 1 is reserved for management. On some switches, it is not possible to change this configuration. Check your switch documentation for more details.

This separation is done through a mechanism called tagging. Each port of a switch is associated with a vlan. Each packet going into a switch through a port receives a tag containing the vlan number, telling from which vlan it is coming. This tag is removed when the packet leaves the switch. In the remaining of this tutorial we will use the 802.1Q standard.

If your server isn’t used as a router between vlans or if it doesn’t need to be connected to several vlans at the same time through the same cable, no additional configuration is required.

However, if it is a router or if it sees several vlans at the same time, your server needs to be connected to a special kind of port called a trunk. A trunk is a port of a switch where the tags are not removed. It is up to the server to remove them.

Configuration Procedure

First, you will need to set up a trunk on the switch side. It’s only in a second stage that you will need to configure vlans on the server side.

Let’s assume that we configured a trunk on a switch dealing with two vlans:

  • vlan number 10 called vlan10, representing the 192.168.10.0/24 network,
  • vlan number 20 called vlan20, representing the 192.168.20.0/24 network.

We now want to connect our server to the trunk through the eth0 network interface with a cable.

To remove any previous configuration on the eth0 network interface, type:

# nmcli con del eth0

Note: It is important that there is no ip configuration on the main interface (no ip address, etc).

To create the two vlans on the eth0 network interface, type:

# nmcli con add type vlan con-name vlan10 dev eth0 id 10
Connection 'vlan10' (8275c94d-2dc7-4c6c-95fd-e64caec67850) successfully added.
# nmcli con add type vlan con-name vlan20 dev eth0 id 20
Connection 'vlan20' (e10eea8c-ea4e-483a-8ceb-1669d2252106) successfully added.

To check the new configuration, type:

# nmcli con show
NAME    UUID                                  TYPE            DEVICE 
vlan20  e10eea8c-ea4e-483a-8ceb-1669d2252106  vlan            --     
vlan10  8275c94d-2dc7-4c6c-95fd-e64caec67850  vlan            --     

Now, you can configure the network interfaces as usual (look at the network configuration tutorial for more details):

# nmcli con mod vlan10 ipv4.addresses 192.168.10.1/24
# nmcli con mod vlan10 ipv4.gateway 192.168.10.1
# nmcli con mod vlan10 ipv4.method manual
# nmcli con up vlan10
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
# nmcli con mod vlan20 ipv4.addresses 192.168.20.1/24
# nmcli con mod vlan20 ipv4.gateway 192.168.20.1
# nmcli con mod vlan20 ipv4.method manual
# nmcli con up vlan20
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)

Finally, to check the configuration, type:

# nmcli dev
DEVICE       TYPE      STATE         CONNECTION 
eth0.10      vlan      connected     vlan10     
eth0.20      vlan      connected     vlan20     
eth0         ethernet  disconnected  --         
lo           loopback  unmanaged     --         
# nmcli con show
NAME UUID TYPE DEVICE 
vlan20 e10eea8c-ea4e-483a-8ceb-1669d2252106 vlan eth0.20 
vlan10 8275c94d-2dc7-4c6c-95fd-e64caec67850 vlan eth0.10 

Note: You’ve got now two sub-interfaces called eth0.10 and eth0.20.

After this configuration, two new files have been created in the /etc/sysconfig/network-script directory and one removed (ifcfg-eth0):

  • ifcfg-vlan10:
    VLAN=yes
    TYPE=Vlan
    PHYSDEV=eth0
    VLAN_ID=10
    REORDER_HDR=0
    BOOTPROTO=none
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    NAME=vlan10
    UUID=8275c94d-2dc7-4c6c-95fd-e64caec67850
    ONBOOT=yes
    IPADDR=192.168.10.1
    PREFIX=24
    GATEWAY=192.168.10.1
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes
  • ifcfg-vlan20:
    VLAN=yes
    TYPE=Vlan
    PHYSDEV=eth0
    VLAN_ID=20
    REORDER_HDR=0
    BOOTPROTO=none
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    NAME=vlan20
    UUID=e10eea8c-ea4e-483a-8ceb-1669d2252106
    ONBOOT=yes
    IPADDR=192.168.20.1
    PREFIX=24
    GATEWAY=192.168.20.1
    IPV6_PEERDNS=yes
    IPV6_PEERROUTES=yes

Obviously, if you plan to route packets between your two network interfaces, type:

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
# sysctl -p

Note: Additional details about the sysctl command are available in the sysctl tutorial.

(10 votes, average: 4.10 out of 5)
Loading...

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |