mportant;">出发点:在linux电脑上面绑定多条adsl链路做家庭带宽及个人DC使用:
0、账号文件:adsl.user【账号 密码】
adsluser1 adslpasswd1adsluser2 adslpasswd2adsluser3 adslpasswd3adsluser4 adslpasswd4……
管理网卡策略路由:
vi /etc/iproute2/rt_tables
……252manage……
下面两条策略放到/etc/rc.local中,并手动执行一遍:
ip route add default via 10.255.255.1 table manage
ip rule add from 10.255.255.0/25 table manage
升级网卡驱动:[注意内核要和内核的头文件版本号完全一致]
https://downloadcenter.intel.com/zh-cn/download/14687/-PCIe-10-Linux-?product=41282
https://downloadmirror.intel.com/14687/eng/ixgbe-5.7.1.tar.gz
yum install -y gcc rpm-build kernel-devel
rpmbuild -tb ixgbe-5.7.1.tar.gz
rpm -Uvh /root/rpmbuild/RPMS/x86_64/ixgbe-5.7.1-1.x86_64.rpm
1、拨号建立脚本:0-adsl.sh
#!/bin/bash
#------------------------------------------------------------------------|
# @Version : 1.1.0 |
# @Writer : Tyumen <tyumen@zhoufengjie.cn> |
# @Date : 2020-06-09 |
#------------------------------------------------------------------------|
adsluserlist=$1
dev=$2
function ShowUsage()
{
echo -e '\033[32;1mUsage: '$0 'adslfile netdev(like p5p1) \033[0m'
echo
exit 1
}
function CheckPPPOE()
{
( rpm -q rp-pppoe > /dev/null || yum install rp-pppoe -y ) && ( exit 0 ) || ( exit 1 )
}
function adduser()
{
adsluser=$1
adslpwd=$2
num=$3
echo "$adsluser * $adslpwd " >> /etc/ppp/chap-secrets
echo "$adsluser * $adslpwd " >> /etc/ppp/pap-secrets
ip link add link $dev dev adsl$num type macvlan mode private
cat > /etc/sysconfig/network-scripts/ifcfg-ppp$num <<EOF
USERCTL=yes
BOOTPROTO=dialup
NAME=DSLppp$num
DEVICE=ppp$num
TYPE=xDSL
ONBOOT=yes
PIDFILE=/var/run/pppoe-adsl$num.pid
FIREWALL=NONE
PING=.
PPPOE_TIMEOUT=80
LCP_FAILURE=3 LCP_INTERVAL=20
CLAMPMSS=1412
CONNECT_POLL=6
CONNECT_TIMEOUT=60
DEFROUTE=yes
SYNCHRONOUS=no
ETH=adsl$num
PROVIDER=DSLppp$num
USER=$adsluser
PEERDNS=no
DEMAND=no
LINUX_PLUGIN=/usr/lib64/pppd/2.4.5/rp-pppoe.so
EOF
grep "ppp"$num /etc/iproute2/rt_tables > /dev/null || echo "1"$num" ppp"$num >> /etc/iproute2/rt_tables
grep "ppp"$num /etc/rc.local > /dev/null || ( echo "ip route add 0/0 dev ppp"$num" table ppp"$num >> /etc/rc.local && ip route add 0/0 dev ppp$num table ppp$num)
ifup ppp$num
}
function AddadslUser()
{
adslfile=$1
num=0
cat $adslfile|while read adsluser adslpwd
do
modprobe macvlan
if [ "$adslpwd" != "" ];then
( ( grep $adsluser /etc/ppp/chap-secrets|grep $adslpwd > /dev/null ) && ( grep $adsluser /etc/ppp/pap-secrets|grep $adslpwd > /dev/null ) ) && (echo "user $adsluser has already exit." ) || ( adduser $adsluser $adslpwd $num ; let num++)
let num++
fi
done
}
if [ $# -ne 2 ]
then
ShowUsage
else
if [ -f $adsluserlist ];then
CheckPPPOE && AddadslUser $adsluserlist
fi
fi
sh /root/adsl/0-adsl.sh /root/adsl/adsl.user p5p1
2、拨号启动脚本:1-iprule.sh
#!/bin/bash
beginnum=0
#endnum=17
endnum=`ls /etc/sysconfig/network-scripts/ifcfg-ppp*|wc -l`
let endnum=endnum-1
function upnet()
{
begnum=$1
endnum=$2
for num in `seq $beginnum $endnum`
do
ifup ppp$num
done
}
function addrule()
{
begnum=$1
endnum=$2
for num in `seq $beginnum $endnum`
do
rulenum=`ip rule | awk '$NF~"^ppp'$num'$"'|wc -l`
while [ $rulenum -gt 0 ] ;do ip rule del lookup ppp$num;let rulenum--;done
#route add default dev ppp$num
ip route add 0/0 dev ppp$num table ppp$num
ip rule add fwmark 0x1$num table ppp$num pref 100
ipaddr=`ifconfig ppp$num|awk '$1~"inet" && $2~"^[0-9]"{print $2 }'`
if [ "$ipaddr" != "" ]
then
ip rule add from $ipaddr table ppp$num pref 200
fi
done
}
function addiptable()
{
begnum=$1
endnum=$2
rpm -q iptables > /dev/null || yum install iptables -y
for num in `seq $beginnum $endnum`
do
iptablenum=`iptables -t mangle -L -n|awk '$1~"MARK" && $NF~"^0x1'$num'$"'|wc -l`
while [ $iptablenum -gt 0 ] ; do iptables -t mangle -D INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num ; let iptablenum--;done
iptables -t mangle -A INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num
done
}
upnet $beginnum $endnum
addrule $beginnum $endnum
addiptable $beginnum $endnum
sh /root/adsl/1-iprule.sh
3、进程检查脚本:/root/adsl/2-adslcheck.sh【adsl出现down掉之后需要进行重启】
#!/bin/bash
beginnum=0
endnum=`ls /etc/sysconfig/network-scripts/ifcfg-ppp*|wc -l`
let endnum=endnum-1
PATH="/sbin:/usr/sbin:/bin:/usr/bin"
export PATH
function UPppp()
{
num=$1
ifup ppp$num
rulenum=`ip rule | awk '$NF~"^ppp'$num'$"'|wc -l`
while [ "$rulenum" -gt "0" ] ;do ip rule del lookup ppp$num;let rulenum--;done
ip route add 0/0 dev ppp$num table ppp$num
ip rule add fwmark 0x1$num table ppp$num pref 100
ipaddr=`ifconfig ppp$num|awk '$1~"inet" && $2~"^[0-9]"{print $2}'`
if [ "$ipaddr" != "" ]
then
ip rule add from $ipaddr table ppp$num pref 200
fi
iptablenum=`iptables -t mangle -L -n|awk '$1~"MARK" && $NF~"^0x1'$num'$"'|wc -l`
while [ $iptablenum -gt 0 ] ; do iptables -t mangle -D INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num ; let iptablenum--;done
iptables -t mangle -A INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num
}
function checkadsl()
{
begnum=$1
endnum=$2
for num in `seq $beginnum $endnum`
do
ipaddr=`ifconfig ppp$num|awk '$1~"inet" && $2~"^[0-9]"{print $2}'`
if [ "$ipaddr" != "" ]
then
routenum=`ip route show table ppp$num|wc -l`
if [ "$routenum" == "0" ]
then
rulenum=`ip rule | awk '$NF~"^ppp'$num'$"'|wc -l`
while [ "$rulenum" -gt "0" ] ;do ip rule del lookup ppp$num;let rulenum--;done
ip route add 0/0 dev ppp$num table ppp$num
ip rule add fwmark 0x1$num table ppp$num pref 100
ipaddr=`ifconfig ppp$num|awk '$1~"inet" && $2~"^[0-9]"{print $2 }'`
if [ "$ipaddr" != "" ]
then
ip rule add from $ipaddr table ppp$num pref 200
fi
iptablenum=`iptables -t mangle -L -n|awk '$1~"MARK" && $NF~"^0x1'$num'$"'|wc -l`
while [ "$iptablenum" -gt 0 ] ; do iptables -t mangle -D INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num ; let iptablenum--;done
iptables -t mangle -A INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num
fi
else
UPppp $num
fi
done
}
function checkroute()
{
for net in `ip a|awk -F"[ :]+" '$2~"^ppp"{print $2}'`
do
pingsucess=`ping 114.114.114.114 -I $net -c 10 -f|awk '$5~"received"{print $4}'`
if [ "$pingsucess" == "0" ];then
ip route add 0/0 dev $net table $net
fi
done
}
checkadsl $beginnum $endnum
#checkroute
chmod +x /root/adsl/2-adslcheck.sh
echo “*/10 * * * * root /root/adsl/2-adslcheck.sh > /dev/null 2>&1″ > /etc/cron.d/adslcheck
4、adsl定期重启
定期重启脚本:3-restartadsl.sh,防止在晚高峰的时候网络掉线
#!/bin/bash
beginnum=0
endnum=`ls /etc/sysconfig/network-scripts/ifcfg-ppp*|wc -l`
let endnum=endnum-1
function UPppp()
{
num=$1
ifup ppp$num
sleep 5
rulenum=`ip rule | awk '$NF~"^ppp'$num'$"'|wc -l`
while [ "$rulenum" -gt "0" ] ;do ip rule del lookup ppp$num;let rulenum--;done
ip route add 0/0 dev ppp$num table ppp$num
ip rule add fwmark 0x1$num table ppp$num pref 100
ipaddr=`ifconfig ppp$num|awk '$1~"inet" && $2~"^[0-9]"{print $2}'`
if [ "$ipaddr" != "" ]
then
ip rule add from $ipaddr table ppp$num pref 200
fi
iptablenum=`iptables -t mangle -L -n|awk '$1~"MARK" && $NF~"^0x1'$num'$"'|wc -l`
while [ "$iptablenum" -gt "0" ] ; do iptables -t mangle -D INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num ; let iptablenum--;done
iptables -t mangle -A INPUT -i ppp$num -m state --state NEW -j MARK --set-mark 0x1$num
}
function restartadsl()
{
begnum=$1
endnum=$2
for num in `seq $beginnum $endnum`
do
ifdown ppp$num
done
sleep 5
for num in `seq $beginnum $endnum`
do
UPppp $num
done
}
restartadsl $beginnum $endnum
echo “0 6 */3 * * root /root/adsl/3-restartadsl.sh > /dev/null 2>&1″ > /etc/cron.d/adslrestart
5、做随机启动配置:添加网卡脚本addnet.sh
#!/bin/bash
adslfile=$1
dev=$2
num=0
function ShowUsage()
{
echo -e '\033[32;1mUsage: '$0 'adslfile netdev(like p5p1) \033[0m'
echo
exit 1
}
function addnet()
{
adslfile=$1
cat $adslfile|while read adsluser adslpasswd vlanid other
do
ip link add link $dev dev adsl$num type macvlan mode private
let num++
done
}
if [ $# -ne 2 ]
then
ShowUsage
else
if [ -f $adslfile ];then
addnet $adslfile
fi
fi
在/etc/rc.local里面添加如下内容:
……ip route add default via 10.255.255.1 table manageip rule add from 10.255.255.0/25 table manage/root/adsl/addnet.sh /root/adsl/adsl.user p5p1/root/adsl/1-iprule.sh……
本文链接:https://www.kinber.cn/post/4364.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝: