找回密码
 注册

QQ登录

只需一步,快速开始

查看: 18226|回复: 16

刷RouterTech后一些高级功能的使用心得

[复制链接]
发表于 2010-5-12 18:15:37 | 显示全部楼层 |阅读模式
因为gt701wg的便宜,所以买了好几个给亲戚朋友家用,可表哥舅妈提出更高的要求要限制小孩的上网时间,这下只好找第三方固件了。幸好RouterTech是支持的,只是麻烦点,以下就是偶的实践过程。

gt701wg刷RouterTech是有2种方法的,所以对挂载nvram目录要区别对待
1.对于内核和文件系统分开的RouterTech刷法,也就是不改mtd的刷法挂载nvram:
telnet 192.168.1.1或ssh 192.168.1.1
运行mkfs.minix /dev/mtdblock/4
这句就是说把mtd4分区转化为minix分区
运行setenv RT_init_minix1 "mount -t minix /dev/mtdblock/4 /nvram"
运行setenv cron_enable "1"
这句意思就是把minix4分区挂载到nvram目录和激活cron
重启路由后telnet进去运行getenv,应该有RT_init_minix1 mount -t minix /dev/mtdblock/4 /nvram的显示了
这时运行edit /nvram/startup.sh就可以编辑你想要的内容了,编辑好别忘了保存,就是按Esc键
再运行chmod a+x /nvram/startup.sh给于运行的权限
最后运行flush(rt2.93版本)或reboot重启(rt2.92版本),重启后就会开路由自动运行startup.sh了。

2.对于内核和文件系统不分开的RouterTech刷法,也就是改mtd的刷法挂载nvram:
telnet 192.168.1.1
运行makemtd.sh mtd5 64 auto_minix就可以了,会自动创建1个64k的mtd5分区并自动挂载nvram目录的其余步骤就和上面的一样的

3.对于上海贝尔500-S6307MPW-II等能刷RouterTech的ti猫,思路是一样的

附上偶的startup.sh内容,还加上了命令解释,不需要的功能大家前面加#注释掉好了:
ledcfg -f /nvram/led.gt701wg.conf
# 以上是关于我的led配置,大家不要就注释掉
/sbin/insmod rshaper.o mode =1
rshaperctl 192.168.0.9 151552
rshaperctl 192.168.0.10 174080
#开启rshaper限速模式为1,0的话限制上传的,并且限制192.168.0.9和192.168.0.10的速度为150k和174k
cronfile=/var/spool/cron/crontabs/root
echo "30 23 * * * echo \"begin;ap:settings/ap_enabled=0;end\"|cm_cli_ex">> $cronfile
# 晚上11点半关闭无线网络
echo -e "" >> $cronfile
echo "15 7 * * * echo \"begin;ap:settings/ap_enabled=1;end\"|cm_cli_ex">> $cronfile
# 早上7点1刻开启无线网络
echo -e "" >> $cronfile
echo "18 21 * * * echo \"begin;lan0:flan:settings/192.168.0.5/block=1;end"|cm_cli_ex">> $cronfile
# 晚上9点18分禁止192.168.0.5上网
echo "24 18 * * * echo \"begin;lan0:flan:settings/192.168.0.5/block=0;end"|cm_cli_ex">> $cronfile
# 晚上6点24分允许192.168.0.5上网
# echo -e "*/15 * * * * /nvram/mac.sh\n" >> /root_cron
# 每过1刻钟帮一次mac地址内网改ip地址没用了
cronjob.sh "/usr/local/bin/memopt.sh&" "*/30" "*/1" "*" "*" "*"
# 每过1个半小时整理一次内存
echo -e "30 17 * * * rshaperctl 192.168.0.9 151552\n" >> /root_cron
echo -e "* 23 * * * rshaperctl 192.168.0.9 0\n" >> /root_cron
echo -e "30 17 * * * rshaperctl 192.168.0.10 184320\n" >> /root_cron
echo -e "* 23 * * * rshaperctl 192.168.0.10 0\n" >> /root_cron
# 以上是关于192.168.0.9和192.168.0.10的2个地址的定时限速和不限速
# echo -e "*/20 * * * * /nvram/3322.sh\n" >> /root_cron
# 上面我申请的3322域名转向,要自己在nvram目录建立一个脚本
sleep 30
/sbin/iptables -I INPUT -i ppp0 -p tcp --dport 23 -j ACCEPT
/sbin/iptables -I FORWARD -i ppp0 -p tcp --dport 23 -j ACCEPT
/sbin/iptables -t nat -I PREROUTING -p tcp -i ppp0 --dport 2023 -j REDIRECT --to-ports 23 
/sbin/iptables -t nat -A PREROUTING -p TCP -i ppp0 --dport 23 -j DNAT --to 192.168.1.99
/sbin/iptables -I INPUT -i ppp0 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -I FORWARD -i ppp0 -p tcp --dport 22 -j ACCEPT
/sbin/iptables -t nat -I PREROUTING -p tcp -i ppp0 --dport 2022 -j REDIRECT --to-ports 22 
/sbin/iptables -t nat -A PREROUTING -p TCP -i ppp0 --dport 22 -j DNAT --to 192.168.1.99
/sbin/iptables -I INPUT -i ppp0 -p icmp --icmp-type 8 -j ACCEPT
/sbin/iptables -I FORWARD -i ppp0 -p icmp --icmp-type 8 -j ACCEPT
# 以上是关于开启远程的telnet和ssh的,这里telnet就是2023端口ssh为2022
sleep 5
/nvram/mac.sh
sleep 5
/nvram/3322.sh

