liyinguang 发表于 2010-5-12 18:15:37

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

因为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里就可以自动运行想要的功能了,大家还可以添加自己想要的命令增加更多的功能

garyhuang84424 发表于 2010-5-13 11:18:53

晕!竟然一点都看不明白!

tzhang 发表于 2010-5-18 23:08:15

请问一下 telnet 的默认账号和密码是什么?

逍遥137 发表于 2010-5-18 23:28:35

这么强的机啊,还没用过

tzhang 发表于 2010-5-19 21:38:41

楼主请教一下 运行setenv 指令设置env变量后好像没效果(返回的显示是设置成功),但重启后看不到设定的变量,是怎么回事

liyinguang 发表于 2010-5-21 09:46:03

默认账号root默认密码Admin

liyinguang 发表于 2010-5-21 09:53:36

本帖最后由 liyinguang 于 2010-5-21 10:00 编辑

楼主请教一下 运行setenv 指令设置env变量后好像没效果(返回的显示是设置成功),但重启后看不到设定的变量 ...
tzhang 发表于 2010-5-19 21:38 https://www.chinadsl.net/images/common/back.gif


这个问题偶也遇到过,照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
ismeanttolimittheincoming bandwidthforpacketsaimedat
differenthosts.With"incoming"I meantrafficthat entersthe
shaping host; ifthat host is a gateway betweentarget hosts and the
rest ofthe Internet,all thetraffic of thetarget hostswill be
shapeable.

I see two interesting uses for this tool:

        * Limiting   the bandwidth availableto permanently connected
                hosts by installing rshaper ontheir gateway. This is
                interestingfor ISPwho offerhousingand wantto
                differentiate the offer.

        * Limiting download bandwidthfrom students' boxes or similar
                setups, by installingthe   rshaper directlyonthe
                target computer. Thisrequires that the user ofthat
                computer can not gain superuser privileges.

Whilethe former issue can beaddressed with the conventional shaper
driver, the    lattercan't beeasily   addressed by   thestandard
shaper. As a matter of facts,I have not been ableto use the shaper
toaddress   the former situation,   either;   this because effective
filtering can only be achieved throughsource-routing, but when I had
to dealwiththis problem, theshaperonly existed for Linux-2.1
while my production setup was constrained to be 2.0.

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

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

First ofall "make". You'll endup with an"rshaper.o" module, that
canbe loadedto yourkernel.If yourkernel sourcesare notin
/usr/src/linux, you must tell make where they are by setting KERNELDIR
inthe environment orspecifying iton themake commandline. For
example:

        make KERNELDIR=/usr/src/linux-2.4

As suggested,the network driver youare using needsto be slightly
modifiedif yourun version2.0 or2.2 ofthe kernel.   The exact
changesto thesekernels dependon yourparticular setup,and are
described in the following section.

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

Theidea is easy:whenevera 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 samemechanism can beused foroutgoing packets
under2.4. If youuse version2.4, youcan skipthe restof this
section, otherwise please read on.

With 2.0 and 2.2, the network driver must be modified in order to call
theshaper's receivefunctioninstead ofthe standardnetif_rx().
Therefore, you should modify two lines of your network device driver.

In case you use aNE2000 clone or another 8390-based ethernet device,
you can use the patchincluded in this package as "8390-2.X.c.patch",
where 2.Xis yourkernel version (2.0or 2.2).   If you arenew to
patches, please refer to the last section.

If your ethernet driver is not an 8390-basedone, you have to do your
own changes (while I mightoffer patches forother 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.2of the Linux kernel, no symbolis exported by default
when loading a module. That'swhy you need to use the "EXPORT_SYMBOL"
macro.   However,using themacromaybenot enough:thesymbol
"EXPORT_SYMTAB" mustbe defined in orderfor the symboltable to be
exported.

Todefine the symbol,compile themodule with"-DEXPORT_SYMTAB" or
define themacro with "#defineEXPORT_SYMTAB" in themodule itself.
Thisstepisnot neededfor8390.c(thedriver usedbyNE2000
compatible devices) because that module already exports some symbols.

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

If your ethernetdriver(s) is linked in thekernel image, instead of
being a module,you must also arrange for"net_shaper_rx_hook" to be
exported to modules, so thatthe "rshaper.o" module will find it.To
dothis, applythepatch "ksyms-2.X.c.patch"(again,2.X isyour
kernel version) to kernel/ksysms.c in the kernel sources.

Pleasedon't applyksysms-2.X.c.patch ifyour networkdriveris a
module.


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

If yournetwork interfaces areof different kinds, change(3) above
mustbe appliedto allthe driversinvolved withshaping 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) mustbe loaded before the ones with
modification(1b),otherwiseloading will   failwith ``unresolved
symbol "net_shaper_rx_hook"''



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

Afterreloadingyourmodules   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 theincoming bandwidth for thehost to 6400bytes per second
and queuespackets as long asthe queue is shorterthan 10 seconds.
If thethird argument is missing,it defaults to5 seconds.

Version 1.06of the tool addsan internal limitation tothe size of
the queue, inorder to try preventing memorysaturation.The amount
of pending data is limitedby the macro RSHAPER_LIMIT_KB which can be
defined atcompile timeand defaultsto half ameg. Notethat the
memory requirements of the queue can be far greater than the amount of
IP data beinghosted, as rshaper has its owndata structures to keep
track of the packets.

To removethe limitassociate to an host, just use0 as the allowed
bandwidth:

           rshaperctl 192.168.1.2 0

From version1.04 onwards, itispossible to use computernames in
addition to IP numbers.

You can also limit the bandwidthallocated to a network of computers.
To this aim, youcanadd a netmasktotheIP address.Both   the
following forms work:

           rshaperctl 192.168.1.16/255.255.255.24019200
           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

Anyotheroptionmakesrshaperctlprintanhelpmessage.More
information about rshaperctl is available as a man page: rshaperctl.8.

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

As suggested above, in kernel2.4 is possible to manage both incoming
andoutgoingpackets.   Theload-timeparameter"mode"specifies
whether the module handlesreceived 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 rshaperworks in mode 2,the same bandwidthlimit is enforced
for both directions.

Mode 2,bidirectional shaping, can be interestingfor leaf computers
where youwant tolimit both downloadand upload speed.However, a
router should notuse mode 2. When a packetis forwarded through the
router and matches a shaping rule,it will be shaped twice: both when
enteringthe computerand whenleavingfrom it.This inpractice
reducesthe availablebandwidthto less-than-halfand redusesthe
effective length of the queue.

We know how to fix the problem, but are reluctant to add computational
overhead for every packet, sothe 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 originalfile to obtaina new one. A good
feature of patches is that theyare human-readable, so you can always
know what is going on.

To apply a patch, feed it to the standardinput of the patch command.
The commandreceivesa fewoptions 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   forfiles. Youshould passthe
correct "-p"option according towhat your current directory is when
you apply the patch file.

Specifically,toapplythe"8390-2.X.c"patchincludedinthis
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, alot of interesting things can be done and
aren't;checkshaper.c   distributedwithLinux-2.2ornetfilter
distributed withLinux-2.4 to see someof the finedetails that are
missing from there.


                LICENSE
                =======

The codeis released accordingto the GPL,in the hope youfind 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 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 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);
页: [1] 2
查看完整版本: 刷RouterTech后一些高级功能的使用心得