找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888
查看: 20157|回复: 56

我这样榨干家用路由器的CPU

[复制链接]
发表于 2016-10-12 21:47 | 显示全部楼层 |阅读模式
本帖最后由 stevemorrislian 于 2017-6-2 15:51 编辑

路由器与其他设备不同,他总是在运行,24小时不关的也是常事。当然如果你用来挖矿就能耗尽CPU,不过它毕竟还是要先完成基本任务,所以先要确定的是“耗尽”的限度
我的rb750有400M的CPU,64M的内存,128的FDD
先用ROS本身的功能:
我的基本功能包括路由表/DHCP/wifi,考虑到要看fq后的海外电视,先打开了CPU监测:然后开了一台电视看国内台,另一台看海外台,测试结果是10-30%的CPU load,带宽单台1-7M/s,同时运行时2-10M/s,显然直接的结果:CPU不能超80%,带宽一定留出10M(保证看电视)
接下去就是先安装较为重要的应用,dns服务可以减少内网反应的时间,他需要的其实不是CPU,而是比较耗内存。时间同步服务,我觉得重要,而且几乎没耗CPU。打印服务显然需要。.这些加上后,cpu的峰值确实上去了,但基本上还有50%的空间可以消耗
我内网分为2个IP段,
192.168.88.1缺省出国,主要是电视机,加了local地址表,只有这个local表内的目标IP才走国内出口
192.168.3.1缺省走国内,主要是wifi,用于手机,pc,平板,智能手表,我定了一个规则(鱼钩法则),访问facebook时,先把源地址(比如192.168.3.10)放进一个表accessList(f@nQ),时间1分钟==这样只要开着这个facebook窗口,他就是走出国的路由。只要我关掉facebook窗口,一分钟后自动回到缺省出口。这样就能省略tunnel包括加密所消耗的CPU。需要说明的是,即使出国,大部分也不需要走F@nQ,hosts文件就是很好的证明

       当然hosts文件也是可以放进DNS服务的,这样即使不用开facebook,很多网站也可以访问,只有发现hosts解决不了的问题,我才在后台开facebook,切换出口。

OpenWRT
用metaRouter功能可以在路由器内部再开虚拟路由器,一些临时开关的功能可以运行在虚拟路由器上,所以运行了一个OpenWRT,首先想到的无疑是Asterisk,这个功能不是很有名,但是仅仅用wifi和网络就能通过sip账户打电话,显然是用来折腾的好项目。家里的智能电视到android手表都无需sim卡就能打电话了——试下来CPU已经在50%了,所以没敢在其中再开视频和会议室,家里应该也用不着。

GitHub上还有一个Chnroutes项目,从亚太网络管控中心下载路由表,我可以每周运行一下,更新我的路由表(你懂的,主要是国内的目标不用去耗CPU)。考虑到Flash硬盘虽然不大,但是速度差不多相当于网速,所以我开了ftp服务,至少可以传送写数据到自己家里(虽然每次要通过查一下当前的IP)

ROS还有一个功能值得推荐,Graph,记录CPUload和网络端口带宽使用情况(24小时不间断,附件的图就是这个应用做出来的)

好了,接近75%的峰值了。

本帖子中包含更多资源

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

×
我的恩山、我的无线 The best wifi forum is right here.
 楼主| 发表于 2016-10-12 21:54 | 显示全部楼层
现在还没有明显的变慢迹象(已经一个月了)
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-10-12 22:25 | 显示全部楼层
NIUBI......
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-10-13 21:06 | 显示全部楼层
路由器反应不会变慢?游戏的ping值不会增加?

点评

记得吗,我看国外的电视直播,所以对网速很敏感。有5秒的网速低于要求,就会出现卡顿的现象。所以一直注意着。  发表于 2016-10-14 21:44
变慢有很多理由,我做的每一步都有监测。保证没有耗尽带宽、没有用光CPU和内存。 要变慢必然有资源耗尽,对吧?  详情 回复 发表于 2016-10-14 16:59
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-14 16:59 | 显示全部楼层
本帖最后由 stevemorrislian 于 2016-10-15 19:59 编辑
laimama 发表于 2016-10-13 21:06
路由器反应不会变慢?游戏的ping值不会增加?

变慢有很多理由,我做的每一步都有监测。保证没有耗尽带宽、没有用光CPU和内存。
变慢必然有资源耗尽,对吧? 至少一定是有原因的,并且可以找到原因

如果路由器资源还有余量,那么變慢了也该在其它地方找原因

我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-14 21:26 | 显示全部楼层
本帖最后由 stevemorrislian 于 2016-10-14 21:40 编辑

我也是尽量选择CPU/mem比较均衡的应用.一般也是每晚关机,可以避免mem leak。

本帖子中包含更多资源

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

×
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-17 10:34 | 显示全部楼层
本帖最后由 stevemorrislian 于 2016-10-17 10:35 编辑

bandwidth : 20M

本帖子中包含更多资源

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

×
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-10-17 18:07 | 显示全部楼层
400MHZ的cpu能用的这么充分,高手!

请问关于“从亚太网络管控中心下载路由表”,能发一个稍微详细一点的教程吗?

谢谢!

点评

chnroutes,这是一个github的项目 phython程序 #!/usr/bin/env python import re import urllib2 import sys import argparse import math import textwrap def generate_ovpn(metric): resul  详情 回复 发表于 2016-10-17 20:45
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-17 20:45 | 显示全部楼层
ramboee 发表于 2016-10-17 18:07
400MHZ的cpu能用的这么充分,高手!

请问关于“从亚太网络管控中心下载路由表”,能发一个稍微详细一点 ...

chnroutes,这是一个github的项目

phython程序
#!/usr/bin/env python

import re
import urllib2
import sys
import argparse
import math
import textwrap


def generate_ovirtual**(metric):
    results = fetch_ip_data()  
    rfile=open('routes.txt','w')
    for ip,datenum,mask2 in results:
        route_item="add list=domesticList address=%s/%s \t %s \n"%(ip,mask2,datenum)
        rfile.write(route_item)
    rfile.close()
    print "Usage: Append the content of the newly created routes.txt to your openvirtual** config file," \
          " and also add 'max-routes %d', which takes a line, to the head of the file." % (len(results)+20)


def generate_linux(metric):
    results = fetch_ip_data()
    upscript_header=textwrap.dedent("""\
    #!/bin/bash
    export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
   
    OLDGW=`ip route show | grep '^default' | sed -e 's/default via \\([^ ]*\\).*/\\1/'`
   
    if [ $OLDGW == '' ]; then
        exit 0
    fi
   
    if [ ! -e /tmp/virtual**_oldgw ]; then
        echo $OLDGW > /tmp/virtual**_oldgw
    fi
   
    """)
   
    downscript_header=textwrap.dedent("""\
    #!/bin/bash
    export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
   
    OLDGW=`cat /tmp/virtual**_oldgw`
   
    """)
   
    upfile=open('ip-pre-up','w')
    downfile=open('ip-down','w')
   
    upfile.write(upscript_header)
    upfile.write('\n')
    downfile.write(downscript_header)
    downfile.write('\n')
   
    for ip,mask,_ in results:
        upfile.write('route add -net %s netmask %s gw $OLDGW\n'%(ip,mask))
        downfile.write('route del -net %s netmask %s\n'%(ip,mask))

    downfile.write('rm /tmp/virtual**_oldgw\n')


    print "For pptp only, please copy the file ip-pre-up to the folder/etc/ppp," \
          "and copy the file ip-down to the folder /etc/ppp/ip-down.d."

def generate_mac(metric):
    results=fetch_ip_data()
   
    upscript_header=textwrap.dedent("""\
    #!/bin/sh
    export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
   
    OLDGW=`netstat -nr | grep '^default' | grep -v 'ppp' | sed 's/default *\\([0-9\.]*\\) .*/\\1/' | awk '{if($1){print $1}}'`

    if [ ! -e /tmp/pptp_oldgw ]; then
        echo "${OLDGW}" > /tmp/pptp_oldgw
    fi
   
    dscacheutil -flushcache

    route add 10.0.0.0/8 "${OLDGW}"
    route add 172.16.0.0/12 "${OLDGW}"
    route add 192.168.0.0/16 "${OLDGW}"
    """)
   
    downscript_header=textwrap.dedent("""\
    #!/bin/sh
    export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
   
    if [ ! -e /tmp/pptp_oldgw ]; then
            exit 0
    fi
   
    ODLGW=`cat /tmp/pptp_oldgw`

    route delete 10.0.0.0/8 "${OLDGW}"
    route delete 172.16.0.0/12 "${OLDGW}"
    route delete 192.168.0.0/16 "${OLDGW}"
    """)
   
    upfile=open('ip-up','w')
    downfile=open('ip-down','w')
   
    upfile.write(upscript_header)
    upfile.write('\n')
    downfile.write(downscript_header)
    downfile.write('\n')
   
    for ip,_,mask in results:
        upfile.write('route add %s/%s "${OLDGW}"\n'%(ip,mask))
        downfile.write('route delete %s/%s ${OLDGW}\n'%(ip,mask))
   
    downfile.write('\n\nrm /tmp/pptp_oldgw\n')
    upfile.close()
    downfile.close()
   
    print "For pptp on mac only, please copy ip-up and ip-down to the /etc/ppp folder," \
          "don't forget to make them executable with the chmod command."

def generate_win(metric):
    results = fetch_ip_data()  

    upscript_header=textwrap.dedent("""@echo off
    for /F "tokens=3" %%* in ('route print ^| findstr "\\<0.0.0.0\\>"') do set "gw=%%*"
   
    """)
   
    upfile=open('virtual**up.bat','w')
    downfile=open('virtual**down.bat','w')
   
    upfile.write(upscript_header)
    upfile.write('\n')
    upfile.write('ipconfig /flushdns\n\n')
   
    downfile.write("@echo off")
    downfile.write('\n')
   
    for ip,mask,_ in results:
        upfile.write('route add %s mask %s %s metric %d\n'%(ip,mask,"%gw%",metric))
        downfile.write('route delete %s\n'%(ip))
   
    upfile.close()
    downfile.close()
   
#    up_vbs_wrapper=open('virtual**up.vbs','w')
#    up_vbs_wrapper.write('Set objShell = CreateObject("Wscript.shell")\ncall objShell.Run("virtual**up.bat",0,FALSE)')
#    up_vbs_wrapper.close()
#    down_vbs_wrapper=open('virtual**down.vbs','w')
#    down_vbs_wrapper.write('Set objShell = CreateObject("Wscript.shell")\ncall objShell.Run("virtual**down.bat",0,FALSE)')
#    down_vbs_wrapper.close()
   
    print "For pptp on windows only, run virtual**up.bat before dialing to virtual**," \
          "and run virtual**down.bat after disconnected from the virtual**."

def generate_android(metric):
    results = fetch_ip_data()
   
    upscript_header=textwrap.dedent("""\
    #!/bin/sh
    alias nestat='/system/xbin/busybox netstat'
    alias grep='/system/xbin/busybox grep'
    alias awk='/system/xbin/busybox awk'
    alias route='/system/xbin/busybox route'
   
    OLDGW=`netstat -rn | grep ^0\.0\.0\.0 | awk '{print $2}'`
   
    """)
   
    downscript_header=textwrap.dedent("""\
    #!/bin/sh
    alias route='/system/xbin/busybox route'
   
    """)
   
    upfile=open('virtual**up.sh','w')
    downfile=open('virtual**down.sh','w')
   
    upfile.write(upscript_header)
    upfile.write('\n')
    downfile.write(downscript_header)
    downfile.write('\n')
   
    for ip,mask,_ in results:
        upfile.write('route add -net %s netmask %s gw $OLDGW\n'%(ip,mask))
        downfile.write('route del -net %s netmask %s\n'%(ip,mask))
   
    upfile.close()
    downfile.close()
   
    print "Old school way to call up/down script from openvirtual** client. " \
          "use the regular openvirtual** 2.1 method to add routes if it's possible"


def fetch_ip_data():
    #fetch data from apnic
    print "Fetching data from apnic.net, it might take a few minutes, please wait..."
    url=r'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest'
    data=urllib2.urlopen(url).read()
   
    cnregex=re.compile(r'apnic\|cn\|ipv4\|[0-9\.]+\|[0-9]+\|[0-9]+\|a.*',re.IGNORECASE)
    cndata=cnregex.findall(data)
   
    results=[]

    for item in cndata:
        unit_items=item.split('|')
        starting_ip=unit_items[3]
        num_ip=int(unit_items[4])
        datenum=unit_items[5]
        
        imask=0xffffffff^(num_ip-1)
        #convert to string
        imask=hex(imask)[2:]
        mask=[0]*4
        mask[0]=imask[0:2]
        mask[1]=imask[2:4]
        mask[2]=imask[4:6]
        mask[3]=imask[6:8]
        
        #convert str to int
        mask=[ int(i,16 ) for i in mask]
        mask="%d.%d.%d.%d"%tuple(mask)
        
        #mask in *nix format
        mask2=32-int(math.log(num_ip,2))
        
        results.append((starting_ip,datenum,mask2))
         
    return results


if __name__=='__main__':
    parser=argparse.ArgumentParser(description="Generate routing rules for virtual**.")
    parser.add_argument('-p','--platform',
                        dest='platform',
                        default='openvirtual**',
                        nargs='?',
                        help="Target platforms, it can be openvirtual**, mac, linux,"
                        "win, android. openvirtual** by default.")
    parser.add_argument('-m','--metric',
                        dest='metric',
                        default=5,
                        nargs='?',
                        type=int,
                        help="Metric setting for the route rules")
   
    args = parser.parse_args()
   
    if args.platform.lower() == 'openvirtual**':
        generate_ovirtual**(args.metric)
    elif args.platform.lower() == 'linux':
        generate_linux(args.metric)
    elif args.platform.lower() == 'mac':
        generate_mac(args.metric)
    elif args.platform.lower() == 'win':
        generate_win(args.metric)
    elif args.platform.lower() == 'android':
        generate_android(args.metric)
    else:
        print>>sys.stderr, "Platform %s is not supported."%args.platform
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-17 21:05 | 显示全部楼层
本帖最后由 stevemorrislian 于 2016-10-17 21:09 编辑

首先,http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest下可以访问到所有路由,as独立号目前已经有超过8000条路由,当然还在不断更新,主要是一旦进入bgp广播,系统就会自动记录,这也是APNIC的一个主要工作。他们管理IP地址

程序仅仅将他们改写为需要的格式,分成openvirtual**,linux,mac,win,android的路由表,他们的用法略有不同
一般都分为fq的up/down两个操作,你也许还要同时修改dns为8.8.8.8,或者114.114.114.114
如果你的路由器支持access-list并可以设置优先权,可以将国际路由放在优先的出国accesslist上,即使出国的线路没有up,他们也一样走非“优先的”accesslist,达到自动选择路由的目的

点评

感谢大师指点! 结合您的说明,看了一下github相关页面。现在双线接入正好有这个需求(电、联访问国内,移动访问国外) 再次感谢!  详情 回复 发表于 2016-10-18 18:37
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-10-17 23:29 来自手机 | 显示全部楼层
感觉楼主是个CCIE

点评

早就不吃香了  发表于 2016-10-18 20:12
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-10-18 18:37 | 显示全部楼层
stevemorrislian 发表于 2016-10-17 21:05
首先,http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest下可以访问到所有路由,as独立号目 ...

感谢大师指点!

结合您的说明,看了一下github相关页面。现在双线接入正好有这个需求(电、联访问国内,移动访问国外)

再次感谢!

点评

应该还有个解决电信/联通的路由表,简称南北问题  发表于 2016-10-18 20:12
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-19 20:33 | 显示全部楼层

点评

感谢推荐好站点! 看到作者做好的策略文件是针对ROS的,请问openwrt系统有导入方法吗? 因为总是听说ROS各种复杂,再加上只有破解版,一直没敢尝试。 谢谢!  详情 回复 发表于 2016-10-19 22:58
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

发表于 2016-10-19 22:58 | 显示全部楼层
stevemorrislian 发表于 2016-10-19 20:33
http://beibei.org.cn/beibei/routerOS/2015/10/Routing-table.html

感谢推荐好站点!

看到作者做好的策略文件是针对ROS的,请问openwrt系统有导入方法吗?

因为总是听说ROS各种复杂,再加上只有破解版,一直没敢尝试。

谢谢!

点评

策略?我不记得ROS有policy或者route-map,你具体指?或者你要怎么用?  发表于 2016-10-20 20:15
OpenWRT = linux  详情 回复 发表于 2016-10-20 14:52
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

 楼主| 发表于 2016-10-20 14:52 | 显示全部楼层
ramboee 发表于 2016-10-19 22:58
感谢推荐好站点!

看到作者做好的策略文件是针对ROS的,请问openwrt系统有导入方法吗?

OpenWRT = linux

点评

我看到您给出的页面这样写着: 导入方法. 1 打开winbox > files 把文件拖入. 2 New Terminal > import file-name=tel.rsc ;如法炮制 就是说ROS可以直接导入到某个 table 来做路由策略。 openwrt可以直接把  详情 回复 发表于 2016-10-20 21:24
我的恩山、我的无线 The best wifi forum is right here.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2024-3-29 12:39

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com 举报电话:0519-86695797

快速回复 返回顶部 返回列表