使用tc ingress来限速接收方向
Linux中的QoS分为入口(Ingress)部分和出口(Egress)部分,入口部分主要用于进行入口流量限速(policing),出口部分主要用于队列调度(queuing scheduling)。大多数排队规则(qdisc)都是用于输出方向的,输入方向只有一个排队规则,即ingress qdisc。ingress qdisc本身的功能很有限,如下;
Ingress qdisc
The ingress qdisc itself does not require any parameters. It differs from other qdiscs in that it does not occupy the root of a device. Attach it like this:
# tc qdisc add dev eth0 ingress
This allows you to have other, sending qdiscs on your device besides the ingress qdisc. About the ingress qdisc
Ingress qdisc (known as ffff:) can't have any children classes. (hence the existence of IMQ)
The only thing you can do with the ingress qdisc is attach filters. About filtering on the ingress qdisc
Since there are no classes to which to direct the packets, the only reasonable option is to drop the packets.
With clever use of filtering, you can limit particular traffic signatures to particular uses of your bandwidth.
具体使用如下命令,进行限速:
tc qdisc add dev vnet1 handle ffff: ingress
tc filter add dev vnet1 parent ffff: protocol all prio 49 basic police rate 10mbit burst 1mb mtu 65535 drop
根据tc相关文档描述,使用tc ingress限速,功能有限,似乎只能选择丢弃,并且也不支持分类。实际应用中,我们可以将业务流重定向到ifb设备上,业务流从这个ifb设备中出去,再又相应的端口接收,那我们就可以像正常使用tc对egress限速一样,来对ifb设备进行egress限速,就可以达到对接收方向的限速了。具体原理可以参考最下面列出的文档。
ifb模块需要手动加载。
# modprobe ifb 启用虚拟设备ifb0
# ip link set dev ifb0 up
接下来配置ifb0的过滤规则
tc qdisc add dev ens3f3 handle ffff: ingress
tc filter add dev ens3f3 parent ffff: protocol ip u32 match u32 0 0 action mirred egress redirect dev ifb0
tc qdisc add dev ifb0 root handle 1: htb default 10
tc class add dev ifb0 parent 1: classid 1:1 htb rate 10000mbit
tc class add dev ifb0 parent 1:1 classid 1:10 htb rate 1000mbit ceil 1000mbit
注:上述配置可以针对端口来限速配置,但是不能与cgroup配合完成对某些进程组限速。
本来是想用cgroup,像限速egress侧一样,限速ingress侧,但是实践后发现不生效,查过了相关的网络资料,很多人讲在ingress侧,是无法达到像cgroup一样限制带宽的,具体是与cgroup标记的先后有关系。
be aware that if you use iptable to mark your packet and then filters them, you can't use ifb since all ingress trafic will be forwarded BEFORE any marking. so you will se your class stay at 0 and all forwarded to the default. IMQ seem the rigth solution for iptables users. 来自 <https://serverfault.com/questions/350023/tc-ingress-policing-and-ifb-mirroring
但可以通过报文中的源ip进行限速控制,如下配置:
tc qdisc add dev ifb0 root handle 1: htb default 20
tc class add dev ifb0 parent 1: classid 1:1 htb rate 10000mbit
tc class add dev ifb0 parent 1:1 classid 1:10 htb rate 2000mbit
tc class add dev ifb0 parent 1:1 classid 1:20 htb rate 1000mbit
tc class add dev ifb0 parent 1:1 classid 1:30 htb rate 500mbit
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip src 129.9.123.85 flowid 1:10
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip src 129.9.123.89 flowid 1:20
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip src 129.9.123.88 flowid 1:20
当然我们也可以通过源端口和目的端口来限速,如下配置:
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip dport 50051 0xffff flowid 1:30
tc filter add dev ifb0 protocol ip parent 1:0 prio 1 u32 match ip sport 45678 0xffff flowid 1:30
参考文档:
https://blog.csdn.net/zhangskd/article/details/8240290
https://www.cnblogs.com/CasonChan/p/4919921.html
使用tc ingress来限速接收方向的更多相关文章
- 使用iptables和tc对端口限速
首先,我们来看一下tc,TC(Traffic Control)命令,是linux自带的告警流控命令.Linux操作系统中的流量控制器TC(Traffic Control)用于Linux内核的流量控制, ...
- tc令牌桶限速心得
一.实验拓扑与实验现象 实验拓扑如图所示,在①号机上发送数据,③号机上接受数据,同时在④号机的eth1与eth2网口限制速率为115200kbps,命令如下 tc qdisc add dev eth1 ...
- 使用tc配置后端设备,来限制虚拟机网卡带宽
如果通过tc来限制虚拟机网卡接收方向带宽呢,实际上使用tc对接收方向限制的不够好,使用tc ingress可以限制接收,但是功能不够多,而且会形成丢包问题.一般是采用将流量重定向到一个虚拟设备ifb上 ...
- 使用tc对linux中某ip段限速
TC 无需安装,Linux 内核自带例:将IP地址段192.168.1.0/24 上传下载限速为 5M将以下内容添加到/etc/ppp/ip-up文件exit 0上面. down=5Mbituploa ...
- ios的位置和方向(来自苹果官方文档,仅供简单参考)
取得用户的当前位置 Core Location框架使您可以定位设备的当前位置,并将这个信息应用到程序中.该框架利用设备内置的硬件,在已有信号的基础上通过三角测量得到固定位置,然后将它报告给您的代码.在 ...
- iOS使用位置和方向服务(来自苹果apple官方)
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] 本文章来自苹果官方文档,特此声明--------禚 Core Location框架为定位用户当前位置和方向(Headin ...
- 全面介绍eBPF-概念
全面介绍eBPF-概念 前面介绍了BCC可观测性和BCC网络,但对底层使用的eBPF的介绍相对较少,且官方欠缺对网络方面的介绍.下面对eBPF进行全面介绍. 目录 全面介绍eBPF-概念 BPF概述 ...
- opencontrail-vrouter命令
vif命令 vrouter需要vrouter接口(vif)来转发流量.使用vif命令查看vrouter已知的接口. 注意: 仅在OS(Linux)中使用接口不足以进行转发.相关接口必须添加到vrout ...
- iptables 安全
注解:来自某位大神的详解,做个笔记. iptables防火墙简介 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的安全自由的**基于包 ...
随机推荐
- 测试提高路线图_tester+
https://mp.weixin.qq.com/s/30ZT0w164Q3iLdPg4R8org
- 根据经纬度坐标获得省市区县行政区划城市名称,自建数据库 java python php c# .net 均适用
目录 步骤一.下载省市区边界数据 步骤二.解析CSV文件导入数据库 步骤三.在程序中根据坐标解析获得城市 在LBS应用中,根据坐标来解析获得对应是哪个城市是一个很常见的功能,比如App里面通过手机定位 ...
- VLAN介绍及实验
目录 一.VLAN 1.1.VLAN的概念及优势 1.2.VLAN的种类 1.3.静态VLAN的配置 1.4.Trunk的作用 1.5.配置实验 1.搭建拓扑图 2.交换机SW1配置情况 3.交换机S ...
- 【流行前沿】联邦学习 Federated Learning with Only Positive Labels
核心问题:如果每个用户只有一类数据,如何进行联邦学习? Felix X. Yu, , Ankit Singh Rawat, Aditya Krishna Menon, and Sanjiv Kumar ...
- MySQL 5.7 基于GTID主从复制+并行复制+半同步复制
环境准备 IP HOSTNAME SERVICE SYSTEM 192.168.131.129 mysql-master1 mysql CentOS7.6 192.168.131.130 mysql- ...
- C++奇异递归模板模式
虚函数的问题 虚函数的主要问题是性能开销比较大,一个虚函数调用可能需要花费数倍于非虚函数调用的时间,尤其是当非虚函数被声明为inline时(注意,虚函数不能被内联). CRTP介绍 CRTP的全称是C ...
- 疑难杂症:运用 transform 导致文本模糊的现象探究
在我们的页面中,经常会出现这样的问题,一块区域内的文本或者边框,在展示的时候,变得特别的模糊,如下(数据经过脱敏处理): 正常而言,应该是这样的: emmm,可能大图不是很明显,我们取一细节对比,就非 ...
- 多个n维向量围成的n维体积的大小
前言 上周我们数学老师给了我们一道题,大意就是两个向量a和b,一个点M=$x*a+y*b$,x,y有范围,然后所有M组成的面积是一个定值,求x+y的最小值.当然这是道小水题,但我在想,如果把两个向量变 ...
- Python:读取二进制文件时使用print输出\x
问题: 有二进制文件,通过open打开和read()读入并输出时,输出为\x十六进制编码,不能正确显示其具体代表的字符 with open(r'C:\Users\Le\Desktop\Test\tki ...
- Leaflet:Path、Polyline、Polygon、Rectangle、Circle、CircleMarker
下边介绍Vector Layer Path(Layer) Path是其他Vector Layer的父类,比如Polyline.Polygon.Rectangle.Circle.CircleMarker ...