#!/bin/bash # /usr/sbin/vznetcfg.custom # a script to bring up bridged network interfaces (veth's) in a VE GLOBALCONFIGFILE=/etc/vz/vz.conf VECONFIGFILE=/etc/vz/conf/$VEID.conf vzctl=/usr/sbin/vzctl ip=/sbin/ip . $GLOBALCONFIGFILE . $VECONFIGFILE NETIF_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#*=}; fi done if [ ! -n "$VETH_IP_ADDRESS" ]; then echo "According to $CONFIGFILE VE$VEID has no veth IPs configured." exit 1 fi if [ ! -n "$VZHOSTIF" ]; then echo "According to $CONFIGFILE VE$VEID has no veth interface configured." exit 1 fi if [ ! -n "$VEIFNAME" ]; then echo "Corrupted $CONFIGFILE: no 'ifname' defined for host_ifname $VZHOSTIF." exit 1 fi for IP in $VETH_IP_ADDRESS; do echo "Initializing interface $VZHOSTIF for VE$VEID." /sbin/ifconfig $VZHOSTIF 0 done VEROUTEDEV=$VZHOSTIF if [ -n "$BRIDGEDEV" ]; then echo "Adding interface $VZHOSTIF to the bridge $BRIDGEDEV." VEROUTEDEV=$BRIDGEDEV /usr/sbin/brctl addif $BRIDGEDEV $VZHOSTIF fi # Up the interface $VEIFNAME link in VE$VEID $vzctl exec $VEID $ip link set $VEIFNAME up for 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 $VEROUTEDEV done if [ -n "$VE0_IP" ]; then echo "Adding a route from VE$VEID to VE0." $vzctl exec $VEID $ip route add $VE0_IP dev $VEIFNAME fi if [ -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 $VEIFNAME fi exit 0