Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Ethernet Card with VLAN tag in CentOS/RHEL system

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

It is believed that many inexperienced people don't know what to do about how to use the Ethernet card with VLAN tag in CentOS/RHEL system. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

In some scenarios, we want to allocate multiple IP from different VLAN on the same Ethernet card (NIC) of the Linux server (CentOS/RHEL). This can be done by using the VLAN tag interface. But to do this, we must make sure that there are multiple VLAN connected to the port of the switch, that is, we can add multiple VLAN to the switch to configure the aggregate port Trunk port. (there are generally aggregate port Trunk port, access port Access port, and hybrid port Hybird port).

Suppose we have a Linux server, where we have two Ethernet cards (enp0s3 and enp0s8). The first card (enp0s3) will be used for data transmission, and the second card (enp0s8) will be used for control / traffic management. I would use multiple VLAN for data transfer (or allocate multiple IP from different VLAN on the data traffic network card).

I assume that the port connecting to the data network card of my server is configured as an aggregation port by mapping multiple VLAN.

The following is the VLAN mapped to the data transfer network card (NIC):

VLAN ID, VLAN Nash W = 172.168.10.0pick 24

VLAN ID, VLAN Nash W = 172.168.20.0 ax 24

To use the VLAN tagging interface in CentOS 7 / RHEL 7 / CentOS 8 / RHEL 8 systems, kernel module 8021q must be loaded.

The following command can be used to load kernel module 8021q:

[root@linuxtechi ~] # lsmod | grep-I 8021q [root@linuxtechi ~] # modprobe-- first-time 8021q [root@linuxtechi ~] # lsmod | grep-I 8021q8021q 29022 0garp 14384 1 8021qmrp 18542 1 8021q [root@linuxtechi ~] #

You can use the modinfo command to display the details of kernel module 8021q:

[root@linuxtechi ~] # modinfo 8021qfilename: / lib/modules/3.10.0-327.el7.x86_64/kernel/net/8021q/8021q.koversion: 1.8license: GPLalias: rtnl-link-vlanrhelversion: 7.2srcversion: 2E63BD725D9DC11C7DA6190depends: mrp Garpintree: Yvermagic: 3.10.0-327.el7.x86_64 SMP mod_unload modversionssigner: CentOS Linux kernel signing keysig_key: 79:AD:88:6A:11:3C:A0:22:35:26:33:6C:0F:82:5B:8A:94:29:6A:B3sig_hashalgo: sha256 [root@linuxtechi ~] #

Now use the ip command to mark (or map) the VLAN of200and300 on the enp0s3 network card.

(LCTT translation note: this is to map the enp0s3 network card with a 200th VLAN tag first. )

[root@linuxtechi] # ip link add link enp0s3 name enp0s3.200 type vlan id 200

Open the interface using the following ip command:

[root@linuxtechi ~] # ip link set dev enp0s3.200 up

In the same way, map the VLAN tag of 300 to the enp0s3 Nic:

[root@linuxtechi ~] # ip link add link enp0s3 name enp0s3.300 type vlan id 300 [root@linuxtechi ~] # ip link set dev enp0s3.300 up

Now use the ip command to view the status of the marked interface:

Tagged-interface-ip-command

Now we can use the following ip command to assign IP addresses to the tagged interfaces from their respective VLAN:

[root@linuxtechi ~] # ip addr add 172.168.10.51 dev enp0s3.200 24 dev enp0s3.200 [root@linuxtechi ~] # ip addr add 172.168.20.51 24 dev enp0s3.300

Use the following ip command to see if the tagged interface is assigned to the IP:

Ip-address-tagged-nic

After reboot, all of the above changes through the ip command will not be maintained. (LCTT note: after modification, it can be saved to the configuration file or database. If it is not saved, only the current environment takes effect, and the configuration becomes invalid after reboot.) These tagged interfaces will not be available after system restart and network service restart (LCTT service network restart, or down and up commands).

Therefore, to keep the marked interface unchanged after reboot, you need to use the interface's ifcfg file.

Edit the interface (enp0s3) file / etc/sysconfig/network-scripts/ifcfg-enp0s3 and add the following:

Author's reminder: replace with the interface name in your environment.

[root@linuxtechi ~] # vi / etc/sysconfig/network-scripts/ifcfg-enp0s3TYPE=EthernetDEVICE=enp0s3BOOTPROTO=noneONBOOT=yes

Save and exit the file.

Create the interface file / etc/sysconfig/network-scripts/ifcfg-enp0s3.200 for the VLAN whose id is 200and add the following:

[root@linuxtechi ~] # vi / etc/sysconfig/network-scripts/ifcfg-enp0s3.200DEVICE=enp0s3.200BOOTPROTO=noneONBOOT=yesIPADDR=172.168.10.51PREFIX=24NETWORK=172.168.10.0VLAN=yes

Save and exit this file.

Similarly, create an interface file / etc/sysconfig/network-scripts/ifcfg-enp0s3.300 for the VLAN whose id is 300, and add the following:

[root@linuxtechi ~] # vi / etc/sysconfig/network-scripts/ifcfg-enp0s3.300DEVICE=enp0s3.300BOOTPROTO=noneONBOOT=yesIPADDR=172.168.20.51PREFIX=24NETWORK=172.168.20.0VLAN=yes

Save and exit the file, and restart the network service using the following command

[root@linuxtechi ~] # systemctl restart network

Now use the following ip command to verify that the marked interface is configured, up, and running:

Tagged-interface-status-ip-command-linux-server

After reading the above, have you learned how to use the Ethernet card with VLAN tag in the CentOS/RHEL system? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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: 0

*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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report