Re: [LARTC] How to use tc to limit bandwidth of a special IP in LAN

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chuanbo Xu <iproute2@xxxxxxxxxxxxxx> writes:

> I want to limit bandwidth of a special IP in LAN, when it upload or
> download from Internet through Linux server. How to use tc to do?

The HOWTO covers this quite well:
        <http://www.linuxdoc.org/HOWTO/Adv-Routing-HOWTO.html>
but there were two hiccups I encountered:
1. with "tc class" the priority must be no more than 8
2. with "tc filter" the priority must be no more than 99

Here is my setup (shortened), modify to suit:

## ROOT Class
tc qdisc add dev eth2 root handle 12: cbq bandwidth 10Mbit avpkt 1400

tc class add dev eth2 parent 12: classid 12:1 cbq bandwidth 10Mbit \
   rate 10Mbit allot 1514 weight 1Mbit prio 2 maxburst 20 avpkt 1400

## FLOWs
# 192.168.2.12 (unbounded)
tc class add dev eth2 parent 12:1 classid 12:212 cbq bandwidth 10Mbit \
   rate 256Kbit allot 1514 weight 25Kbit prio 5 maxburst 20 avpkt 1400

# 192.168.2.13 (bounded)
tc class add dev eth2 parent 12:1 classid 12:213 cbq bandwidth 10Mbit \
   rate 64Kbit allot 1514 weight 6Kbit prio 5 maxburst 20 avpkt 1400 bounded

# unbounded class for local traffic
tc class add dev eth2 parent 12:1 classid 12:300 cbq bandwidth 10Mbit \
   rate 3Mbit allot 1514 weight 300Kbit prio 3 maxburst 20 avpkt 1400

## QDISCs
tc qdisc add dev eth2 parent 12:212 sfq quantum 1514b perturb 15
tc qdisc add dev eth2 parent 12:213 sfq quantum 1514b perturb 15
tc qdisc add dev eth2 parent 12:300 sfq quantum 1514b perturb 15

## FILTERs
# unbounded class (local)
tc filter add dev eth2 parent 12:0 protocol ip prio 10 u32 \
   match ip src 192.168.2.0/24  flowid 12:300

# bounded classes (Internet)
tc filter add dev eth2 parent 12:0 protocol ip prio 20 u32 \
   match ip dst 192.168.2.12 flowid 12:212
tc filter add dev eth2 parent 12:0 protocol ip prio 20 u32 \
   match ip dst 192.168.2.13 flowid 12:213


I have only limited downloads.  To cover uploads as well you need to 
do the same thing for that direction.

-- 
Manfred
----------------------------------------------------------------
NetfilterLogAnalyzer, NetCalc, whois at: <http://logi.cc/linux/>




[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux