使用设置文件进行设置
在etc/sysconfig/network-scripts/下准备好eth0.100用的配置文件,系统启动时就可以自动生成VLAN接口。请设置DEVICE=VLAN接口名,并设置为VLAN=yes。
cat ifcfg-eth0.100
DEVICE=eth0.100
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.100
ONBOOT=yes
VLAN=yes
VLAN_PLUS_VID、VLAN_PLUS_VID_NO_PAD的VLAN接口需要设置为VLAN=yes,并在PHYSDEV=后面写入物理网络接口名。
cat ifcfg-vlan002
DEVICE=vlan002
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.1.102
ONBOOT=yes
VLAN=yes
PHYSDEV=eth0
准备eth0.001用和vlan3用的配置文件,然后执行ifup命令,内核中就能够正常识别这些VLAN接口。
cat ifcfg-eth0.001
DEVICE=eth0.001
……
VLAN=yes
cat ifcfg-vlan3
DEVICE=vlan3
……
VLAN=yes
PHYSDEV=eth0
ifup eth0.001
ifup vlan002
ifup vlan3
cat/proc/net/vlan/confg
VLAN Dev name|VLAN ID
Name-Type:VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
eth0.001|1|eth0
vlan002|2|eth0
vlan3|3|eth0
ifconfg
eth0 Link encap:Ethernet HWaddr 00:1B:21:0F:91:8F
inet addr:192.168.3.100 Bcast:192.168.3.255 Mask:255.255.255.0 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
……
eth0.001 Link encap:Ethernet HWaddr 00:1B:21:0F:91:8F
inet addr:192.168.1.101 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
……
vlan002 Link encap:Ethernet HWaddr 00:1B:21:0F:91:8F
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
……
vlan3 Link encap:Ethernet HWaddr 00:1B:21:0F:91:8F
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
……