RHEL7.2 配置VLAN连接网络

CONFIGURE 802.1Q VLAN TAGGING USING THE COMMAND LINE

In Red Hat Enterprise Linux 7, the8021qmodule is loaded by default. If necessary, you can make sure that the module is loaded by issuing the following command asroot:

~]#modprobe --first-time 8021qmodprobe: ERROR: could not insert '8021q': Module already in kernel

To display information about the module, issue the following command:

~]$modinfo 8021q

See themodprobe(8)man page for more command options.

7.4.1. Setting Up 802.1Q VLAN Tagging Using ifcfg Files

Configure the parent interface in/etc/sysconfig/network-scripts/ifcfg-ethX, whereXis a unique number corresponding to a specific interface, as follows:

DEVICE=ethX

TYPE=Ethernet

BOOTPROTO=none

ONBOOT=yes

Configure the VLAN interface configuration in the/etc/sysconfig/network-scripts/directory. The configuration file name should be the parent interface plus a.character plus the VLAN ID number. For example, if the VLAN ID is 192, and the parent interface iseth0, then the configuration file name should beifcfg-eth0.192:

DEVICE=ethX.192

BOOTPROTO=none

ONBOOT=yes

IPADDR=192.168.1.1

PREFIX=24

NETWORK=192.168.1.0

VLAN=yes

If there is a need to configure a second VLAN, with for example, VLAN ID 193, on the same interface,eth0, add a new file with the nameeth0.193with the VLAN configuration details.

Restart the networking service in order for the changes to take effect. Asrootissue the following command:

~]#systemctl restart network

7.4.2. Configure 802.1Q VLAN Tagging Using ip Commands

To create an 802.1Q VLAN interface on Ethernet interfaceeth0, with nameVLAN8and ID8, issue a command asrootas follows:

~]#ip link add linketh0nameeth0.8type vlan id 8

To view the VLAN, issue the following command:

~]$ip -d link showeth0.84: eth0.8@eth0: mtu 1500 qdisc noqueue state UP mode DEFAULT    link/ether 52:54:00:ce:5f:6c brd ff:ff:ff:ff:ff:ff promiscuity 0    vlan protocol 802.1Q id 8

Note that theiputility interprets the VLAN ID as a hexadecimal value if it is preceded by0xand as an octal value if it has a leading0. This means that in order to assign a VLAN ID with a decimal value of22, you must not add any leading zeros.

To remove the VLAN, issue a command asrootas follows:

~]#ip link deleteeth0.8

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容