LINUX.ORG.RU

История изменений

Исправление h578b1bde, (текущая версия) :

Спасибо за ссылку. Прописал таблицы T1 и T2 в /etc/iproute2/rt_tables, наговнокодил на скорую руку скрипт:

#!/bin/sh
# http://www.opennet.ru/tips/info/1179.shtml

iface1=tun1
iface2=bond0

iface1_ip=$(ifconfig "${iface1}" | grep 'inet addr:' | cut -d':' -f2 | cut -d' ' -f1)
iface1_gw=$(ifconfig "${iface1}" | grep 'P-t-P:'     | cut -d':' -f3 | cut -d' ' -f1)

iface2_ip=$(ifconfig "${iface2}" | grep 'inet addr:' | cut -d':' -f2 | cut -d' ' -f1)
iface2_gw=$(route -n | awk -v iface="${iface2}" '{if ($8 == iface && $2 != "0.0.0.0") print $2;}' | head -n 1)

while [ -z "${iface1_ip}" ] || [ -z "${iface2_ip}" ]; do
        sleep 10s
done

routes()
        {
        ip route "${1}" default via "${iface1_gw}" table T1
        ip route "${1}" default via "${iface2_gw}" table T2
        ip route "${1}" default via "${iface1_gw}"
        ip rule "${1}" from "${iface1_ip}" table T1
        ip rule "${1}" from "${iface2_ip}" table T2
        }

case "${1}" in
        up)
                routes 'add'
                ;;
        down)
                routes 'del'
                ;;
        *)
                echo "${iface1}\nIP:\t${iface1_ip}\nGW:\t${iface1_gw}\n"
                echo "${iface2}\nIP:\t${iface2_ip}\nGW:\t${iface2_gw}\n"
                ;;
esac
В конфиг клиента OpenVPN засунул опции
script-security 2
up   "'/somepath/gateways.sh' up"
down "'/somepath/gateways.sh' down"
Вроде работает.

Исходная версия h578b1bde, :

Спасибо за ссылку. Прописал таблицы T1 и T2 в /etc/iproute2/rt_tables, наговнокодил на скорую руку скрипт:

#!/bin/sh
# http://www.opennet.ru/tips/info/1179.shtml

iface1=tun1
iface2=bond0

iface1_ip=$(ifconfig "${iface1}" | grep 'inet addr:' | cut -d':' -f2 | cut -d' ' -f1)
iface1_gw=$(ifconfig "${iface1}" | grep 'P-t-P:'     | cut -d':' -f3 | cut -d' ' -f1)

iface2_ip=$(ifconfig "${iface2}" | grep 'inet addr:' | cut -d':' -f2 | cut -d' ' -f1)
iface2_gw=$(route -n | awk -v iface="${iface2}" '{if ($8 == iface && $2 != "0.0.0.0") print $2;}' | head -n 1)

while [ -z "${iface1_ip}" ] || [ -z "${iface2_ip}" ]; do
        sleep 10s
done

case "${1}" in
        up)
                ip route add default via "${iface1_gw}" table T1
                ip route add default via "${iface2_gw}" table T2
                ip route add default via "${iface1_gw}"
                ip rule add from "${iface1_ip}" table T1
                ip rule add from "${iface2_ip}" table T2
                ;;
        down)
                ip route del default via "${iface1_gw}" table T1
                ip route del default via "${iface2_gw}" table T2
                ip route del default via "${iface1_gw}"
                ip rule del from "${iface1_ip}" table T1
                ip rule del from "${iface2_ip}" table T2
                ;;
        *)
                echo "${iface1}\nIP:\t${iface1_ip}\nGW:\t${iface1_gw}\n"
                echo "${iface2}\nIP:\t${iface2_ip}\nGW:\t${iface2_gw}\n"
                ;;
esac
В конфиг клиента OpenVPN засунул опции
script-security 2
up   "'/somepath/gateways.sh' up"
down "'/somepath/gateways.sh' down"
Вроде работает.