海运的博客

Iptables/ROS做流量控制QOS的一些理解

发布时间:November 2, 2012 // 分类:Iptables,ROS // No Comments

1.关于Iptables链PREROUTING和POSTROUTING:

#https://www.haiyun.me
PREROUTING在包进入防火墙之后,DNAT之前
POSTROUTING是在DNAT后,SNAT之前

2.在哪里标记,怎么标记上传和下载。

PREROUTING可以根据进入端口为内网或外网标记上传和下载,或根据源地址为本地、非本地标记上传、下载;
POSTROUTING可以根据发出端口、源地址标记上传;
FORWARD可以根据进入端口为内网或外网标记上传和下载,或根据源地址、目标地址都可以。

3.在哪里进行流量整形:
3.1.使用lan和wan:

lan可根据目标地址进行下载限制,正常识别。
wan根据源地址进行上传限制,在SNAT后,源地址已改变,不能正常限制流量。

3.2.使用虚拟接口,ROS使用global in和global-out,Iptables使用IMQ

global-in在PREROUTING、DNAT后,可按目标地址限制下载
global-out在POSTROUTING后,SNAT前,可按源地址限制上传。

4.使用TC限制特定IP下载、上传的问题:
4.1.限制上传使用MARK标记:

iptables -t mangle -I POSTROUTING -s 192.168.1.16 -j MARK --set-mark 27

4.2.限制下载使用U32标记:

tc filter add dev imq1 parent 1:0 protocol ip prio 4 u32 match ip dst 192.168.1.16 flowid 1:24

5.标记mark-connection和mark-packet区别
关于Iptables/ROS进行流控的一些理解,如有误请更正。

ROS通过DNAT实现推送PUSH广告、通知等服务

发布时间:November 1, 2012 // 分类:ROS // No Comments

实现:ROS下客户第一次打开网页时重定向到自定义页面,可用于推送广告、PPPOE用户到期提醒等服务。
1.在postrouting链添加规则:

add action=add-src-to-address-list address-list=LAN address-list-timeout=5m chain=postrouting dst-port=80 protocol=tcp
#经过postrouting链时添加IP至地址列表

2.在NAT表prerouting链添加DNAT,判断条件为源地址不在LAN列表,DNAT后经过postrouting链会添加IP至LAN列表,再次访问网络正常。

add action=dst-nat chain=dstnat dst-port=80 in-interface=bridge-local protocol=tcp src-address-list=!LAN to-addresses=192.168.1.4 to-ports=80
#DNAT至192.168.1.4:80
ip firewall nat add chain=srcnat action=masquerade dst-address=192.168.1.4
#添加相应SNAT

如果客户端使用PPPOE拨号可用以下脚本判断客户端是否在线,如不在线从LAN列表中将IP移除。

#https://www.haiyun.me
{:local ip
/ip firewall address-list
:foreach i in=[find list=LAN] do={
#遍历LAN列表内IP赋值ip
:set ip [get $i address]
:if ([:len [/ip address find dynamic=yes network=$ip]]=0) do={remove $i}}
#查找相应IP是否在线,不在线则IP位数为0,删除相应IP。
}

ROS下Hotspot使用user-manager验证

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

ROS配置Hotspot允许radius验证:

ip hotspot profile set hsprof use-radius=yes

添加radius客户端:

radius add service=hotspot address=192.168.1.1 secret=onovps

ROS增加user-manger用户:

tool user-manager customer add login="onovps" password="onovps" permissions=owner

增加radius验证客户:

tool user-manager router add name=Hotspot ip-address=192.168.1.1 shared-secret=123456 customer=onovps

添加用户组规则:

tool user-manager profile add name=hotspot owner=onovps

添加验证用户:

tool user-manager user add name=user password=passwd customer=onovps

也可通过Web界面www.haiyun.me/userman登录user-manager进行设置。
ros路由user-manager管理界面.png

ROS配置HotSpot热点Web认证服务

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

HotSpot是一种通过Web网页认证访问网络的方法,用户可以使网页浏览器通过HTTP快速接入网络。
ROS开启HotSpot通过以下几个步骤:
1.配置用户IP地址池:

#https://www.haiyun.me
ip pool add name=hotspot ranges=192.168.1.2-192.168.1.254

2.添加认证用户组规则:

ip hotspot user profile add name=hotspot address-pool=hotspot shared-users=1 idle-timeout=00:10 rate-limit=128k/1024k

3.添加认证用户和密码:

ip hotspot user add name=hotspot profile=hotspot server=all user=user password=passwd

4.配置服务器规则:

ip hotspot profile add name=hotspot login-by=http-chap hotspot-address=192.168.1.1 

5.新增并开启HotSpot服务:

ip hotspot add name=hotspot profile=hotspot interface=br-lan disabled=no 

然后通过ROS访问外网浏览器会自动转向hotspot认证页面:
ros hotspot认证页面.png

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

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

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

#https://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

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...