Reputation: 831
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.
Upvotes: 5
Views: 4647
Reputation: 636
Bandwidth limiting for specific application (google-chrome in this case):
trickle -d 600 -u 200 google-chrome
units are in kbits
Total bandwidth limiting for an ethernet device :
sudo wondershaper eth0 600 200
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 :
ip
ifconfig
route
iptables
netstat
tc
wondershaper
trickle
iftop
iptraf-ng
wget
curl
nslookup
dig
The document you need to use as a reference is :
https://www.lartc.org/howto/index.html
Cookbook has nice examples in this document.
An easy-to-read flowing blog page is :
https://www.cnblogs.com/zengkefu/p/5635100.html
Do not forget to have fun experimenting with them ;).
Upvotes: 0
Reputation: 45324
You want the iproute2 suite, in which you use the tc command. tc commands look like
tc class add dev eth2 parent 1: classid 1:1 htb rate 100Mbit ceil 100Mbit quantum 1600
Here's an existing Python traffic-shaping application that uses iproute2.
Upvotes: 6
Reputation: 12037
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 as iptables
and tc
)
Upvotes: 0
Reputation: 54079
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 on tc
. 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.
Upvotes: 6