# 开机就马上运行一次域名解析和帮一次mac 
# echo "0 0 * * * /usr/local/bin/reboot.sh\n" >> /root_cron

# 定时重启
 把以上存进startup.sh里就可以自动运行想要的功能了,大家还可以添加自己想要的命令增加更多的功能
发表于 2010-5-13 11:18:53 | 显示全部楼层
晕!竟然一点都看不明白!
发表于 2010-5-18 23:08:15 | 显示全部楼层
请问一下 telnet 的默认账号和密码是什么?
发表于 2010-5-18 23:28:35 | 显示全部楼层
这么强的机啊,还没用过
发表于 2010-5-19 21:38:41 | 显示全部楼层
楼主请教一下 运行setenv 指令设置env变量后好像没效果(返回的显示是设置成功),但重启后看不到设定的变量,是怎么回事
 楼主| 发表于 2010-5-21 09:46:03 | 显示全部楼层
默认账号root默认密码Admin
 楼主| 发表于 2010-5-21 09:53:36 | 显示全部楼层
本帖最后由 liyinguang 于 2010-5-21 10:00 编辑
楼主请教一下 运行setenv 指令设置env变量后好像没效果(返回的显示是设置成功),但重启后看不到设定的变量 ...
tzhang 发表于 2010-5-19 21:38



这个问题偶也遇到过,照rt的官方说法,这是ADAM2的缺点了,大意就是adam2环境有点乱了设置不进去,偶的一般解决方法是把setenv 指令设置的不重要env变量都删除,比如led灯Led pppoered 0和Led powerred 0的设置都UNSETENV掉,(最好在tools>RT Configurations里看不到一个打勾的,或者最多就Enable Cron打勾的)再进ADAM2环境去设置,也就是ftp进去设置,100%可以成功的。
ftp下的指令要大写,例如quote SETENV 。。。或quote UNSETENV 。。。等等
而led灯的指令可以在startup.sh设置,懂了吧
发表于 2010-6-13 13:45:10 | 显示全部楼层
RSHAPER - shape incoming traffic
                ================================

This is a module for versions 2.0, 2.2 and 2.4 of the Linux kernel, it
is  meant  to  limit  the  incoming bandwidth  for  packets  aimed  at
different  hosts.  With  "incoming"  I mean  traffic  that enters  the
shaping host; if  that host is a gateway between  target hosts and the
rest of  the Internet,  all the  traffic of the  target hosts  will be
shapeable.

I see two interesting uses for this tool:

        * Limiting   the bandwidth available  to permanently connected
                hosts by installing rshaper on  their gateway. This is
                interesting  for ISP  who offer  housing  and want  to
                differentiate the offer.

        * Limiting download bandwidth  from students' boxes or similar
                setups, by installing  the   rshaper directly  on  the
                target computer. This  requires that the user of  that
                computer can not gain superuser privileges.

While  the former issue can be  addressed with the conventional shaper
driver, the    latter  can't be  easily   addressed by   the  standard
shaper. As a matter of facts,  I have not been able  to use the shaper
to  address   the former situation,   either;   this because effective
filtering can only be achieved through  source-routing, but when I had
to deal  with  this problem, the  shaper  only existed for Linux-2.1
while my production setup was constrained to be 2.0.

While running rshaper  with 2.0 and 2.2 requires  patching the network
driver, the 2.4 "netfilter" feature helps rshaper by avoiding the need
to patch  the netword driver. Moreover, with netfilter the rshaper can
also shape outgoing traffic.

                INSTALLATION
                ============

First of  all "make". You'll end  up with an  "rshaper.o" module, that
can  be loaded  to your  kernel.  If your  kernel sources  are not  in
/usr/src/linux, you must tell make where they are by setting KERNELDIR
in  the environment or  specifying it  on the  make command  line. For
example:

        make KERNELDIR=/usr/src/linux-2.4

As suggested,  the network driver you  are using needs  to be slightly
modified  if you  run version  2.0 or  2.2 of  the kernel.   The exact
changes  to these  kernels depend  on your  particular setup,  and are
described in the following section.

                THEORY OF OPERATION
                ===================

The  idea is easy:  whenever  a packet is   received through a network
interface, the rshaper module delays notification of the packet to the
network subsystem of Linux according to the expected data flow for the
involved host.  The same  mechanism can be  used for  outgoing packets
under  2.4. If you  use version  2.4, you  can skip  the rest  of this
section, otherwise please read on.

With 2.0 and 2.2, the network driver must be modified in order to call
the  shaper's receive  function  instead of  the standard  netif_rx().
Therefore, you should modify two lines of your network device driver.

In case you use a  NE2000 clone or another 8390-based ethernet device,
you can use the patch  included in this package as "8390-2.X.c.patch",
where 2.X  is your  kernel version (2.0  or 2.2).   If you are  new to
patches, please refer to the last section.

If your ethernet driver is not an 8390-based  one, you have to do your
own changes (while I might  offer patches for  other devices, I am too
lazy to do it, generally).

The code is simple:

  (1) in global space add the following line:
          int (*net_shaper_rx_hook)(struct sk_buff *skb) = NULL;

  (2) Only for Linux-2.2 (not for Linux-2.0), add this too:
          EXPORT_SYMBOL(net_shaper_rx_hook)
      this line must appear after the definition of the hook.

  (3) in the receive function of the driver change
           netif_rx(skb)
  to
           if (net_shaper_rx_hook)
                   (*net_shaper_rx_hook)(skb);
           else
                   netif_rx(skb);

        NOTE 1: using non-8390-based modularized drivers with Linux-2.2
        ---------------------------------------------------------------

In version 2.2  of the Linux kernel, no symbol  is exported by default
when loading a module. That's  why you need to use the "EXPORT_SYMBOL"
macro.   However,  using the  macro  may  be  not enough:  the  symbol
"EXPORT_SYMTAB" must  be defined in order  for the symbol  table to be
exported.

To  define the symbol,  compile the  module with  "-DEXPORT_SYMTAB" or
define the  macro with "#define  EXPORT_SYMTAB" in the  module itself.
This  step  is  not needed  for  8390.c  (the  driver used  by  NE2000
compatible devices) because that module already exports some symbols.

        NOTE 2: using non-modularized drivers
        -------------------------------------

If your ethernet  driver(s) is linked in the  kernel image, instead of
being a module,  you must also arrange for  "net_shaper_rx_hook" to be
exported to modules, so that  the "rshaper.o" module will find it.  To
do  this, apply  the  patch "ksyms-2.X.c.patch"  (again,  2.X is  your
kernel version) to kernel/ksysms.c in the kernel sources.

