#!/bin/sh # script for making sure networking of each vserver guest has the correct # routing rules. # # how do we do it? # - in /etc/iproute2/rt_tables, we add a -net line for each of the # networks our guests are on # eg. 100 eth0.49-net # i also use vlan trunking on the vserver machines, hence the .49 ;) # - we make sure we have the ipcalc program installed so we can calculate # our network/gateway (as this script needs it) # - put this script (together with post-stop) in # ${PREFIX}/etc/vservers/.defaults/scripts so that it gets exectuted before the # guests start # - result: when you add more ip's to the guest in the same network, you'll # see some "errors" which you can ignore, they are just saying you allready # have a route for that network defined , but we know that, we just want to # make SURE that it's there for every ip of the guest # # is it useful/stable? # we use it for all our vservers at the KULeuven, without problems, # so i guess you can say it's pretty reliable # it also makes routing for each guest "more logical" and "separated" # and how is that? hard to explain, just ask on irc, and i'll give it a shot # # is it perfect? # well... no, you could make a routing table for each virtual host too # but i just chose to do it this way. less tables, works as good as the other # # greetz and have fun with it # harry PREFIX=/usr/local HOSTNAME=$2 for a in ${PREFIX}/etc/vservers/${HOSTNAME}/interfaces/* do IF=`cat ${a}/dev` IP=`cat ${a}/ip` NETMASK=`cat ${a}/prefix` GW=`ipcalc -n $IP $NETMASK |grep "HostMax:"| awk '{print $2}'` NETWORK=`ipcalc -n $IP $NETMASK |grep "Network:"| awk '{print $2}'` ip route add $NETWORK dev $IF table $IF-net ip route add default via $GW dev $IF table $IF-net ip rule add from $IP/32 table $IF-net pref 1000 done