2024年4月28日发(作者:)

Mangle分类标记介绍MikroTikRouterOS

Mangle 分类标记介绍MikroTik RouterOS

mangle 允许对IP 数据包做特殊的标记,mangle 是通过修改指定的IP 数据包头字

段,去标记IP 数据包的特征能标记端口、IP、协议、TCP 协议和相应的IP 数据流。

Mangle 属于综合性功能,所以在路由、流量控制和其他相应功能中都会涉及到。

需要功能包: system

需要等级: Level1

操作路径: /ip firewall mangle

协议标准: IP

Mangle 介绍Mangle 是一种标记器,标记特殊的数据包等待将来处理。在

RouterOS 中许多其他的功能组件会使用到他,如queue-trees 和nat,他们识别到一个

数据包了标记的便会做相应的处理。Mangle 标记仅存在于该路由器中,他们无法传输到

网络中去。根据数据传输方式不同可以选择:· Prerouting:路由前,常用于标记策略和

端口路由

· Input:进入路由器的数据

· Foreward:通过路由转发,用于修改TTL、TCP-MSS 和流量控制规则

· Output:数据输出

· Prostrouting:路由后RouterOS 中的IP firewall 主要由3 个规则部分组成Mangle、

Filter、NAT ,而Address-list 常用于地址列表分类。Mangle 通过标记特定的IP 数据流

后,为Filter、NAT 和、路由、Queue 提供标记后的IP 数据流

标记IP 数据流的三种类型,这三种类型会在各种应用中多次出现,特别是Queue 的

流量控制和ip route 的路由:· Mark-connection:标记所有IP 流的连接

· Mark-packet:标记IP 流中数据包

· Mark-routing:标记IP 流中IP 数据包的路由信息

三种类型的关系,所有的在IP 数据包传输前,首先需要通

过建立TCP/UDP 连接,进行传输。所以当数据通过

IP 流进入Mangle 后,建立相应的连接标记,并从连接标记中提取数据包,做处理。

图示如下:

Mangle 应用Peer-to-Peer 传输标记保证优质的网络连接,如VoIP 和HTTP 等为最

优先级,将P2P 的优先级设置为最低RouterOS QOS 操作首先使用mangle 标记不同

类型的传输,然后把它们放入的queues 做不同的限制。下面的事例是强迫P2P 的总

的传输不能超过1Mbps,其他的传输连接则扩大连接带宽和优先级:

111213

[admin@MikroTik] > /ip firewall mangle add

chain=forward p2p=all-p2p action=mark-connection

new-connection-mark=p2p_conn[admin@MikroTik] > /ip firewall mangle add

chain=forward

connection-mark=p2p_conn action=mark-packet

new-packet-mark=p2p[admin@MikroTik] > /ip firewall mangle add

chain=forward packet-mark=!p2p_conn

action=mark-packet

new-packet-mark=other[admin@MikroTik] > /ip firewall

mangle printFlags: X - disabled, I - invalid, D - dynamic0 chain=forward

p2p=all-p2p action=mark-connection

new-connection-mark=p2p_conn1

mark=p2p_conn action=mark-packet

chain=forward connection-

new-packet-mark=p2p2 chain=forward

packet-mark=!p2p_conn action=mark-packet

new-packet-mark=other[admin@MikroTik]

>[admin@MikroTik] > /queue tree add parent=Public packet-mark=p2p limit-

at=1000000 max-limit=100000000 priority=8[admin@MikroTik] > /queue tree

add

parent=Local packet-mark=p2p limit-at=1000000 max-li mit=100000000

priority=8[admin@MikroTik] > /queue tree add parent=Public packet-mark=other

limit-at=1000000 max-limit=100000000

priority=1[admin@MikroTik] > /queue tree add

parent=Local packet-mark=other limit-at=1000000

max-limit=100000000 priority=1