#!/bin/bash# /usr/sbin/vznetcfg.custom# a script to bring up bridged network interfaces (veth's) in a VEGLOBALCONFIGFILE=/etc/vz/vz.confVECONFIGFILE=/etc/vz/conf/$VEID.confvzctl=/usr/sbin/vzctlip=/sbin/ip. $GLOBALCONFIGFILE. $VECONFIGFILENETIF_OPTIONS=`echo $NETIF | sed 's/,/\n/g'`for str in $NETIF_OPTIONS; do \ echo $str # getting 'ifname' parameter value if [[ "$str" =~ ^ifname= ]]; then # remove the parameter name from the string (along with '=') VEIFNAME=${str#*=}; fi # getting 'host_ifname' parameter value if [[ "$str" =~ ^host_ifname= ]]; then # remove the parameter name from the string (along with '=') VZHOSTIF=${str#*=}; fidoneif [ ! -n "$VETH_IP_ADDRESS" ]; then echo "According to $CONFIGFILE VE$VEID has no veth IPs configured." exit 1fiif [ ! -n "$VZHOSTIF" ]; then echo "According to $CONFIGFILE VE$VEID has no veth interface configured." exit 1fiif [ ! -n "$VEIFNAME" ]; then echo "Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF." exit 1fifor IP in $VETH_IP_ADDRESS; do echo "Initializing interface $VZHOSTIF for VE$VEID." /sbin/ifconfig $VZHOSTIF 0doneVEROUTEDEV=$VZHOSTIFif [ -n "$BRIDGEDEV" ]; then echo "Adding interface $VZHOSTIF to the bridge $BRIDGEDEV." VEROUTEDEV=$BRIDGEDEV /usr/sbin/brctl addif $BRIDGEDEV $VZHOSTIFfi# Up the interface $VEIFNAME link in VE$VEID$vzctl exec $VEID $ip link set $VEIFNAME upfor IP in $VETH_IP_ADDRESS; do echo "Adding an IP $IP to the $VEIFNAME for VE$VEID." $vzctl exec $VEID $ip address add $IP dev $VEIFNAME # removing the netmask IP_STRIP=${IP%%/*}; echo "Adding a route from VE0 to VE$VEID." $ip route add $IP_STRIP dev $VEROUTEDEVdoneif [ -n "$VE0_IP" ]; then echo "Adding a route from VE$VEID to VE0." $vzctl exec $VEID $ip route add $VE0_IP dev $VEIFNAMEfiif [ -n "$VE_DEFAULT_GATEWAY" ]; then echo "Setting $VE_DEFAULT_GATEWAY as a default gateway for VE$VEID." $vzctl exec $VEID \ $ip route add default via $VE_DEFAULT_GATEWAY dev $VEIFNAMEfiexit 0