Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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,

share|improve this question
    
Do you want to shape HTTP traffic ONLY? Are all other types of traffic to pass unshaped? –  Steven Monday Dec 7 '10 at 16:35
    
Yes indeed, that's what I want. –  user57921 Dec 8 '10 at 8:34

2 Answers 2

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/

share|improve this answer
    
Hey thanks, I don't know if something is wrong here but even with those commands, I can download at 110mbps from another server. –  user57921 Dec 8 '10 at 8:37
    
you probably want to change dport to sport in the egress rule (line 14) –  Carl Hörberg Jun 19 at 7:34

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.