分类: LINUX
2010-09-09 16:37:08
1. 创建网桥
[root@localhost ~]# brctl addbr xenvbr11
[root@localhost ~]# brctl stp xenvbr11 off
[root@localhost ~]# brctl setfd xenvbr11 0 //set forward delay time
[root@localhost ~]# ip link set xenvbr11 up
2. 创建vlan
[root@localhost ~]# vconfig set_name_type DEV_PLUS_VID_NO_PAD
[root@localhost ~]#vconfig add peth0 11 //在peth0上创建vlan
[root@localhost ~]# ip link set peth0.11 address fe:ff:ff:ff:ff:ff
[root@localhost ~]# ip link set peth0.11 up
3. 把vlan加入到网桥中
[root@localhost ~]# brctl addif xenvbr11 peth0.11
4. 创建端口配置文件
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cat ifcfg-peth0.11
DEVICE=peth0.11
TYPE=Ethernet
ONBOOT=yes
MACADDR=fe:ff:ff:ff:ff:ff
VLAN=yes
IPADDR=192.168.5.1
NETMASK=255.255.255.0
VLAN_NAME_TYPE=DEV_PLUS_VID_NO_PAD
BRIDGE=xenvbr11
[root@localhost network-scripts]# cat ifcfg-xenvbr11
DEVICE=xenvbr11
TYPE=Bridge
DELAY=0
STP=off
ONBOOT=yes
[root@localhost ~]# cat /etc/init.d/xenvlansetup
#!/bin/bash
#
# xenvlansetup Script to start and stop the Xen vlan .
#
#
# chkconfig: 2345 98 02
# description: Starts and stops the Xen vlan.
# Source function library.
. /etc/rc.d/init.d/functions
RETVAL=0
case "$1" in
start)
xenbridge=`brctl show | grep xenvbr | awk '($4 == ""){print $1}' 2>&1`
for bridge in $xenbridge
do
device="peth0"
vlanId=${bridge:6}
vlanDevice="peth0.${vlanId}"
vconfig add $device $vlanId 2>&1
ip link set $vlanDevice address fe:ff:ff:ff:ff:ff 2>&1
ip link set $vlanDevice up 2>&1
brctl addif $bridge $vlanDevice 2>&1
done
;;
stop)
;;
status)
;;
*)
exit 1
esac
exit $RETVAL
[root@localhost ~]# chmod +x /etc/init.d/xenvlansetup
[root@localhost ~]# chkconfig --add xenvlansetup