admin管理员组

文章数量:1533081

2023年12月19日发(作者:)

ROS软路由防火墙规则(转自网络)

routeros防火墙功能非常灵活。routeros防火墙属于包过滤防火墙,你可以定义一系列的规则过滤掉发往routeros、从routeros发出、通过routeros转发的数据包。在routeros防火墙中定义了三个防火墙(过滤)链(即input、forward、output),你可以在这三个链当中定义你自己的规则。

input意思是指发往routeros自己的数据(也就是目的ip是routeros接口中的一个ip地址);

output意思是指从routeros发出去的数据(也就是数据包源ip是routeros接口中的一个ip地址);

forward意思是指通过routeros转发的(比如你内部计算机访问外部网络,数据需要通过你的routeros 进行转发出去)。

禁止ping routeros,我们一般需要在input链中添加规则,因为数据包是发给routeros的,数据包的目标ip是routeros的一个接口ip地址。(当然如果你硬是要在output里建立一条规则过滤掉icmp信息也能做到ping不通,当你ping的数据包到达routeos时,routeos能接收这个数据包并做出回应,当routeros回应给你的包要发出去的时候会检查output的规则并过滤掉回应你的包。)

在每条链中的每条规则都有目标ip,源ip,进入的接口(in interface),非常灵活的去建立规则。比如ROS 禁止PING,禁止外网ping你routeros,只需要在in

interface中选择你连外部网络的接口。禁止内部ping 的话可以选择连你内部网络的接口。如果禁止所有的ping的话,那么接口选择all。当然禁止ping 协议要选择icmp ,action选择drop或reject。

另外要注意的就是,icmp协议并不是就指的是ping,而是ping是使用icmp协议中的一种(我们ping 出去发送的数据包icmp协议的类型为8 代码为0,在

routeros中写为icmp-options=8:0;而我们对ping 做出回应icmp类型为0 代码为0),还有很多东西也属于icmp协议。打个比方,如果你禁止内部网络ping 所有外部网络,可以在forward链中建立一条规则,协议为icmp,action为drop,其他默认,那么你内部网络ping不通外部任何地址,同时如果你用trancroute命令跟踪路由也跟踪不了。在做规则是要注意每一个细节。

还有就是,input,output,forward三条链在routeros中默认都是允许所有的数据。也就是除非你在规则中明确禁止,否则允许。可以通过ip firewall set

input policy=drop等进行修改默认策略

ros防火墙名词解释

input - 进入路由,并且需要对其处理

forward - 路由转发

output - 经过路由处理,并且从接口出去的包

action:

1 accept:接受

add-dst-to-address-list - 把一个目标IP地址加入address-list

add-src-to-address-list - 把一个源IP地址加入address-list

2 drop - 丢弃

3 jump - 跳转,可以跳转到一个规则主题里面,如input forward,也可以跳转到某一条里面

4 log - 日志记录

5 passthrough - 忽略此条规则

6 reject - 丢弃这个包,并且发送一个ICMP回应消息

7 return - 把控制返回给jump的所在

8 tarpit - 捕获和扣留进来的TCP连接(用SYN/ACK回应进来的TCP SYN 包)

address-list (name) - 把从action=add-dst-to-address-list or

action=add-src-to-address-list actions得到的IP地址放入address-list列表. 这个列表要用来对比address-list-timeout 看是什么时候用address-list

parameter从address list中移走

chain (forward | input | output | name) - 使用chain得到特定列表,不同的数据流经过不同的chain规则

要仔细的选对正确的访问控制. 如果input 不是非常的确定和一个新的规则需要添加注释,

transfered through the particular connection

0的意思是无限的,例如connection-bytes=2000000-0 意思是2MB以上

connection-limit (integer | netmask) - 地址的传输流量控制

connection-mark (name) - 传输中的标记后的数据包

connection-state (estabilished | invalid | new | related) - 连接的状态(连接中,不规则的连接,新的连接,相互联系的连接)

connection-type 连接的类型(ftp | gre | h323 | irc | mms | pptp |

quake3 | tftp)

content 包的内容

dst-address (IP address | netmask | IP address | IP address) - 目标地址

dst-address-list (name) - 目标地址表

dst-address-type (unicast | local | broadcast | multicast) - 目标地址类型

unicast -点对点

local - 本地地址

broadcast - 广播

multicast - 多播

dst-limit (integer | time | integer | dst-address | dst-port | src-address | time) - 目标限制

Count - 每秒最大的包数量

by Time option

Time - 时间

Burst - 突发的

Mode -等级优先

Expire - 终止

dst-port 目标端口

