#! /bin/bash
getip() {
ifconfig $1 |grep -o -e ‘inet addr:[^ ]*‘ | grep -o -e ‘[^:]*$‘
}
ip link add link br0 address 00:16:3e:10:24:72 dev veth0 type macvlan
ip link add link br0 address 00:16:3e:10:24:73 dev veth1 type macvlan
ip link add link br0 address 00:16:3e:10:24:74 dev veth2 type macvlan
dhclient veth0 veth1 veth2
IPROUTE_ARGS=""
for((i=0;i<3;++i)); do
for ((j=0;j<15;++j)); do
IP="$(getip veth$i)"
[[ -n $IP ]] && break
sleep 3
done
[[ -z $IP ]] && continue
GATEWAY="${IP%.[0-9]*}.254"
ip route add default via $GATEWAY dev veth$i table veth$i
ip rule add from $IP table veth$i
IPROUTE_ARGS=$IPROUTE_ARGS" nexthop via "$GATEWAY" dev veth"$i" weight 1"
done
ip route replace default scope global equalize $IPROUTE_ARGS
原文:http://www.cnblogs.com/esxgx/p/5022794.html