vconfig 命令允许您在启用 vlan 的内核的 Linux 上创建和删除 vlan 设备。vlan 设备是一种虚拟的 以太网设备,代表了物理局域网中的虚拟局域网。
安装
CentOS
yum install -y vconfig
Ubuntu
apt-get install vlan
加载内核
$ modprobe 8021q
$ lsmod |grep -i 8021q
示例
在ens33添加两个VLAN
$ vconfig add ens33 100
Added VLAN with VID == 100 to IF -:ens33:-
# 设置 REORDER_HDR 参数
$ vconfig set_flag ens33.100 1 1
Set flag on device -:ens33.100:- Should be visible in /proc/net/vlan/ens33.100
$ vconfig add ens33 200
Added VLAN with VID == 200 to IF -:ens33:-
$ vconfig set_flag ens33.200 1 1
Set flag on device -:ens33.200:- Should be visible in /proc/net/vlan/ens33.200
配置网络信息
启用网络,不配置ip
ip link set ens33.100 up
ip link set ens33.200 up
启用网络,配置ip
ip addr add 10.0.1.1/24 dev ens33.100
ip link set ens33.100 up
ip addr add 10.0.2.1/24 dev ens33.200
ip link set ens33.200 up
删除VLAN
$ vconfig rem ens33.100
Removed VLAN -:ens33.100:-
$ vconfig rem ens33.200
Removed VLAN -:ens33.200:-
We use cookies and similar methods to recognise visitors and remember preferences. We also use them to measure
campaign effectiveness and analyse site traffic.
By selecting 'Accept', you consent to the use of these methods by us and trusted third parties.