Титла: Два интернет доставчика Публикувано от: Йордан в Jul 05, 2009, 17:21 Здравейте,
Имам оптика А и оптика Б. Искам винаги да ползвам оптика А, като някои сайтове изброени изрично да минават през Б /iptv примерно/. Когато А изчезне искам всичко автоматично да премине към Б. Въпроса е има ли нещо готово и просто за използване? Титла: Re: Два интернет доставчика Публикувано от: lkr в Jul 05, 2009, 19:46 routing tables + active-backup bonding
Титла: Re: Два интернет доставчика Публикувано от: plamen_f в Jul 05, 2009, 20:11 http://www.pfsense.com/ ($2)
Титла: Re: Два интернет доставчика Публикувано от: Йордан в Jul 05, 2009, 20:32 routing tables + active-backup bondingС бондинг не става т.к. имам различни IP'та на двете оптики. Титла: Re: Два интернет доставчика Публикувано от: ntrance в Jul 05, 2009, 20:34 Ае , много с зле всичките , не му казвахте какво + какво + какво и да му давате линкове ... ами вземете дайте идеи...
Пич този скрипт ползвам , той ми рутира и 2-двата нета Просто добави 2-та gateway-a и на кой лан картите се намират това е За въпроси пиши root@greenbox-server:/etc/network# cat routing # Mandatory variables TABLE1=1 # The TABLE ID associated to your 1st ISP IF1=eth0 # The NIC name connected to your 1st ISP GW1=10.6.0.1 # 1st or Default Internet Service Provider Gateway (Router IP Address) TABLE2=2 # The TABLE ID associated to your 2th ISP IF2=eth5 # The NIC name connected to your 2th ISP GW2=192.168.1.1 # 2th Internet Server Provider Gateway (Router IP Address) #TABLE2=n # The TABLE ID associated to your n.. ISP # This line is an example # IF2=ethn # The NIC name connected to your n... ISP # This line is an example # GW2=192.168.nnn.nnn # n... Internet Provider Gateway # This line is an example izbalancing() { # Command Syntax: $1 "InterfaceName" "TableID" "IPDefaultGateway" # Add a Command line for any external internet connection $1 $IF1 $TABLE1 $GW1 $1 $IF2 $TABLE2 $GW2 #$1 $IFn $TABLEn $GWn # This line is an example if [ "$1" = "start" ] then # Misc $IP route del default $IP route add default equalize nexthop via $GW1 nexthop via $GW2 #$IP route add default equalize nexthop via $GW1 nexthop via $GW2 nexthop via $GWn # ...so on... ## NOTE!! # You must execute the following iptables rules if you want act as Load Balanced/MultiHomed GNU/Linux Firewall # > mangle table < $IPTABLES -t mangle -A PREROUTING -p ALL -j CONNMARK --restore-mark $IPTABLES -t mangle -A PREROUTING -p ALL -i $IF1 -m mark --mark 0 -j MARK --set-mark $TABLE1 $IPTABLES -t mangle -A PREROUTING -p ALL -i $IF2 -m mark --mark 0 -j MARK --set-mark $TABLE2 # $IPTABLES -t mangle -A PREROUTING -p ALL -i $IFn -m mark --mark 0 -j MARK --set-mark $TABLEn # This line is an example $IPTABLES -t mangle -A POSTROUTING -p ALL -o $IF1 -m state --state NEW -j MARK --set-mark $TABLE1 $IPTABLES -t mangle -A POSTROUTING -p ALL -o $IF2 -m state --state NEW -j MARK --set-mark $TABLE2 # $IPTABLES -t mangle -A POSTROUTING -p ALL -o $IFn -m state --state NEW -j MARK --set-mark $TABLEn # This line is an example $IPTABLES -t mangle -A POSTROUTING -p ALL -m state --state NEW -j CONNMARK --save-mark # > nat table < $IPTABLES -t nat -A POSTROUTING -p ALL -o $IF1 -m mark --mark $TABLE1 -j SNAT --to-source $(find_primary_ip $IF1) $IPTABLES -t nat -A POSTROUTING -p ALL -o $IF2 -m mark --mark $TABLE2 -j SNAT --to-source $(find_primary_ip $IF2) # $IPTABLES -t nat -A POSTROUTING -p ALL -o $IFn -m mark --mark $TABLEn -j SNAT --to-source $(find_primary_ip $IFn) # This line is an example fi } # Default commands path IP=ip IPTABLES=iptables ############################################################################################### ############################################################################################### ## CONFIGURATION IS OVER, DON'T EDIT ANYTHING BELLOW ## ############################################################################################### ############################################################################################### ### $1 = Ethernet Interface Name ### $2 = Table Number ### $3 = Default Gateway # Init default policies and variables init() { # Enable fast failover of broken gateways links (this isn't a real failover) echo "10" > /proc/sys/net/ipv4/route/gc_timeout # Make this machine a Routing Machine(tm) :-) echo "1" > /proc/sys/net/ipv4/ip_forward # Variables IF=$1 TABLE=$2 FWIP=$(find_primary_ip $IF) GWIP=$3 #echo "Init: IF=$IF TABLE=$TABLE FWIP=$FWIP GWIP=$GWIP IP=$IP" } ## STOP # Stop izbalancing stop() { init $1 $2 $3 route_stop rule_stop } # Reset routing tables route_stop() { # Flush whole routing table of current table if [ ! -z "$($IP route show table $TABLE)" ] then $IP route flush table $TABLE fi # Reset to default Single Gateway if [ ! -z "$GW1" ] then $IP route del default $IP route add default via $GW1 fi # If you don't want to reset the routing cache every time you run this ******, comment the following line $IP route flush cache } # Reset rule tables rule_stop() { # Flush whole rule table of current table (except for fwmark rules) $IP rule list | grep "lookup $TABLE" | grep -v "from all fwmark" | awk '{print $2" "$3" "$4" "$5" "$6" "$7}' $1 | while read RULE do $IP rule del $RULE done # Flush whole fwmark rule table of current table $IP rule list | grep "lookup $TABLE" | grep "from all fwmark" | awk '{print $4" "$5" "$6" "$7}' $1 | while read RULE do $IP rule del $RULE done } ## START # Start izbalancing Subsystem start() { #echo "1 Before init ($1 $2 $3)" init $1 $2 $3 #echo "2 Before stop ($1 $2 $3)" stop $1 $2 $3 #echo "3 Before route_start ($1 $2 $3)" route_start #echo "4 Before rule_start ($1 $2 $3)" rule_start } route_start() { # Import from table 'default' to 'current table' the whole routing settings $IP route show table main | grep -Ev ^default | grep -Ev nexthop | while read ROUTE; do $IP route add table $TABLE $ROUTE; done # Add the default interface gateway to the current table $IP route add table $TABLE default via $GWIP } # Add iproute2 rules in current table rule_start() { $IP rule add from $FWIP lookup $TABLE $IP rule add fwmark $TABLE lookup $TABLE for IP_ALIAS in $(find_secondary_ip $IF) do $IP rule add from $IP_ALIAS lookup $TABLE done } ######################################################### # Autodetect IP number of specified network interface find_primary_ip() { if [ ! -z $1 ] then echo $($IP addr show $1 | grep 'inet' | grep -v ":" | awk '{print $2}' | sed -e 's/\/.*//') fi } find_secondary_ip() { if [ ! -z $1 ] then echo $($IP addr show $1 | grep 'inet' | grep "$1:" | awk '{print $2}' | sed -e 's/\/.*//') fi } ############################################################################################### ## Valid ****** input from command line case $1 in stop) izbalancing stop ;; start) izbalancing start ;; restart) izbalancing start ;; *) echo "InitZero GNU/Linux Firewall/Router Incoming/Outgoing MultiHomed/LoadBalanced Subsystem" echo " < vsichko e nared>" echo "Version $VERSION" echo echo "Usage: $0 [OPTIONS]" echo echo "Available Options:" echo " start, Start the izbalancing subsystem" echo " stop, Stop the izbalancing subsystem" echo " restart, ReStart the izbalancing subsystem" echo echo " example: $0 start" exit 0 esac ## The End ###############################################################################################. root@greenbox-server:/etc/network# Титла: Re: Два интернет доставчика Публикувано от: ntrance в Jul 05, 2009, 20:36 И този също ми върши работа :)
root@greenbox-server:/etc/scripts# cat route.sh ip route add $10.6.0.1 dev $eth0 src $10.6.160.100 table T1 ip route add default via $10.6.160.100 table T1 ip route add $192.168.1.1 dev $eth1 src $192.168.1.2 table T2 ip route add default via $192.168.1.1 table T2 ip route add $10.6.0.1 dev $eth0 src $10.6.160.100 ip route add $192.168.1.1 dev $eth1 src 192.168.1.2 ip route add default via $10.6.0.1 ip rule add from $10.6.160.100 table T1 ip rule add from $192.168.1.2 table T2 ip route add $172.16.1.1 dev $eth2 table T1 ip route add $192.168.1.1 dev $eth1 table T1 ip route add 127.0.0.0/8 dev lo table T1 ip route add $192.168.0.0 dev $eth2 table T2 ip route add $10.6.160.100 dev $eth0 table T2 ip route add 127.0.0.0/8 dev lo table T2 root@greenbox-server:/etc/scripts# #---------------------------2-------------------------- #!/bin/sh # variables ip='/sbin/ip' # Networks /30 for vlans ext1_net='172.16.0.0/16' #ext2_net='y.y.y.y/yy' #ext3_net='z.z.z.z/zz' # IPS ext1_ip='10.6.160.100' ext2_ip='192.168.1.2' #ext3_ip='z.z.z.z' # gateways ext1_gw='10.6.0.1' ext2_gw='192.168.1.1' #ext3_gw='z.z.z.1' # devices ext1_dev='eth2' #ext2_dev='eth1' #ext3_dev='ethZ.zz' # don't touch below ${ip} route add ${ext1_net} dev ${ext1_dev} src ${ext1_ip} table elit1 ${ip} route add default via ${ext1_gw} table elit1 ${ip} route add ${ext1_net} dev ${ext1_dev} src ${ext1_ip} table elit2 ${ip} route add default via ${ext2_gw} table elit2 #${ip} route add ${ext3_net} dev ${ext3_dev} src ${ext3_ip} table elit3 #${ip} route add default via ${ext3_gw} table elit3 ${ip} rule add from ${ext1_ip} table elit1 ${ip} rule add from ${ext2_ip} table elit2 #${ip} rule add from ${ext3_ip} table elit3 ${ip} route add default scope global nexthop via ${ext1_gw} dev ${ext1_dev} weight 1 \ nexthop via ${ext2_gw} dev ${ext1_dev} weight 1 # nexthop via ${ext3_gw} dev ${ext3_dev} weight 5 root@greenbox-server:/etc/scripts# Титла: Re: Два интернет доставчика Публикувано от: Йордан в Jul 05, 2009, 20:39 http://www.pfsense.com/ ($2)Добра идея. Преди нея си мислиш за микротик, но има камара излишни неща в повече |