例如我的网卡现在是eth2 我想增加一个Vlan为eth2.10
方法一 通过创建配置文件来创建vlan
复制一份eth2的配置文件:
cp /etc/sysconfig/network-scripts/ifcfg-eth2
/etc/sysconfig/network-scripts/ifcfg-eth2.10
修改ifcfg-eth2.10的配置文件
找到 DEVICE=eth2改为:DEVICE=eth2.10
添加:VLAN=yes
编辑配置文件 vi /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2.10
HWADDR=1E:C5:72:60:01:65
TYPE=Ethernet
UUID=d20a5cd4-9d06-4288-a007-cfbe098ed6d7
ONBOOT=no
NM_CONTROLLED=yes
BOOTPROTO=dhcp
VLAN=yes
重启网络服务
service network restart
方法二 使用 vconfig 命令
首先安装vconfig工具
yum install -y vconfig
vconfig add eth2 10 #为eth2接口创建vlan10
用下面命令为eth2.10分配ip
ifconfig eth2.10 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255 up
获取Vlan2.10的详细信息:
cat /proc/net/vlan/eth2.10
删除Vlan的方法:
ifconfig eth2.10 down
vconfig rem eth2.10
方法三 使用IP命令创建Vlan
可以使用Ip命令为eth0添加Vlan:
ip link add link eth2 name eth2.10 type vlan id 10
ip link
ip -d link show eth2.10
分配IP并设置启动:
ip addr add 192.168.1.200/24 brd 192.168.1.255 dev eth2.10
ip link set dev eth2.10 up
删除命令:
ip link set dev eth2.10 down
ip link delete eth2.10