In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to configure the vlan of the linux network card". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to configure the vlan of the linux network card"!
If the switch port connected to the server is pre-set with TRUNK and allows a specific VLAN to pass through, then the server's network card must specify the VLAN to which it belongs, otherwise it will not work, which is common in virtualized deployment.
For example, in an office environment, the VLAN of the office is 1020, and there are two 10 Gigabit network cards on the virtualized physical host, belonging to 3111 and 3112VLAN, and the three VLAN can communicate with each other, so how to configure it?
one。 First, make sure that the Linux kernel already supports the VLAN feature:
Currently using kernel and operating system versions:
[root@test ~] # cat / etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
First of all, yum installs vconfig. If you have it, you don't have to install it.
Yum install vconfig
Check whether the core provides VLAN function, and execute
Dmesg | grep-I 802
[root@test] # dmesg | grep-I 802
802.1Q VLAN Support v1.8 Ben Greear
[root@test] # modprobe 8021q
[root@test~] # lsmod | grep 8021q / / check whether the system kernel supports 802.1q protocol
8021q 18633 0
[root@test ~] # lspci / / confirm whether the Nic driver has been loaded normally
00Rom 00.0 Host bridge: Intel Corporation 440BX/ZX/DX-82443BX/ZX/DX Host bridge (rev 01)
00Rom 01.0 PCI bridge: Intel Corporation 440BX/ZX/DX-82443BX/ZX/DX AGP bridge (rev 01)
00Rom 07.0 ISA bridge: Intel Corporation 82371AB/EB/MB PIIX4 ISA (rev 08)
00VR 07.1 IDE interface: Intel Corporation 82371AB/EB/MB PIIX4 IDE (rev 01)
00rev 07.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 ACPI (rev 08)
00Rom 07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00RU 11.0 PCI bridge: VMware PCI bridge (rev 02)
00RU 15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
0015. 1 PCI bridge: VMware PCI Express Root Port (rev 01)
00RV 15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
two。 The relationship between physical Nic, sub-Nic, and virtual VLAN Nic:
1. Physical network card: physical network card here refers to the actual network interface devices on the server, which can be seen in the system, for example, two physical network cards correspond to eth0 and eth2 network interfaces respectively.
two。 Subnet card: the subnet card is not actually a network interface device here, but it can appear in the system as a network interface, such as eth0:1 and eth2:2. They must rely on physical network cards, although they can exist and use different IP addresses in the system at the same time as the network interfaces of physical network cards, and they also have their own network interface profiles. However, when the dependent physical network card is not enabled (Down status), these sub-network cards will not work together.
3. Virtual VLAN network cards: these virtual VLAN network cards are not actual network interface devices, and can also appear in the system as network interfaces, but unlike sub-network cards, they do not have their own configuration files. They are just VLAN virtual network cards generated by adding physical networks to different VLAN. If you add a physical network card to multiple VLAN, multiple VLAN virtual network cards will appear, and their information and related VLAN information will be saved in the temporary file / proc/net/vlan/config, instead of a separate configuration file. Their network interface names are eth0.1 and eth2.2.
Note: when you need to enable the VLAN virtual network card to work, the associated physical network card network interface must not have the configuration information of the IP address.
[root@test ~] # vi/etc/sysconfig/network-scripts/ifcfg-eth2
-
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=static
Set the static address and do not set the IP address.
3. Configure VLAN Trunk in Linux:
Because eth2 is set to Trunk on Linux and belongs to a specific 3111VLAN. Eth3 should also be set to Trunk and belong to a specific 3112VLAN.
1. Add eth2 to VLAN 3111:
[root@test] # vconfig add eth2 3111
WARNING: Could not open/proc/net/vlan/config. Maybe you need to load the 8021q module, or maybe youare not using PROCFS??
Added VLAN with VID = = 3111 to IF -: eth2:-
The above prompt must appear the first time you add a VLAN virtual network card, because the file / proc/net/vlan/config, which is used specifically to save VLAN information, is not available by default. Since the VLAN network card is added for the first time, this file will also be created automatically. In addition, the files under the / proc/ directory are temporary files of the system, so you must lose your rest after rebooting, so after configuring and testing VLAN successfully, you can add some related commands to the startup script rc.local. Before executing the command, you can go to the / proc/net/ directory to check, there is no vlan folder, after execution will create a vlan folder and generate a config configuration file, as well as the corresponding virtual vlan network card configuration file eth2.3111 and so on.
two。 Also add eth3 to VLAN3112:
[root@test ~] # vconfig add eth3 3112
Added VLAN with VID = = 3112 to IF -: eth3:-
3. Check the added VLAN virtual Nic information:
[root@test ~] # cat/proc/net/vlan/config
VLAN Dev name | VLAN ID
Name-Type:VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
Eth2.3111 | 3111 | eth2
Eth3.3112 | 3112 | eth3
You can see all the VLAN virtual network cards and the primary physical network cards to which they belong.
(if there is only one physical network card, it can also be configured as files ifcfg-eth2.3111 and ifcfg-eth2.3112)
4. Set the IP address for the VLAN virtual network card and enable it:
[root@test ~] # ifconfig eth2.3111 192.168.20.1 up
[root@test ~] # ifconfig eth3.3112 192.168.30.1 up
It's temporary. It can be done.
Use the cp command to copy the ip address configuration of the interface
Cp ifcfg-eth2 ifcfg-eth2.3111
Cp ifcfg-eth3 ifcfg-eth3.3112
Remove the original address in ifcfg-eth2 and ifcfg-eth3, then vi modify ifcfg-eth2.3111 and ifcfg-eth3.3112 files, set IP address and other information.
5. Finally, restart the network service to make the configuration effective.
Restart the network service
[root@test ~] # service network restart
Shutting down interface eth2: [OK]
Shutting down interface eth3: [OK]
Shutting down loopback interface: [OK]
Bringing up loopback interface: [OK]
Bringing up interface eth2: [OK]
Bringing up interface eth3: [OK]
6. Check all network interface information under the Linux system:
[root@test ~] # ifconfig | more
So far, you have basically completed the main configuration of VLAN.
7. Verify connectivity
[root@test ~] # ping 192.168.20.254
PING 192.168.20.254 (192.168.20.254) 56 (84) bytes of data.
64 bytes from 192.168.20.254: icmp_seq=1 ttl=255 time=8.42 ms
64 bytes from 192.168.20.254: icmp_seq=2 ttl=255 time=1.47 ms
64 bytes from 192.168.20.254: icmp_seq=3 ttl=255 time=1.51 ms
64 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
[root@test ~] # ping 192.168.30.254
PING 192.168.30.254 (192.168.30.254) 56 (84) bytes of data.
64 bytes from 192.168.30.254: icmp_seq=1 ttl=255 time=8.42 ms
64 bytes from 192.168.30.254: icmp_seq=2 ttl=255 time=1.47 ms
64 bytes from 192.168.30.254: icmp_seq=3 ttl=255 time=1.51 ms
64 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
At this point, I believe you have a deeper understanding of "how to configure the vlan of the linux network card". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 272
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.