ip rule add prio 101 fwmark 1 table chan1 ip rule add prio 102 fwmark 2 table chan2 ip rule add prio 103 fwmark 4 table chan3
#!/bin/bash lst='/etc/rc.balance.lst' ########### Flushing ################## /sbin/iptables -t mangle -F PREROUTING /sbin/iptables -t mangle -F POSTROUTING /sbin/iptables -t mangle -F OUTPUT ####################################### /etc/rc.baltor /sbin/iptables -t mangle -A PREROUTING -d 172.16.0.0/16 -j RETURN /sbin/iptables -t mangle -A PREROUTING -s 172.16.0.0/16 -m state --state INVALID -j DROP while read net mark do /sbin/iptables -t mangle -A PREROUTING -s $net -m state --state new,related -j CONNMARK --set-mark $mark done<$lst /sbin/iptables -t mangle -A PREROUTING -s 172.16.0.0/16 -p udp --sport 11000:60000 --dport 11000:60000 -m state --state new,related -j BALANCE /sbin/iptables -t mangle -A PREROUTING -s 172.16.0.0/16 -p tcp --sport 11000:60000 --dport 11000:60000 -m state --state new,related -j BALANCE /sbin/iptables -t mangle -A PREROUTING -s 172.16.0.0/16 -j CONNMARK --restore-mark exit 0
172.16.0.0/22 1 172.16.4.0/22 2 172.16.8.0/22 4
#!/bin/bash /sbin/iptables -t mangle -F BALANCE lst='/etc/rc.cnload.lst' mrk=1 while read kld do /sbin/iptables -t mangle -A BALANCE -j CONNMARK --set-mark $mrk /sbin/iptables -t mangle -A BALANCE -m statistic --mode random --probability 0.$kld -j RETURN mrk=`expr $mrk \* 2` done < $lst /sbin/iptables -t mangle -A BALANCE -j CONNMARK --set-mark $mrk exit 0
#!/bin/bash cn1=800000 # cn2=600000 # .. cn3=400000 # if1='eth1' # if2='eth2' # if3='eth3' # lst='/etc/rc.cnload.lst' a1=`ifconfig $if1 | grep "RX bytes" | awk '{print $2}' | awk -F: '{print $2}'` a2=`ifconfig $if2 | grep "RX bytes" | awk '{print $2}' | awk -F: '{print $2}'` a3=`ifconfig $if3 | grep "RX bytes" | awk '{print $2}' | awk -F: '{print $2}'` sleep 20 b1=`ifconfig $if1 | grep "RX bytes" | awk '{print $2}' | awk -F: '{print $2}'` b2=`ifconfig $if2 | grep "RX bytes" | awk '{print $2}' | awk -F: '{print $2}'` b3=`ifconfig $if3 | grep "RX bytes" | awk '{print $2}' | awk -F: '{print $2}'` c1=`expr \( $b1 - $a1 \) \* 8 / 20000` c2=`expr \( $b2 - $a2 \) \* 8 / 20000` c3=`expr \( $b3 - $a3 \) \* 8 / 20000` d1=`expr \( $cn1 - $c1 \) \* 100 / $cn1` d2=`expr \( $cn2 - $c2 \) \* 100 / $cn2` d3=`expr \( $cn3 - $c3 \) \* 100 / $cn3` # 60% if [ $d1 -lt "40" -o $d2 -lt "40" -o $d3 -lt "40" ] then e1=`expr 100 \* $d1 / \( $d1 + $d2 + $d3 \)` e2=`expr 100 \* $d2 / \( $d2 + $d3 \)` f1=`head -n 1 $lst | tail -n 1` f2=`head -n 2 $lst | tail -n 1` # if [ $e1 -ne $f1 -a $e2 -ne $f2 ] then echo $e1 > $lst echo $e2 >> $lst /etc/rc.baltor fi fi exit 0
/etc/rc.balance
*/1 * * * * root /etc/rc.cnload
Source: https://habr.com/ru/post/157401/
All Articles