1

I would like to do a simple rate limiting so all the http traffic (in & out) going to or from my http server is shaped.

I have a GigE connexion on the server and I want to rate limit all HTTP traffic to 50mbps for instance (this service will be used for local speedtests).

I'v already tried several setups with tc but nothing worked, any idea how I could easily do that?

I never want the total traffic (aggregated HTTP) to go above 50mbps, overwise drop and if I perform a test on another server from the same vlan (at GigE), I would exepect it to get 50mbps.

Thanks and regards,

2 Answers2

3

Simple script to limit ingress and egress http traffic:

#!/bin/bash

INT="eth1"

case "$1" in
start|restart)
        tc qdisc del dev $INT handle ffff: ingress 2>/dev/null
        tc qdisc add dev $INT handle ffff: ingress
        tc filter add dev $INT parent ffff: protocol ip prio 50 u32 match ip dport 80 0xffff police rate 50Mbit burst 10m drop flowid :1
        tc qdisc del dev $INT root handle 1: htb 2>/dev/null
        tc qdisc add dev $INT root handle 1: htb
        tc class add dev $INT parent 1: classid 1:1 htb rate 1000Mbit
        tc class add dev $INT parent 1:1 classid 1:5 htb rate 50Mbit prio 1
        tc filter add dev $INT parent 1:0 prio 1 protocol ip u32 match ip dport 80 0xffff flowid 1:5
        ;;
stop)
        tc qdisc del dev $INT handle ffff: ingress 2>/dev/null
        tc qdisc del dev $INT root handle 1: htb 2>/dev/null
        ;;
*)
        echo "Use: $0 start|stop"
esac

script in work: http://linux.dyndns-work.com/video/linux_tc_simple_shape_ingress_and_egress_traffic.ogv/

hiemye
  • 779
  • 1
  • 7
  • 9
  • Hey thanks, I don't know if something is wrong here but even with those commands, I can download at 110mbps from another server. –  Dec 08 '10 at 08:37
  • you probably want to change `dport` to `sport` in the egress rule (line 14) – Carl Hörberg Jun 19 '14 at 07:34
0

you may use htb-tools http://htb-tools.skydevel.ro/, its using tc also, but its easier to use.

chocripple
  • 2,039
  • 14
  • 9