Code: Select all
# randomly grab an unused IP from the 10.whatever subnet specific to that instance.
found_one=0
while [ "$found_one" -eq "0" ]; do
# randomly generate the last octet, in the range of 3-254 for each. only last octet cause doin c-class on this box
RANDIP=$POOL.`echo $[ 3 + $[ RANDOM % 251 ]]`
# not taken yet?
if [ ! -r $instance_pool_dir/$RANDIP ]; then
# take it
touch $instance_pool_dir/$RANDIP
# write out the ifconfig line to $1 which is picked up by openvpn
echo "ifconfig-push $RANDIP 255.255.255.0" > $1
found_one=1
fi
done
or multiple clients could get assigned the same IP