VLAN configuration for Linux network cards

Source: Internet
Author: User
Tags dmesg

If the port on the server has a pre-set trunk and allows certain VLANs to pass, then the server's network adapter must specify the VLAN it belongs to when it is configured, otherwise it will not work, which is more common in virtualized deployments.

For example, in an office environment, the Office VLAN is 1020, the virtual physical host has two million gigabit network card, 3111 and 3112VLAN, which can be interconnected between the three VLANs, then how to configure it?

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6B/8E/wKiom1UwlybDrobzAACnGvfptco560.jpg "title=" 111. JPG "alt=" wkiom1uwlybdrobzaacngvfptco560.jpg "/>

a . The first thing to confirm Does the Linux system kernel already support VLAN functionality:

Currently using kernel and OS version:

[Email protected] ~]# cat/etc/redhat-release

Red Hat Enterprise Linux Server release 6.5 (Santiago)

First yum installs the Vconfig, if there is no need to install

Yum Install Vconfig

See if the core provides VLAN functionality, performing

DMESG | Grep-i 802

[[Email protected]]# DMESG | Grep-i 802

802.1Q VLAN Support v1.8 Ben greear<[email protected]>

[Email protected]]# modprobe 8021q

[[Email protected]~] #lsmod |grep 8021q// See if the system kernel supports the 802.1q protocol

8021q 18633 0

[[email protected] ~]# LSPCI// Verify that the NIC driver is loaded properly

00:00.0 host Bridge:intel Corporation 440BX/ZX/DX-82443BX/ZX/DX host Bridge (Rev. 01)

00:01.0 PCI Bridge:intel Corporation 440bx/zx/dx-82443bx/zx/dx AGP Bridge (Rev. 01)

00:07.0 Isa Bridge:intel Corporation 82371ab/eb/mb PIIX4 Isa (Rev. 08)

00:07.1 IDE Interface:intel Corporation 82371ab/eb/mb PIIX4 IDE (Rev. 01)

00:07.3 Bridge:intel Corporation 82371ab/eb/mb PIIX4 ACPI (rev. 08)

00:07.7 System peripheral:vmware Virtual Machine Communication Interface (rev 10)

00:0f.0 VGA compatible Controller:vmware SVGA II Adapter

00:11.0 PCI Bridge:vmware PCI bridge (rev. 02)

00:15.0 PCI bridge:vmware PCI Express Root Port (rev. 01)

00:15.1 PCI bridge:vmware PCI Express Root Port (rev. 01)

00:15.2 PCI bridge:vmware PCI Express Root Port (rev. 01)

two . physical network card, sub-network card, virtual VLAN nic Relationship:

1. Physical network card: Physical network card here refers to the actual interface device on the server, can be seen in the system, such as 2 physical network cards corresponding to the eth0 and eth1 the two network interfaces.

2. Sub-network card: Sub-network card is not the actual network interface device, but can be used as a network interface in the system, such as eth0:1,eth1:2 This network interface. They must depend on the physical network card, although the network interface with the physical network card can exist in the system and use different IP addresses, but also have their own network interface configuration files. However, when the dependent physical network card is not enabled (down State) These sub-cards will not work together.

3. virtual VLAN NIC: these virtual VLAN NICs are not actually network interface devices or can appear as network interfaces in the system, but unlike sub-NICs, they do not have their own configuration files. They are simply VLAN virtual NICs that are generated by adding a physical network to different VLANs . If a physical network card is added to multiple VLANs , there will be multiple VLAN virtual network cards, and their information and related VLAN information are stored in the/proc/net/vlan/ Config in this temporary file, without the configuration file alone. Their network interface name is the name eth0.1,eth1.2 .

Note: When you need to enable VLAN Virtual network card when working, the associated physical NIC network interface must not have the configuration information for the IP address.

[Email protected] ~]# vi/etc/sysconfig/network-scripts/ifcfg-eth1

————————————————–

Device=eth1

Onboot=yes

Bootproto=static

set static address and do not give IP address settings.

third, in Linux configuration VLAN Trunk:

since the Linux eth1 is set to Trunk andbelongs to a specific 3111VLAN. The eth2 is also set to Trunk andbelongs to a specific 3112VLAN.

1. Add the eth1 to the VLAN 3111 :

[[Email protected]]# vconfig Add eth1 3111