Please  don't apply  ksysms-2.X.c.patch if  your network  driver  is a
module.


        NOTE 3: using more than one network interface
        ---------------------------------------------

If your  network interfaces are  of different kinds, change  (3) above
must  be applied  to all  the drivers  involved with  shaping traffic,
while change (1) must be applied differently:

  (1a) only one network driver must have this line:
          int (*net_shaper_rx_hook)(struct sk_buff *skb) = NULL;

  (1b) every other driver must have:
          extern int (*net_shaper_rx_hook)(struct sk_buff *skb);

  (2) if using version 2.2, only in the driver of (1a) above add:
          EXPORT_SYMBOL(net_shaper_rx_hook)

  (3) if needed, follow NOTE 1 above, only for the driver

The module with modification (1a) must  be loaded before the ones with
modification  (1b),  otherwise  loading will   fail  with ``unresolved
symbol "net_shaper_rx_hook"''



                CONFIGURATION (USING RSHAPERCTL)
                ================================

After  reloading  your  modules   or rebooting,  you   must load   the
"rshaper.o"  module.   To   configure   the   bandwidth,    then,  use
"./rshaperctl". For example:

           rshaperctl 192.168.1.2 6400 10

Limits the  incoming bandwidth for the  host to 6400  bytes per second
and queues  packets as long as  the queue is shorter  than 10 seconds.
If the  third argument is missing,  it defaults to  5 seconds.

Version 1.06  of the tool adds  an internal limitation to  the size of
the queue, in  order to try preventing memory  saturation.  The amount
of pending data is limited  by the macro RSHAPER_LIMIT_KB which can be
defined at  compile time  and defaults  to half a  meg. Note  that the
memory requirements of the queue can be far greater than the amount of
IP data being  hosted, as rshaper has its own  data structures to keep
track of the packets.

To remove  the limit  associate to an host, just use  0 as the allowed
bandwidth:

           rshaperctl 192.168.1.2 0

From version  1.04 onwards, it  is  possible to use computer  names in
addition to IP numbers.

You can also limit the bandwidth  allocated to a network of computers.
To this aim, you  can  add a netmask  to  the  IP address.  Both   the
following forms work:

           rshaperctl 192.168.1.16/255.255.255.240  19200
           rshaperctl 192.168.1.16/28 19200

"rshaperctl", when   called   without arguments,   shows   the current
configuration. Two options can be passed to rshaperctl:

        -n   (numeric): don't decode IP numbers to name when reporting
                configuration information
        -t   (no-title): don't print the title line in the report. This
                is useful if you feed the output to a script

Any  other  option  makes  rshaperctl  print  an  help  message.  More
information about rshaperctl is available as a man page: rshaperctl.8.

                SHAPING OUTGOING TRAFFIC
                ========================

As suggested above, in kernel  2.4 is possible to manage both incoming
and  outgoing  packets.   The  load-time  parameter  "mode"  specifies
whether the module handles  received packets, transmitted ones or both
directions. It is an integer parameter that can be set to:

        0: Outgoing
        1: Incoming (default)
        2: 2 directions

other values make the module barf and refuse to load. For example, for
bidirectional shaping use:

        insmod rshaper.o mode=2

When rshaper  works in mode 2,  the same bandwidth  limit is enforced
for both directions.

Mode 2,  bidirectional shaping, can be interesting  for leaf computers
where you  want to  limit both download  and upload speed.  However, a
router should not  use mode 2. When a packet  is forwarded through the
router and matches a shaping rule,  it will be shaped twice: both when
entering  the computer  and when  leaving  from it.  This in  practice
reduces  the available  bandwidth  to less-than-half  and reduses  the
effective length of the queue.

We know how to fix the problem, but are reluctant to add computational
overhead for every packet, so  the simple rule is: "routers should not
use mode 2, that would make no sense for them anyways".

                PATCHES (for users of Linux-2.0 and 2.2)
                ========================================

Patch files are the output of "diff -c" or "diff -u" (preferred). They
describe how to change the original  file to obtain  a new one. A good
feature of patches is that they  are human-readable, so you can always
know what is going on.

To apply a patch, feed it to the standard  input of the patch command.
The command  receives  a few  options on   its command-line,  the most
needed being "-p". "-p" tells patch to discard path components: "patch
-p1" for example discards one path-component in the file names it find
in the patch   file before looking   for  files. You  should pass  the
correct "-p"  option according to  what your current directory is when
you apply the patch file.

Specifically,  to  apply  the  "8390-2.X.c"  patch  included  in  this
distribution:

    cd /your/kernel/src; patch -p0 < /.../8390-2.X.c.patch
or
    cd /your/kernel/src/drivers/net; patch -p2 < /.../8390-2.X.c.patch


                DISCLAIMER
                ==========

This is not very refined, a  lot of interesting things can be done and
aren't;  check  shaper.c   distributed  with  Linux-2.2  or  netfilter
distributed with  Linux-2.4 to see some  of the fine  details that are
missing from there.


                LICENSE
                =======

The code  is released according  to the GPL,  in the hope you  find it
useful.

Enjoy
/alessandro and rodolfo
发表于 2010-6-13 13:54:02 | 显示全部楼层
本帖最后由 圣诞之王 于 2010-6-13 14:49 编辑

#  New (experimental) feature - "netshaper". Like the alternative "rshaper", this allows you to limit the bandwidth by IP addresses/ranges - plus a command to configure it: "netshaper"
e.g., "netshaper -d 192.168.1.6 32768" (will limit the bandwidth of the computer at 192.168.1.6 to 32kbps)
The netshaper module is NOT loaded by default. Run this command to enable it: setenv "netshaper_enable 1" && /sbin/reboot
NOTE that the netshaper facility CANNOT be used in conjunction with rshaper. You have to choose one or the other. Run "netshaper" without any arguments to see the syntax.

  fprintf (stderr, "%s: Usage: \"%s [options] bandwidth\n"
           "        \"-s <host>\" specify a source host\n"
           "        \"-d <host>\" specify a destination host\n"
           "                   <host> can specify a mask like \"/24\" or \"/255.255.255.0\"\n"
           "        \"-sport <host>\" specify a source port\n"
           "        \"-dport <host>\" specify a destination port\n"
           "        \"-p <protocol>\" specify a protocol (udp and tcp only supported\n"
           "        \"-i <iface>\" specify a input interface\n"
           "        \"-o <iface>\" specify a output interface\n"
           "        \"-t <timeout>\" specify a timeout of enqueued packets\n"
           "Note: the bandwidth is in Bytes/seconds\n"
           "see /proc/netshaper for rules info\n", prgname, prgname);
  exit (1);
发表于 2010-6-13 14:40:34 | 显示全部楼层
netshaper 命令,netshaper比RSHAPER更好更稳定。
help (char *prgname)
{
  fprintf (stderr, "%s: Usage: \"%s [options] bandwidth\n"
           "        \"-s <host>\" specify a source host\n"
           "        \"-d <host>\" specify a destination host\n"
           "                   <host> can specify a mask like \"/24\" or \"/255.255.255.0\"\n"
           "        \"-sport <host>\" specify a source port\n"
           "        \"-dport <host>\" specify a destination port\n"
           "        \"-p <protocol>\" specify a protocol (udp and tcp only supported\n"
           "        \"-i <iface>\" specify a input interface\n"
           "        \"-o <iface>\" specify a output interface\n"
           "        \"-t <timeout>\" specify a timeout of enqueued packets\n"
           "Note: the bandwidth is in Bytes/seconds\n"
           "see /proc/netshaper for rules info\n", prgname, prgname);
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|宽带技术网 |网站地图

粤公网安备 44152102000001号

GMT+8, 2024-4-18 09:57 , Processed in 0.024207 second(s), 4 queries , Redis On.

Powered by Discuz! X3.5 Licensed

Copyright © 2001-2020, Tencent Cloud.

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