hotspot 暂时不做学习

icmp-options (integer | integer) - ICMP 选择

in-interface (name) - 进入接口

ipv4-options (any | loose-source-routing | no-record-route | no-router-alert | no-source-routing |no-timestamp | none | record-route |

router-alert | strict-source-routing | timestamp)

any - match packet with at least one of the ipv4 options

loose-source-routing - match packets with loose source routing

option. This option is used toroute the internet datagram based on

information supplied by the source

no-record-route - match packets with no record route option. This

option is used to route the

internet datagram based on information supplied by the source

no-router-alert - match packets with no router alter option

no-source-routing - match packets with no source routing option

no-timestamp - match packets with no timestamp option

record-route - match packets with record route option

router-alert - match packets with router alter option

strict-source-routing - match packets with strict source routing

option

timestamp - match packets with timestamp

jump-target (forward | input | output | name) -跳转

limit (integer | time | integer) - 限制

Count - 每秒最大的包数量

Time - 突发的总时间

log-prefix (text) - 如果还有定义的字符,加入日志

out-interface (name) - 流出的接口

p2p (all-p2p | bit-torrent | blubster | direct-connect | edonkey |

fasttrack | gnutella | soulseek | warez

| winmx) - P2P协议

packet-mark (text) - 给包标记

packet-size (integer: 0..65535 | integer: 0..65535) - 包大小

range in bytes

Min - 最小

Max - 最大

phys-in-interface (name) - 物理上的进入接口

phys-out-interface (name) -物理上的出去接口

protocol (ddp | egp | encap | ggp | gre | hmp | icmp | idrp-cmtp |

igmp | ipencap | ipip | ipsec-ah |ipsec-esp | iso-tp4 | ospf | pup | rdp

| rspf | st | tcp | udp | vmtp | xns-idp | xtp | integer) -协议

psd (integer | time | integer | integer) - 防止对ROS的端口扫描

random (integer: 1..99) - matches packets randomly with given

propability

reject-with (icmp-admin-prohibited | icmp-echo-reply | icmp-host-prohibited |

icmp-host-unreachable | icmp-net-prohibited | icmp-network-unreachable | icmp-port-unreachable

|icmp-protocol-unreachable | tcp-reset | integer) - 改变reject的回答方式

routing-mark (name) - 路由标记

src-address (IP address | netmask | IP address | IP address) -源地址

src-address-list (name) -源地址列表

src-address-type (unicast | local | broadcast | multicast) - 源地址类型

src-mac-address (MAC address) - 源MAC地址

src-port (integer: 0..65535 | integer: 0..65535) - 源端口

tcp-flags (ack | cwr | ece | fin | psh | rst | syn | urg) -TCP 标志类型

ack - acknowledging data

cwr - congestion window reduced

ece - ECN-echo flag (explicit congestion notification)

fin - close connection

psh - push function

rst - drop connection

syn - new connection

urg - urgent data

tcp-mss (integer: 0..65535) - TCP MSS

time (time | time | sat | fri | thu | wed | tue | mon | sun) -

allows to create filter based on the packets'

arrival time and date or, for locally generated packets, departure

time and date

tos (max-reliability | max-throughput | min-cost | min-delay |

normal) - specifies a match for the

value of Type of Service (ToS) field of an IP header

max-reliability - maximize reliability (ToS=4)

max-throughput - maximize throughput (ToS=8)

min-cost - minimize monetary cost (ToS=2)

min-delay - minimize delay (ToS=16)

normal - normal service (ToS=0)

:foreach i in=[/system logging facility find local=memory ]

do=[/system logging facility set $i local=none]

RO防syn

ip-firewall-connections

Tracking:TCP Syn Sent Timeout:50

TCP syn received timeout:30

限线程脚本:

:for aaa from 2 to 254 do={/ip firewall filter add chain=forward

src-address=(192.168.0. . $aaa) protocol=tcp connection-limit=50,32

action=drop}

RO端口的屏蔽

ip-firewall-Filer Rules里面选择

forward的意思代表包的转发

firewall rule-General

s:要屏蔽的端口

Protocol:tcp

Action:drop(丢弃)

ros限速

手动限速

winbox---queues----simple queues

点“+”,NAME里随便填,下面是IP地址的确定

①Target Address 不管,Dst. Address里填你要限制的内网机器的IP,比如我这里有个1号机器IP为192.168.1.101,那s 里就填192.168.1.101

然后是/32(这里的32不是指掩码了,个人理解为指定的意思)!

②interface里记着要选你连接外网那个卡,我这里分了“local和public”,所以选public

