0

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?

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
ehuang
  • 109
  • 3
  • 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 05 '13 at 00:50
  • However, I need to restrict shaping to only certain IPs. – ehuang Dec 05 '13 at 00:54

1 Answers1

2

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 10.0.0.5 -j MARK --set-mark 5
iptables -t mangle -A shaper-in -d 10.0.0.5 -j MARK --set-mark 5

That should shape 10.0.0.5 to 256kbps.

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

Lawrence
  • 380
  • 2
  • 10