海运的博客

ROS下单线ADSL使用HTB+PCQ限速

发布时间:October 18, 2012 // 分类:ROS // 7 Comments

单线ADSL带宽4M,线路损耗后实际速度3.5M左右,上传350k左右,由于ADSL满速下载、上传速度会变慢,配置ROS最高上传、下载不得超过总带宽90%,QOS配置如下:
首先分类标记上传、下载数据:

#http://www.haiyun.me
/ip firewall mangle
#小数据
add chain=prerouting action=mark-connection new-connection-mark=Small-conn passthrough=yes protocol=icmp comment=Small
add chain=prerouting action=mark-connection new-connection-mark=Small-conn passthrough=yes protocol=udp dst-port=53
add chain=postrouting action=mark-connection new-connection-mark=Small-conn passthrough=yes protocol=udp dst-port=53
add chain=prerouting action=mark-connection new-connection-mark=Small-conn passthrough=yes protocol=udp dst-port=123
add chain=postrouting action=mark-packet new-packet-mark=Small-up passthrough=no out-interface=pppoe-out1 connection-mark=Small-conn 
add chain=prerouting action=mark-packet new-packet-mark=Small-up passthrough=no in-interface=bridge-local connection-mark=Small-conn 
add chain=prerouting action=mark-packet new-packet-mark=Small-down passthrough=no in-interface=pppoe-out1 connection-mark=Small-conn 
#SSH及VPN
add chain=prerouting action=mark-connection new-connection-mark=SSH-conn passthrough=yes protocol=tcp dst-port=22 comment=SSH
add chain=prerouting action=mark-connection new-connection-mark=SSH-conn passthrough=yes protocol=tcp dst-port=23
add chain=prerouting action=mark-packet new-packet-mark=SSH-up passthrough=no in-interface=bridge-local connection-mark=SSH-conn 
add chain=prerouting action=mark-packet new-packet-mark=SSH-down passthrough=no in-interface=pppoe-out1 connection-mark=SSH-conn 
#网页数据
add chain=prerouting action=mark-connection new-connection-mark=HTTP-conn passthrough=yes protocol=tcp dst-port=80 comment=HTTP
add chain=prerouting action=mark-connection new-connection-mark=HTTP-conn passthrough=yes protocol=tcp dst-port=443
add chain=prerouting action=mark-packet new-packet-mark=HTTP-up passthrough=no in-interface=bridge-local connection-mark=HTTP-conn 
add chain=prerouting action=mark-packet new-packet-mark=HTTP-down passthrough=no in-interface=pppoe-out1 connection-mark=HTTP-conn 
#其它
add chain=prerouting action=mark-connection new-connection-mark=Other-conn passthrough=yes comment=Other
add chain=prerouting action=mark-packet new-packet-mark=Other-up passthrough=no in-interface=bridge-local connection-mark=Other-conn 
add chain=prerouting action=mark-packet new-packet-mark=Other-down passthrough=no in-interface=pppoe-out1 connection-mark=Other-conn

新建队列类型为PCQ

#pcq-rate为每个了数据流最大速度,0为按数据流数公平分配带宽,pcq-limit为每一数据流队列长度;
#pcq-total-limit不能小于内网主机数*pcq-limit。
/queue type 
add name="Small-down" kind=pcq pcq-rate=0 pcq-limit=50 pcq-classifier=dst-address pcq-total-limit=2000 
add name="Small-up" kind=pcq pcq-rate=50k pcq-limit=50 pcq-classifier=src-address pcq-total-limit=2000 
add name="SSH-down" kind=pcq pcq-rate=0 pcq-limit=50 pcq-classifier=dst-address pcq-total-limit=2000 
add name="SSH-up" kind=pcq pcq-rate=50k pcq-limit=50 pcq-classifier=src-address pcq-total-limit=2000 
add name="HTTP-down" kind=pcq pcq-rate=0 pcq-limit=50 pcq-classifier=dst-address pcq-total-limit=2000 
add name="HTTP-up" kind=pcq pcq-rate=80k pcq-limit=50 pcq-classifier=src-address pcq-total-limit=2000 
add name="Other-down" kind=pcq pcq-rate=0 pcq-limit=50 pcq-classifier=dst-address pcq-total-limit=2000 
add name="Other-up" kind=pcq pcq-rate=30k pcq-limit=50 pcq-classifier=src-address pcq-total-limit=2000 

添加队列树调用之前标记的数据包设置优先级,队列类型设置为之前新建的PCQ类型。

/queue tree
add name="Parent-up" parent=global-out limit-at=330k max-limit=330k
add name="Parent-down" parent=global-in limit-at=3300k max-limit=3300k
add name=Small-up parent=Parent-up packet-mark=Small-up limit-at=70k max-limit=150k queue=Small-up priority=1
add name=Small-down parent=Parent-down packet-mark=Small-down limit-at=500k max-limit=1000k queue=Small-down priority=1
add name=SSH-up parent=Parent-up packet-mark=SSH-up limit-at=70k max-limit=200k queue=SSH-up priority=2
add name=SSH-down parent=Parent-down packet-mark=SSH-down limit-at=500k max-limit=1000k queue=SSH-down priority=2
add name=HTTP-up parent=Parent-up packet-mark=HTTP-up limit-at=150k max-limit=200k queue=HTTP-up priority=3
add name=HTTP-down parent=Parent-down packet-mark=HTTP-down limit-at=2000k max-limit=3000k queue=HTTP-down priority=3
add name=Other-up parent=Parent-up packet-mark=Other-up limit-at=20k max-limit=80k queue=Other-up priority=4
add name=Other-down parent=Parent-down packet-mark=Other-down limit-at=200k max-limit=2000k queue=Other-down priority=4

ros+htb+pcq限速.png
ROS路由设置HTB+PCQ流量控制的一些注意事项

1.WAN限制上传,按源地址分组;LAN限制下载,按目标地址分组;
2.passthrough是否继续向下匹配此链接,选择yes会向下匹配,下面规则如有匹配标记会改变;
3.在HTB首先满足Limit At,在父级有剩余带宽的前提下才会Max Limit,优先级高的队列优先获得Max Limit;
4.mark-connection的数据包是双向的,然后通过mark-pack区分上传和下载;
5.global-in在DNAT后,global-out在SNAT前,分别可匹配目标地址和源地址。

ROS数据包流程图:
ros数据包流程图.png
ROS防火墙处理数据包流程.png

ROS软路由开启配置UPNP

发布时间:October 17, 2012 // 分类:ROS // No Comments

ROSUPNP配置:

#http://www.haiyun.me
ip upnp set enabled=yes 
ip upnp interfaces add interface=pppoe-out1 type=external disabled=no 
ip upnp interfaces add interface=bridge-local type=internal disabled=no 

启动支持UPNP的软件进行测试,如迅雷:

ip firewall nat print all 
chain=srcnat action=masquerade out-interface=pppoe-out1 
chain=dstnat action=dst-nat to-addresses=192.168.1.250 to-ports=41019 protocol=tcp\
 dst-address=8.8.8.8 dst-port=41019 
chain=dstnat action=dst-nat to-addresses=192.168.1.250 to-ports=64677 protocol=udp\
 dst-address=8.8.8.8 dst-port=41019 

可见UPNP已为迅雷添加端口DNAT。

PPPOE服务器CHAP连接验证流程

发布时间:August 28, 2012 // 分类:ROS // No Comments

ROS配置PPPOE服务器,连接 PPPOE服务器监听数据包如下:

07:50:52.398419 PPPoE PADI [Service-Name] [Host-Uniq 0x12150000]
07:50:52.398461 PPPoE PADO [Host-Uniq 0x12150000] [Service-Name] [AC-Name "MikroTik"] [Service-Name "pppoe"]
07:50:52.400079 PPPoE PADR [Service-Name] [Host-Uniq 0x12150000]
07:50:52.400120 PPPoE PADS [ses 0x12] [Host-Uniq 0x12150000] [Service-Name]
07:50:52.402604 PPPoE  [ses 0x12] LCP, Conf-Request (0x01), id 1, length 16
07:50:52.402611 PPPoE  [ses 0x12] LCP, Conf-Request (0x01), id 1, length 21
07:50:52.402611 PPPoE  [ses 0x12] LCP, Conf-Ack (0x02), id 1, length 16
07:50:52.403494 PPPoE  [ses 0x12] LCP, Conf-Ack (0x02), id 1, length 21
07:50:52.403502 PPPoE  [ses 0x12] CHAP, Challenge (0x01), id 1, Value 3cca193423b93a6e8b13609aa4209bf1, Name MikroTik
07:50:52.406462 PPPoE  [ses 0x12] LCP, Echo-Request (0x09), id 0, length 10
07:50:52.406467 PPPoE  [ses 0x12] LCP, Echo-Reply (0x0a), id 0, length 10
07:50:52.408030 PPPoE  [ses 0x12] CHAP, Response (0x02), id 1, Value 8fbdbac8f438f0c540fc21f801d0e6fe, Name user
07:50:52.408050 PPPoE  [ses 0x12] CHAP, Success (0x03), id 1, Msg Welcome.

PPPOE连接验证流程如下:

#http://www.haiyun.me
客户端开始连接发送广播包PADI寻找PPPOE服务器
PPPOE服务器接受到PADI广播包后,回复PADO注明主机名、服务类型。
客户端选择PPPOE服务器。
PPPOE服务器收到客户端发送的PADR消息后,给客户端分配会话ID并进行会话确认。
PPPOE服务器主动向客户端主动发起连接,发送一些随机字符串、id和PPPOE服务器的主机名作为连接信息。
客户端根据PPPOE服务器连接信息中字符串、id、主机名、账号密码计算出md5值发送给PPPOE服务器,同时明文发送账号。
PPPOE服务器确认验证信息是否正确,若正确定进行网络配置阶段,错误则断开链路。

ROS简单队列限速和PCQ动态限速配置/HTB队列树优先级限制

发布时间:July 28, 2012 // 分类:ROS // No Comments

1.ROS网络管理功能十分强大,如需简单对IP或网段进行限速可使用简单队列限速。

queue simple add target-addresses=192.168.0.0/24 limit-at=500000/1000000  max-limit=1000000/2000000 \
burst-threshold=1000000/1000000 burst-limit=1000000/3000000 burst-time=8/8 
#limit-at 限制在此速率
#max-limit 空闲时可用最大速率,未设置等于limit-at
#burst-threshold 速率阀值
#burst-limit 单位时间内速率低于阀值,可突破至此速率
#burst time 突破速率的时间间隔

2.使用简单限速用户较少时会造成带宽的浪费,为此可使用PCQ动态限速。

queue type add name=down-pcq kind=pcq pcq-rate=0 pcq-limit=50 pcq-total-limit=2000 pcq-classifier=dst-address
#PCQ下载队列,针对内部目标IP
#默认情况下仅能容纳50个用户,即2000/50,用户较多时可调整pcq-total-limit或pcq-limit数值
queue type add name=up-pcq kind=pcq pcq-rate=0 pcq-limit=50 pcq-total-limit=2000 pcq-classifier=src-address   
#PCQ上传队列,针对内部源IP
queue simple add name=pcq-queue target-addresses=192.168.1.0/24 max-limit=500000/1000000 queue=up-pcq/down-pcq
#新建简单队列应用PCQ规则

3.基于等级优先级HTB设置,可针对IP、协议进行限制。

