I am aware of how to shape latency and bandwidth separately. For bandwidth, I can do

wondershaper etho0 100 100

for latency I can run

tc qdisc add dev eth0 root netem delay 200ms

However, I need to restrict shaping to specific IP connections and I need to shape latency and bandwidth simultaneously.

How can I do this?

  • tc can do both latency and bandwidth. The lines tc qdisc add dev wlan0 root handle 1:0 htb default 10 and tc class add dev wlan0 parent 1:0 classid 1:10 htb rate 64kbps ceil 64kbps prio 0 would shape everyone to 64kbps – Lawrence Dec 5 '13 at 0:50
  • However, I need to restrict shaping to only certain IPs. – ehuang Dec 5 '13 at 0:54

You can use tc to shape bandwidth like so

This class will shape certain addresses to a certain speed. We also need to setup a filter so that any packets marked as such go through this rule

tc class add dev eth0 parent 1:1 classid 1:5 htb rate 256kbps ceil 256kbps prio 1
tc filter add dev eth0 parent 1:0 prio 1 handle 5 fw flowid 1:5

Once that class is setup, you need to setup iptables to mark the specific packets you want to shape.

Next, create the mangle table that's needed.

iptables -t mangle -N shaper-out
iptables -t mangle -N shaper-in

iptables -t mangle -I PREROUTING -i eth0 -j shaper-in
iptables -t mangle -I POSTROUTING -o eth0 -j shaper-out

Next setup the marks that we need to shape certain IP addresses. mark 5 is the one that is shaped to 256.
iptables -t mangle -A shaper-out -s -j MARK --set-mark 5
iptables -t mangle -A shaper-in -d -j MARK --set-mark 5

That should shape to 256kbps.

Reference (my blog) - http://sirlagz.net/2013/01/27/how-to-turn-the-raspberry-pi-into-a-shaping-wifi-router/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.