#!/bin/sh
export IF1="eth1";
export IP1="192.168.50.240";
export P1="192.168.50.1";
export P1_NET="192.168.50.0";
export IF2="eth1:0";
export IP2="192.168.60.240";
export P2="192.168.60.1";
export P2_NET="192.168.60.0";
export IF0="eth1:1";
export P0_NET="192.168.40.0";
# Das habe ich auch schon probiert:
#export IF0="lo";
#export P0_NET="127.0.0.1";
ip route delete default;
ip route delete default;
ip route add $P1_NET dev $IF1 src $IP1 table T1;
ip route add default via $P1 table T1;
ip route add $P2_NET dev $IF2 src $IP2 table T2;
ip route add default via $P2 table T2;
ip route add $P1_NET dev $IF1 src $IP1;
ip route add $P2_NET dev $IF2 src $IP2;
ip rule add from $IP1 table T1;
ip rule add from $IP2 table T2;
ip route add $P0_NET dev $IF0 table T1;
ip route add $P2_NET dev $IF2 table T1;
ip route add 127.0.0.0/8 dev lo table T1;
ip route add $P0_NET dev $IF0 table T2;
ip route add $P1_NET dev $IF1 table T2;
ip route add 127.0.0.0/8 dev lo table T2;
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 nexthop via $P2 dev $IF2 weight 1
echo "done.";
ip route flush cache
exit
Was auch anstandslos genommen wird.
Jedoch kann eine 2te Maschiene mit IP 192.168.40.10 und Gateway 192.168.40.1
zwar auf die 40.1 pingen aber kommt nicht ins Internet.
Die Maschine selber (wget ping... gehen alle über eth1)
#!/bin/sh -e
#
# rc.local
#
route del default
route del default
route del default
ip route add default scope global nexthop via 192.168.50.1 nexthop via 192.168.60.1
nohup /usr/sbin/gwping &
exit 0
/usr/sbin/gwping (musst du erstellen und mit root:root 0755 belegen)
#!/bin/bash
#Copyright Angsuman Chakraborty, Taragana. Permission is granted for personal, non-commercial use.
#The script may not be re-distributed in any form without written permission from Angsuman Chakraborty ( angsuman@taragana.com ).
#The script may be modified for personal use.
#THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHOR ACCEPTS NO RESPONSIBILITY IN ANY CONCEIVABLE MANNER.
# Conventionally 0 indicates success in this script.
# Time between checks in seconds
SLEEPTIME=10
#IP Address or domain name to ping. The script relies on the domain being
#pingable and always available
TESTIP=www.switch.ch
#Ping timeout in seconds
TIMEOUT=2
# External interfaces
EXTIF1=eth0
EXTIF2=eth0
#IP address of external interfaces. This is not the gateway address.
IP1=192.168.50.250
IP2=192.168.60.250
#Gateway IP addresses. This is the first (hop) gateway, could be your router IP
#address if it has been configured as the gateway
GW1=192.168.50.1
GW2=192.168.60.1
# Relative weights of routes. Keep this to a low integer value. I am using 4
# for TATA connection because it is 4 times faster
W1=1
W2=1
# Broadband providers name; use your own names here.
NAME1=BSNL
NAME2=TATA
#No of repeats of success or failure before changing status of connection
SUCCESSREPEATCOUNT=4
FAILUREREPEATCOUNT=1
# Do not change anything below this line
# Last link status indicates the macro status of the link we determined. This is down initially to force routing change upfront. Don't change these values.
LLS1=1
LLS2=1
# Last ping status. Don't change these values.
LPS1=1
LPS2=1
# Current ping status. Don't change these values.
CPS1=1
CPS2=1
# Change link status indicates that the link needs to be changed. Don't change these values.
CLS1=1
CLS2=1
# Count of repeated up status or down status. Don't change these values.
COUNT1=0
COUNT2=0
while : ; do
ping -W $TIMEOUT -I $IP1 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo $NAME1 Down
CPS1=1
else
CPS1=0
fi
if [ $LPS1 -ne $CPS1 ]; then
echo Ping status changed for $NAME1 from $LPS1 to $CPS1
COUNT1=1
else
if [ $LPS1 -ne $LLS1 ]; then
COUNT1=`expr $COUNT1 + 1`
fi
fi
if [[ $COUNT1 -ge $SUCCESSREPEATCOUNT || ($LLS1 -eq 0 && $COUNT1 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME1 from $LLS1
CLS1=0
COUNT1=0
if [ $LLS1 -eq 1 ]; then
LLS1=0
else
LLS1=1
fi
else
CLS1=1
fi
LPS1=$CPS1
ping -W $TIMEOUT -I $IP2 -c 1 $TESTIP > /dev/null 2>&1
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
echo $NAME2 Down
CPS2=1
else
CPS2=0
fi
if [ $LPS2 -ne $CPS2 ]; then
echo Ping status changed for $NAME2 from $LPS2 to $CPS2
COUNT2=1
else
if [ $LPS2 -ne $LLS2 ]; then
COUNT2=`expr $COUNT2 + 1`
fi
fi
if [[ $COUNT2 -ge $SUCCESSREPEATCOUNT || ($LLS2 -eq 0 && $COUNT2 -ge $FAILUREREPEATCOUNT) ]]; then
echo Uptime status will be changed for $NAME2 from $LLS2
CLS2=0
COUNT2=0
if [ $LLS2 -eq 1 ]; then
LLS2=0
else
LLS2=1
fi
else
CLS2=1
fi
LPS2=$CPS2
if [[ $CLS1 -eq 0 || $CLS2 -eq 0 ]]; then
if [[ $LLS1 -eq 1 && $LLS2 -eq 0 ]]; then
echo Switching to $NAME2
ip route replace default scope global via $GW2 dev $EXTIF2
elif [[ $LLS1 -eq 0 && $LLS2 -eq 1 ]]; then
echo Switching to $NAME1
ip route replace default scope global via $GW1 dev $EXTIF1
elif [[ $LLS1 -eq 0 && $LLS2 -eq 0 ]]; then
echo Restoring default load balancing
ip route replace default scope global nexthop via $GW1 dev $EXTIF1 weight $W1 nexthop via $GW2 dev $EXTIF2 weight $W2
fi
fi
sleep $SLEEPTIME
done
Last edited by greenrover on 2009-04-02 14:15, edited 1 time in total.
Bei mir bekomme ich über beide Netzwerke auf dem Router-Computer Internet.
Jedoch wenn ein Client sich anhängt bekommt er eine IP 192.168.10.x und als Standartgateway 192.168.10.1, aber kein Internet.
#!/bin/sh
echo "1" > /proc/sys/net/ipv4/ip_forward
export IF1="eth0";
export IP1="10.221.0.2";
export P1="10.221.0.1";
export P1_NET="10.221.0/16";
export IF2="eth1";
export IP2="10.219.0.2";
export P2="10.219.0.1";
export P2_NET="10.219.0/16";
export IF0="eth2";
export IP0="192.10.0.1";
export P0_NET="192.10.0/16";
ip route delete default;
ip route delete default;
ip route add $P1_NET dev $IF1 src $IP1 table T1;
ip route add default via $P1 table T1;
ip route add $P2_NET dev $IF2 src $IP2 table T2;
ip route add default via $P2 table T2;
ip route add $P1_NET dev $IF1 src $IP1;
ip route add $P2_NET dev $IF2 src $IP2;
ip rule add from $IP1 table T1;
ip rule add from $IP2 table T2;
ip route add $P0_NET dev $IF0 table T1;
ip route add $P2_NET dev $IF2 table T1;
ip route add 127.0.0.0/8 dev lo table T1;
ip route add $P0_NET dev $IF0 table T2;
ip route add $P1_NET dev $IF1 table T2;
ip route add 127.0.0.0/8 dev lo table T2;
ip route add default scope global nexthop via $P1 dev $IF1 weight 1 nexthop via $P2 dev $IF2 weight 1
echo "done.";
exit
10.221.0.0/16 dev eth0 proto kernel scope link src 10.221.0.2
192.11.0.0/16 dev eth2 proto kernel scope link src 192.11.0.1
169.254.0.0/16 dev eth0 scope link metric 1000
192.10.0.0/16 dev eth2 proto kernel scope link src 192.10.0.1
10.219.0.0/16 dev eth1 proto kernel scope link src 10.219.0.2
default via 192.10.0.2 dev eth2 metric 100
default via 10.219.0.1 dev eth1 metric 100
default via 10.221.0.1 dev eth0 metric 100
Mach mal nen reboot damit die routing regeln leer sind (ich weis leider nicht wie es anders geht)
und die IPTABLES auch auf default sind und dann probiere es nochmal und mal alle Fehlerquellen aus zu schließen.