网络科技

    今日:1221| 主题:246121
收藏本版
互联网、科技极客的综合动态。

[其他] Double your Internet speed: Load Balancing made easy

[复制链接]
lzxohgzxf 发表于 2016-10-3 06:02:21
130 2

立即注册CoLaBug.com会员,免费获得投稿人的专业资料,享用更多功能,玩转个人品牌!

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Ever wanted to combine two WAN connections for faster* internet? I do, for torrenting. And I scripted it.
  On the Web, you’ll easily find “tutorials” that just give you some bash script you have to painstakingly modify for it to run. This is as simple as it gets!    But see for yourself!(code at the end of this post)  
  Since I get a dynamic (external) IP right into my PC, that would mean, I’d have to modify that every time. So I made this small script, that only depends on    iproute2, which you’ll need anyways, and    awkand    grep, that should already be on your system.  
  Just run the script as root and give the network interfaces you want to balance as parameters.
  1. ~$ sudo ./load-balance.sh eth0 eth1 wlan0
复制代码
In a future version, I’d like to add support for dynamically setting the weight (currently, all interfaces get the same priority).
  My setup looks like this:
  
       
  •       eth0goes to my Uni’s Interweb (they are my ISP)   
  •       eth1is connected via a USB-Ethernet-adapter to a router with a UMTS-modem   
  •       wlan0is my Android phone in tethering mode  
  As you can see, it is of course necessary, that you have multiple entry points into the Internet. If you connect your PC with multiple connections to the same WAN, you won’t get any speed increase.
  * Load balancing won’t work in all use cases. If you for example just stream a single video (or download a single file), only one of the balanced interfaces will be in use, and no speed increase is visible. But when you download multiple things, like the chunks of a torrent, half of the files/chunks are downloaded over the first IF, and half over the other.
      See on GitHub Gist  

  1. #!/bin/bash

  2. # Load balance multiple internet connections. Requires iproute2, awk and grep.
  3. # (C) 2016 Tobias Girstmair, isticktoit.net, GPLv2
  4. # Also useful: speedometer -l  -r eth1 -t eth1 -m $(( 1024 * 1024 * 3 / 2 ))
  5. # Not much user error checking is done - only pass working network connections

  6. # script needs root to work and at least two connections to be useful
  7. [ $EUID -eq 0 -a $# -ge 2 ] || {
  8.         echo "Usage (as root): $0 iface1 iface2 ..." >&2
  9.         exit 1
  10. }

  11. get_free_tblnum() { # http://stackoverflow.com/a/28702075
  12.         awk -v RS='\\s+' '{ a[$1] } END { for(i = 10; i in a; ++i); print i }'> /etc/iproute2/rt_tables
  13.         fi
  14.         MY_IP=$(ip -o -4 addr show $IFACE |awk -F'(\\s|/)+' '{print $4}')
  15.         GW_IP=$(ip route show dev $IFACE | awk '/default/ {print $3}')
  16.         SUBNT=$(ip route show dev eth0 | awk '/proto kernel/ {print $1}')

  17.         ip route add $SUBNT dev $IFACE src $MY_IP table $TABLE
  18.         ip route add default via $GW_IP table $TABLE
  19.         ip rule add from $MY_IP table $TABLE
  20.         echo nexthop via $GW_IP dev $IFACE weight 1
  21. }

  22. ip route add default scope global $(for IF in "$@"; do loadbal $IF; done)
复制代码
友荐云推荐




上一篇:Drivers stunned as porn appears on electronic billboard
下一篇:Your iPhone Is Secretly Tracking Everywhere You Go and This is How to Turn Off T
酷辣虫提示酷辣虫禁止发表任何与中华人民共和国法律有抵触的内容!所有内容由用户发布,并不代表酷辣虫的观点,酷辣虫无法对用户发布内容真实性提供任何的保证,请自行验证并承担风险与后果。如您有版权、违规等问题,请通过"联系我们"或"违规举报"告知我们处理。

草兮丶 发表于 2016-10-3 08:18:45
友情提示:由于此用户的签名太过于个性而被系统自动屏蔽
回复 支持 反对

使用道具 举报

yh7jt 发表于 2016-10-5 02:24:14
☆:签到是人气、荣誉的比拼,让我们的签到见证一份坚持吧!!!
回复 支持 反对

使用道具 举报

*滑动验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

我要投稿

推荐阅读

扫码访问 @iTTTTT瑞翔 的微博
回页顶回复上一篇下一篇回列表手机版
手机版/CoLaBug.com ( 粤ICP备05003221号 | 文网文[2010]257号 )|网站地图 酷辣虫

© 2001-2016 Comsenz Inc. Design: Dean. DiscuzFans.

返回顶部 返回列表