Warning:could not open/proc/net/vlan/config. Maybe need to load the 8021q module, or maybe youare not using PROCFS??

Added VLAN with VID = = 3111 to IF-:eth1:-

First time Add VLAN Virtual network card when it is bound to appear above that sentence, the reason is because the default /proc/net/vlan/config this dedicated to save VLAN information file is not. The first time you add a VLAN nic, the file will be automatically created as well. In addition, the files under the/proc/directory are temporary files for the system, so it is necessary to lose rest after the reboot, so after configuring and testing the VLAN successfully, you can add some related commands to the rc.local This startup script. Before executing this command, you can go to the/proc/net/ directory to see, there is no VLAN folder, after execution will create a VLAN folder, and Generate config configuration file, As well as the corresponding virtual VLAN NIC configuration file eth1.3111 and so on.


2. also add eth2 to the VLAN3112 :

[[email protected] ~]# vconfig add eth2 3112

Added VLAN with VID = = 3112 to IF-:eth2:-


3. Check the VLAN virtual NIC information added:

[Email protected] ~]# Cat/proc/net/vlan/config

--------------------------------------------------

VLAN Dev Name | VLAN ID

Name-type:vlan_name_type_raw_plus_vid_no_pad

eth1.3111 |      3111 | Eth1

eth2.3112 |      3112 | Eth2

can see all the VLAN Virtual network cards and the primary physical network card to which they belong.

(can also be configured as files ifcfg-eth1.3111 and ifcfg-eth1.3112 if there is only one physical network card)


4. to be VLAN Virtual NIC sets the IP address and enables:

[Email protected] ~]# ifconfig eth1.3111 192.168.20.1 up

[Email protected] ~]# ifconfig eth2.3112 192.168.30.1 up

It's temporary, you can do it.

Copy the IP address configuration of the interface using the CP command

CP Ifcfg-eth1 ifcfg-eth1.3111

CP Ifcfg-eth2 ifcfg-eth2.3112

Ifcfg-eth1 and Ifcfg-eth2 in the original address removed, and then VI Modify ifcfg-eth1.3111 and ifcfg-eth2.3112 files, set the IP address and other information.

5. finally restart the network service to make the configuration effective.

Restart Network Service

[Email protected] ~]# service network restart

--------------------------------------------------

Shutting down interface eth1: [OK]

Shutting down interface eth2: [OK]

Shutting down loopback interface: [OK]

Bringing up loopback interface: [OK]

Bringing Up interface eth1: [OK]

Bringing Up interface eth2: [OK]

--------------------------------------------------

6. Check all the network interface information under the Linux system:

[Email protected] ~]# ifconfig |more

to here has basically been going The main configuration of the VLAN is complete.


7. Verification of Connectivity

[[email protected] ~]# Ping 192.168.20.254

PING 192.168.20.254 (192.168.20.254) bytes of data.

Bytes from 192.168.20.254:icmp_seq=1 ttl=255 time=8.42 ms

Bytes from 192.168.20.254:icmp_seq=2 ttl=255 time=1.47 ms

Bytes from 192.168.20.254:icmp_seq=3 ttl=255 time=1.51 ms

Bytes from 192.168.20.254:icmp_seq=4 ttl=255 time=1.58 ms

^c

---192.168.20.254 ping statistics---

4 packets transmitted, 4 received, 0% packet loss, time 6325ms

RTT Min/avg/max/mdev = 1.470/2.550/8.427/2.400 ms


[[email protected] ~]# Ping 192.168.30.254

PING 192.168.30.254 (192.168.30.254) bytes of data.

Bytes from 192.168.30.254:icmp_seq=1 ttl=255 time=8.42 ms

Bytes from 192.168.30.254:icmp_seq=2 ttl=255 time=1.47 ms

Bytes from 192.168.30.254:icmp_seq=3 ttl=255 time=1.51 ms

Bytes from 192.168.30.254:icmp_seq=4 ttl=255 time=1.58 ms

^c

---192.168.30.254 ping statistics---

4 packets transmitted, 4 received, 0% packet loss, time 6325ms

RTT Min/avg/max/mdev = 1.470/2.550/8.427/2.400 ms


This article is from the "Hollows Jie Sun" blog, be sure to keep this source http://xjsunjie.blog.51cto.com/999372/1633815

VLAN configuration for Linux network cards

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.