Linux下的流量整形
在哪里可以了解有关 Linux 下控制/询问网络接口的信息?我想获得特定的应用程序上传/下载速度,并对特定应用程序实施速度限制。
我特别想要能够帮助我使用 Python 编写流量整形应用程序的信息。
Where can I learn about controlling/interrogating the network interface under Linux? I'd like to get specific application upload/download speeds, and enforce a speed limit for a specific application.
I'd particularly like information that can help me write a traffic shaping application using Python.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要 iproute2 套件,在其中使用 tc 命令。 tc 命令看起来像
下面是使用 iproute2 的现有的 Python 流量整形应用程序。
You want the iproute2 suite, in which you use the tc command. tc commands look like
Here's an existing Python traffic-shaping application that uses iproute2.
实际上,使用 Linux 内核工具对每个应用程序进行整形是相当困难的,除非应用程序使用您可以匹配的特定 IP 地址和/或端口。
假设是这种情况,那么您需要阅读 iptables,特别是 fwmarks。您还需要阅读
tc
。结合使用这两个工具可以完成您想要的事情。 Linux 高级路由&交通控制是一个很好的起点。假设您的应用程序不使用可预测的端口/IP 地址集,那么您需要使用用户空间整形器,例如 涓流。它会将自身插入到应用程序和内核之间,并在用户空间中调整该应用程序的流量。
我不认为这些工具有任何直接的 python 绑定,但使用 python 编写脚本并直接调用可执行文件会很简单。
It is actually quite hard shaping per application using the linux kernel tools, unless the application uses specific ip addresses and/or ports you can match on.
Assuming that is the case then you'll need to read up on
iptables
and in particular fwmarks. You'll also need to read up ontc
. In combination those two tools can do what you want. The Linux Advanced Routing & Traffic Control is a good place to start.Assuming your application doesn't use a predictable set of ports/ip addresses then you'll need to use a userspace shaper like Trickle. This inserts itself between the application and the kernel and shapes the traffic for that application in userspace.
I don't think there are any direct python bindings for any of those tools, but it would be simple to script them using python and just calling the executables directly.
特定应用程序的带宽限制(在本例中为 google-chrome):
单位为 kbits
以太网设备的总带宽限制:
单位再次为 kbits。将 eth0 更改为您的接口名称。它使用 tc tbf 和 htb...
要掌握 linux 上的连接,命令和您需要学习的程序是:
您需要用作参考的文档是:
Cookbook 在该文档中提供了很好的示例。
一个易于阅读的流畅博客页面是:
不要忘记尝试它们并从中获得乐趣;)。
Bandwidth limiting for specific application (google-chrome in this case):
units are in kbits
Total bandwidth limiting for an ethernet device :
Units are in kbits again. Change eth0 to your interface name. It uses tc tbf and htb...
To master connectivity on linux, commands & programs you need to learn are :
The document you need to use as a reference is :
Cookbook has nice examples in this document.
An easy-to-read flowing blog page is :
Do not forget to have fun experimenting with them ;).
你有什么理由想使用 python 吗?如前所述,它可能只会移交给已经为此目的开发的工具。但是,如果您环顾四周,您可以找到诸如
Click! 之类的内容。模块化路由器
、XORP
以及其他提供您想做的事情的插件 - 更不用说已经提供的所有建议(例如iptables
和tc
)Is there any reason you wish to use python? As mentioned, it will likely only hand-off to already developed tools for this purpose. However, if you look around, you can find things such as
Click! modular router
,XORP
, and others that provide a drop-in for things you want to do - not to mention all the suggestions already provided (such asiptables
andtc
)