F
F
facha2012-06-12 13:07:11
linux
facha, 2012-06-12 13:07:11

Tc: how to limit the bandwidth to the interface?

Hello everyone
I'm trying to cut down the outgoing speed to the eth0 interface.
It looks like it should work like this:

/sbin/tc qdisc add dev eth0 root handle 1: htb default 30<br/>
/sbin/tc class add dev eth0 parent 1: classid 1:30 htb rate 2mbit

But doesn't work. The interface sends traffic at full speed. Tell me, please, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
U
ur3ckr, 2012-06-12
@ur3ckr

On my router like this:
# enter the guaranteed and maximum interface bandwidth
tc class add dev $WAN parent 1: classid 1:1 htb rate 5mbit ceil 5mbit

M
Maxim, 2012-06-12
@Maxim_ka

On one of the customer's servers, the following tc configuration script is used, if necessary, I can paint the details. Contact.
#!/bin/bash
tc qdisc add dev eth2 root handle 1: htb default 10 #Корневая дисциплина, с указание класса по умолчания не
попавшего ни под один фильтр
tc class add dev eth2 parent 1: classid 1:1 htb rate 4096kbit #Корневой класс отвечающий за общую пропускную
cпособность
tc class add dev eth2 parent 1:1 classid 1:10 htb rate 64kbit ceil 150kbit prio 7 #класс с наименьшим приоритетом
tc qdisc add dev eth2 parent 1:10 handle 10: sfq perturb 10
#Фильтр по IP добавить
tc filter add dev eth2 parent 1:0 prio 1 protocol ip u32 match ip dst 192.168.0.5 classid 1:10
tc filter add dev eth2 parent 1:0 prio 2 protocol ip u32 match ip dst 192.168.0.15 classid 1:10
########################################################################
tc class add dev eth2 parent 1:1 classid 1:2 htb rate 200kbit ceil 400kbit prio 2
tc qdisc add dev eth2 parent 1:2 handle 2: sfq perturb 10
#Фильтр по IP добавить
tc filter add dev eth2 parent 1:0 prio 3 protocol ip u32 match ip dst 192.168.0.10 classid 1:2
tc filter add dev eth2 parent 1:0 prio 4 protocol ip u32 match ip dst 192.168.0.11 classid 1:2
tc filter add dev eth2 parent 1:0 prio 5 protocol ip u32 match ip dst 192.168.0.21 classid 1:2
########################################################################
tc class add dev eth2 parent 1:1 classid 1:3 htb rate 184kbit ceil 450kbit prio 3
tc qdisc add dev eth2 parent 1:3 handle 3: sfq perturb 10
#Фильтр по IP добавить
tc filter add dev eth2 parent 1:0 prio 8 protocol ip u32 match ip dst 192.168.0.41 classid 1:3
tc filter add dev eth2 parent 1:0 prio 6 protocol ip u32 match ip dst 192.168.0.28 classid 1:3
tc filter add dev eth2 parent 1:0 prio 8 protocol ip u32 match ip dst 192.168.0.202 classid 1:3
tc filter add dev eth2 parent 1:0 prio 9 protocol ip u32 match ip dst 10.10.10.10 classid 1:3
########################################################################
tc class add dev eth2 parent 1:1 classid 1:4 htb rate 64kbit ceil 256kbit prio 4
tc qdisc add dev eth2 parent 1:4 handle 4: sfq perturb 10
#Фильтр по IP добавить
tc filter add dev eth2 parent 1:0 prio 10 protocol ip u32 match ip dst 192.168.0.22 classid 1:4
tc filter add dev eth2 parent 1:0 prio 11 protocol ip u32 match ip dst 192.168.0.27 classid 1:4
tc filter add dev eth2 parent 1:0 prio 12 protocol ip u32 match ip dst 192.168.0.203 classid 1:4

S
smartlight, 2012-06-12
@smartlight

#
# speed limit to download\upload data from Internet
# for local IP's in interface eth0
#
#!/bin/sh
# start shaper
shaper_start() {
tc qdisc add dev eth0 root handle 1: htb default 12
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit ceil 100mbit
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 512kbit ceil 512kbit
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 512kbit ceil 512kbit
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 100mbit ceil 100mbit
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip dst 192.168.10.0/24 match ip sport 80 0xffff flowid 1:10
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 match ip src 192.168.10.0/24 match ip dport 80 0xffff flowid 1:10
tc qdisc add dev eth0 parent 1:10 handle 20: pfifo limit 5
tc qdisc add dev eth0 parent 1:11 handle 30: pfifo limit 5
tc qdisc add dev eth0 parent 1:12 handle 40: pfifo limit 10
}
shaper_stop () {
# remove shaper
tc qdisc del dev eth0 root
}
# Restart shaper
shaper_restart (){
shaper_stop
sleep 1
shaper_start
}
# View shaper status
shaper_status (){
# view status shaper
tc -s -d qdisc show dev eth0
}
case "$1" in
'start')
shaper_start
;;
'stop')
shaper_stop
;;
'restart')
shaper_restart
;;
'status')
shaper_status
;;
*)
echo "usage rc.shaper : start|stop|restart|status"
esac

eth0 - Local Area
eth1 - Internet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question