配置网卡为vlan trunk
http://www.microhowto.info/tutorials/802.1q.html
Configure an Ethernet interface as a VLAN trunk
host需要连接2个 VLANs, 192.168.2.1/24
on VLAN 2 and 192.168.3.1/24
on VLAN 3
# modprobe 8021q # lsmod | grep 8021q
3种方法:
1 通过配置文件
auto eth0.2 iface eth0.2 inet static address 192.168.2.1 netmask 255.255.255.0 auto eth0.3 iface eth0.3 inet static address 192.168.3.1 netmask 255.255.255.0
ifup eth0.2 ifup eth0.3
ifconfig eth0.2 eth0.2 Link encap:Ethernet HWaddr 00:00:00:00:00:00 inet addr:192.168.2.1 Bcast:12.168.2.255 Mask:255.255.255.0 UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
如果需要指定连到那个物理网卡:
auto vlan2 iface vlan2 inet static address 192.168.2.1 netmask 255.255.255.0 vlan-raw-device eth0
http://www.microhowto.info/tutorials/802.1q.html
2 Vconfig
vconfig add eth0 2 vconfig add eth0 3
# ifconfig eth0.2 192.168.2.1 netmask 255.255.255.0 broadcast 192.168.2.255 up # ifconfig eth0.3 192.168.3.1 netmask 255.255.255.0 broadcast 192.168.3.255 up
获取VLAN interface的详细信息
# cat /proc/net/vlan/eth0.5
删除VLAN interface
# ifconfig eth0.5 down # vconfig rem eth0.5
3 通过ip
# ip link add link eth0 name eth0.2 type vlan id 2 # ip link # ip -d link show eth0.2 # ip addr add 192.168.2.1/24 brd 192.168.2.255 dev eth0.2 # ip link set dev eth0.2 up
删除:
# ip link set dev eth0.2 down # ip link delete eth0.2
配置完后,来ping eth0的ip,会发生eth0可以收到并回复,但eth0.2收到但不回复。
http://blog.csdn.net/suiyuan19840208/article/details/8221529