ip firewall mangle add chain=forward action=mark-connection new-connection-mark=1.2 src-address=192.168.1.2 passthrough=yes 
ip firewall mangle add chain=forward action=mark-connection new-connection-mark=1.3 src-address=192.168.1.3 passthrough=yes 
#标记特定的连接
ip firewall mangle add chain=forward action=mark-packet new-packet-mark=1.2 connection-mark=1.3 passthrough=no 
ip firewall mangle add chain=forward action=mark-packet new-packet-mark=1.3 connection-mark=1.3 passthrough=no 
#标记特定连接的所有数据包

建立父队列:

queue tree add name=totaldown parent=ether2 limit-at=2000000 max-limit=2000000
queue tree add name=totalup parent=ether1 limit-at=500000 max-limit=500000 
#标记数据LAN为下载,WAN为上传
#Global-in识别Prerouting标记的数据
#Global-out/total能识别pre,forward,post标记的数据

建立子队列:

queue tree add name=pc1.2down parent=totaldown limit-at=2000000 max-limit=2000000 priority=2 
queue tree add name=pc1.2up parent=totalup limit-at=500000 max-limit=5555500000 priority=2 
queue tree add name=pc1.3down parent=totaldown  limit-at=1000000 max-limit=1000000 priority=3 
queue tree add name=pc1.3up parent=totalup  limit-at=500000 max-limit=500000 priority=3 

ROS配置PPTPD VPN服务器

发布时间:July 28, 2012 // 分类:ROS // No Comments

新建PPTP客户端IP池:

ip pool add name=ppptp ranges=192.168.2.2-192.168.2.254  

新建PPTP模板:

ppp profile add name=pptp local-address=ppptp remote-address=ppptp dns-server=192.168.1.1 

新建PPTP用户:

ppp secret add service=pptp name=user password=passwd profile=pptp 

开启PPTP服务器:

interface pptp-server server set enabled=yes 

配置PPTP客户NAT转发:

ip firewall nat add chain=srcnat action=masquerade to-addresses=0.0.0.0 src-address=192.168.2.0/24 out-interface=ether1

PPTP客户端配置:

interface pptp-client add connect-to=192.168.1.22 user=user password=passwd disabled=no

Windows下连接方法略过:

PPP adapter PPTP:

        Connection-specific DNS Suffix  . :
        Description . . . . . . . . . . . : WAN (PPP/SLIP) Interface
        Physical Address. . . . . . . . . : 00-53-45-00-00-00
        Dhcp Enabled. . . . . . . . . . . : No
        IP Address. . . . . . . . . . . . : 192.168.2.253
        Subnet Mask . . . . . . . . . . . : 255.255.255.255
        Default Gateway . . . . . . . . . : 192.168.2.253
        DNS Servers . . . . . . . . . . . : 192.168.1.1
分类
最新文章
最近回复
  • 海运: 你是编译不成功呢?还是编译后不能运行呢?还是运行后不能访问web界面呢?
  • 白墨: 可能不清楚就是编译安装后启动后访问不了web界面
  • 白墨: 你好博主按照你的教程是编译安装不了的,在centos7版本下,我在开源镜像站下载centos7...
  • 感谢: 好的谢谢。
  • 海运: 可在github选择指定的branch或tag查看Makefile文件内核版本git指定bra...
  • 感谢: 请问一下“git checkout 20181012”这条命令是什么意思,没有google到。...
  • 海运: 抱歉,我没用蓝牙,现在N1在稳定挂PT中,没法折腾了。
  • hxhw: 大神能弄一個N1盒子開啟藍芽的教程不?我目前的藍芽識別不了似的(BD Address: 00:...
  • 海运: 抱歉,没用过wireguard,不了解具体情况。看错误提示是创建虚拟网卡的类型wireguar...
  • zhu tie: 本人小白我想在n1上装wireguard,安装后错误信息如下:wg-quick up wg0[...
页面执行耗时:0.0742秒。-->