2021-09-28

Linux 配置VLAN

本节以CentOS Linux release 7.9.2009 (Core)系统为例,介绍在OS 下配置VLAN 方法

(1)加载802.1q 模块,modprobe 8021q

[root@localhost ~]# modprobe 8021q
[root@localhost ~]# modinfo 8021q
filename:       /lib/modules/3.10.0-1160.25.1.el7.x86_64/kernel/net/8021q/8021q.ko.xz
version:        1.8
license:        GPL
alias:          rtnl-link-vlan
retpoline:      Y
rhelversion:    7.9
srcversion:     1DD872AF3C7FF7FFD5B14D5
depends:        mrp,garp
intree:         Y
vermagic:       3.10.0-1160.25.1.el7.x86_64 SMP mod_unload modversions 
signer:         CentOS Linux kernel signing key
sig_key:        66:86:A0:85:9C:1D:7F:F2:2A:92:8D:A4:A4:42:1E:2D:9B:5A:B3:69
sig_hashalgo:   sha256

(2)在物理接口上创建VLAN接口,ip link add link ethX name ethX.id type vlan id id

[root@localhost ~]# ip link add link ens33 name ens33.2 type vlan id 2

(3)查看VLAN 接口是否创建成功,ip –d link show ethX.id

[root@localhost ~]# ip -d link show ens33.2
5: ens33.2@ens33: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:38:b9:97 brd ff:ff:ff:ff:ff:ff promiscuity 0 
    vlan protocol 802.1Q id 2 <REORDER_HDR> addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 

(4)给VLAN 接口配置IP

[root@localhost ~]# ip addr add 192.168.50.100/24 brd 192.168.50.255 dev ens33.2

(5)启动VLAN接口

ip link set dev ens33.2 up

(6)查看VLAN接口的网卡

2021-09-28

执行“ip link set dev ethX.id down”和“ip link delete ethX.id”命令可以删除VLAN 接口。

上一篇:Linux系统的安装、启动与远程连接


下一篇:leetcode-Algorithms-1480|一维数组的动态和