linuxnetfiltertrafficshaping

How to limit network speed using tc?


I have three machines: client, server and proxy. On client(1.1.1.1) I have simple script, which using wget, on server(2.2.2.1) I have apache. And on proxy machine I want to limit speed by using tc. On proxy machine I have two interfaces eth0(1.1.1.2) connected to client and eth1(2.2.2.2) connected to server.

I tried adding this rules, but they are not working:

tc qdisc add dev eth1 root handle 1: cbq avpkt 1000 bandwidth 10mbit 
tc class add dev eth1 parent 1: classid 1:1 cbq rate 1mbit \
allot 1500 prio 5 bounded isolated 
tc filter add dev eth1 parent 1: protocol ip prio 16 u32 \
match ip dst 1.1.1.1 flowid 1:1

Solution

  • Found the answer. this is my script:

    #!/bin/bash
    set -x
    
    tc qdisc del dev eth0 root
    tc qdisc add dev eth0 root handle 1: cbq avpkt 1000 bandwidth 100mbit
    
    tc class add dev eth0 parent 1: classid 1:1 cbq rate 1mbps \
       allot 1500 prio 5 bounded isolated
    
    tc filter add dev eth0 parent 1: protocol ip prio 16 u32 \
       match ip dst 1.1.1.1 flowid 1:1