③其他的不管,我们来看最重要的东西拉,Max limit ,这个东西是你限制的上限,注意的是这里的数值是比特位,比如我要限制下载的速度为500K 那么就填入多少呢?500 X 1000 X 8=400 0000=4M。

④另外,很多朋友都有个疑问,到底一般的用户会有多大流量呢?一般的网络游戏,如梦幻西游传奇封神榜等等,其下行在20Kbps以内!最耗网络资源的就是下载-----我们就是为了限制它拉,其次是VOD 点播,一般DVD格式的大约要2M多吧,所以你看情况限制拉别搞的太绝!!!

限速脚本:

:for aaa from 2 to 254 do={/queue simple add name=(queue . $aaa)

dst-address=(192.168.0. . $aaa) limit-at=0/0 max-limit=2000000/2000000}

说明:

aaa是变量

2 to 254是2~254

192.168.0. . $aaa是IP

上两句加起来是192.168.0.2~192.168.0.254

connection-limit=50是线程数这里为50

max-limit=2000000/2000000是上行/下行

使用:

WinBox-System-Scripts-+

Name(脚本名程)

Source(脚本)

OK-选择要运行的脚本-Run Script

ROS限速的极致应用

一般我们用ros限速只是使用了max-limit,其实ros限速可以更好的运用。比如我们希望客户打开网页时速度可以快一些,下载时速度可以慢一些。ros2.9就可以实现。

max-limit------我们最常用的地方,最大速度

burst-limit--------突破速度的最大值

burst-thershold--------突破速度的阀值

burst-time-------突破速度的时间值

解释一下图片的限制意义

当客户机在30秒(burst-time)内的平均值小于突破速度阀值(burst-thershold)180K时,客户机的最大下载速率可以超过最大限速值(max-limit)200K,达到突破最大值(burst-limit)400K,如果30秒内平均值大于180K,那客户机的最大速度只能达到200K。

这样也就是当我们开网页时可以得到一个更大的速度400K,长时间下载时速度只能得到200K,使我们的带宽可以更有效的利用

动态限速

ROS动态限速(检测外网总速度进行限速开关)废话不说先看脚本原理:

以下操作全部在WINBOX界面里完成

介绍:可以实现在总速度不超过9M的情况下自动关闭所有生成的限速规则在总速度超过18M的时候自动启动所有生成的限速规则。

说明:在输入脚本内容时不要把两边的()带上,那个是为了区分非脚本字符。

总速度=你的外网网卡当前速度。

打开/system/scripts

脚本:

:for aaa from 1 to 254 do={/queue simple add name=(ip_ . $aaa) dst-address=(192.168.0. . $aaa) interface=wan max-limit=256000/800000 burst-limit=1000000/3000000 burst-threshold=128000/512000

burst-time=30s/1m }

上面是生成限速树,对网段内所有IP的限速列表!

下面进入正题:

脚本名:node_on

脚本内容:(:for aaa from 1 to 254 do={/queue sim en [find name=(ip_ .

$aaa)]})

脚本名:node_off

脚本内容:(:for aaa from 1 to 254 do={/queue sim dis [find

name=(ip_ . $aaa)]})

scripts(脚本部分)以完成

打开/tools/traffic monitor

新建:

名:node_18M traffic=received trigger=above on event=node_on

threshold:18000000

新建:

名:node_9M traffic=received trigger=below on event=node_off

threshold:9000000

在输入脚本内容时不要把两边的()带上,那个是为了区分非脚本字符。

ROS映射

ip-firewall-Destination NAT

General-In. Interface all(如果你是拨号的就选择pppoe的、固定IP选择all即可)

Dst. Address:外网IP/32

Dst. Port:要映射的端口

Protocol:tcp(如果映射反恐的就用udp)

Action action:nat

TO ses:你的内网IP

TO :要映射的端口

ip伪装

ip-firewall-Source NAT

Action Action:masquerade(IP伪装)

回流(因为假如说在本网吧做SF需要回流)

ip-firewall-Source NAT

在s:192.168.0.0/24 这里特殊说明下内网ip段24代表定值不可修改ROS的IP:mac绑定

绑定:foreach i in=[/ip arp find dynamic=yes ] do=[/ip arp add copy-from=$i]

解除绑定:foreach i in=[/ip arp find ] do=[/ip arp remove $i]

完了在interfaces里面选择内网在选择reply-only

ROS设置的备份(两种方法)

files-file list

backup即可(可以到你的ftp里面找)背份资料命令行:system回车backup回车

save name=设置文件名回车

资料恢复命令

system回车

backup回车

load name=文件名回车

本文标签: 规则速度限速脚本防火墙