在linux下,只要系统内核支持,则可以利用vconfig管理vlan虚拟设备
1、先检查环境
lsmod | grep 8021q 8021q 29022 0 garp 14384 1 8021q mrp 18542 1 8021q
2、安装 vconfig
yum install -y vconfig
3、配置vlan接口
比如,在eth2口配置vlan 2202
vconfig add eth2 2202 Added VLAN with VID == 2202 to IF -:eth2:-
把该接口拉起,并设置IP
ip link set dev eth2.2202 up 207: eth2.2202@eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether fe:fc:fe:68:1c:78 brd ff:ff:ff:ff:ff:ff ip a add 192.168.202.101/24 dev eth2.2202 207: eth2.2202@eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP link/ether fe:fc:fe:68:1c:78 brd ff:ff:ff:ff:ff:ff inet 192.168.202.101/24 scope global eth2.2202 valid_lft forever preferred_lft forever inet6 fe80::fcfc:feff:fe68:1c78/64 scope link tentative valid_lft forever preferred_lft forever
当然,也可以使用ifconfig命令,一行命令拉起并设置ip
ifconfig eth2.2202 192.168.202.101 netmask 255.255.255.0 broadcast 192.168.202.255 up
至此,vlan环境配置成功,从该接口发出的数据包带有vlan2202标签。
4、删除vlan
删除命令如下
ip link set eth2.2202 down
vconfig rem eth2.2202
时间: 2024-10-25 03:11:30