Thursday, August 29, 2013

Linux Bandwidth Management

1. Menggunakan HTB

HTB example

tc qdisc del dev eth0 root
tc qdisc add dev eth0 root handle 1: htb default 11

tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 2kbps ceil 2kbps
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 50kbps ceil 50kbps

tc filter replace dev eth0 \
 protocol ip parent 1: prio 1 handle 0x19 fw flowid 1:12

iptables -t mangle -F
iptables -t mangle -A POSTROUTING -d 195.47.235.3 -j MARK --set-mark 0x19
 
 
Untuk menangkap trafik paket yang cache hit dari mesin proxy remote yang mempunyai TOS 0×30 atau DSCP 12, ada dua cara yang bisa dilakukan untuk traffic control di linux (Note: eth0 adalah LAN device):
  1. Buat class untuk menangkap trafik cache hit dan set filter seperti di bawah ini:
    tc filter add dev eth0 parent 1:0 protocol ip prio 1 u32 match ip protocol 0x6 \
        0xff match ip tos 0x30 0xff flowid 1:68
    
  2. Buat iptables mangle dan set mark untuk trafik cache hit seperti di bawah ini:
    iptables -A FORWARD -t mangle -p tcp -m dscp --dscp 12 -j MARK --set-mark 0x212
    
Sekarang bandingkan hasil dari dua perintah di bawah ini:
  1. tc -s -d class show dev eth0
    ...
    class htb 1:68 parent 1:66 leaf 68: prio 0 quantum 60000 rate 100000Kbit ceil 100000Kbit burst 126575b/8 mpu 0b overhead 0b cburst 126575b/8 mpu 0b overhead 0b level 0 
    Sent 679063 bytes 665 pkts (dropped 0, overlimits 0)
     rate 136bit
     lended: 665 borrowed: 0 giants: 0
     tokens: 8265 ctokens: 8265
    
  2. iptables -L FORWARD -t mangle -nv
    Chain FORWARD (policy ACCEPT 255K packets, 127M bytes)
     pkts bytes target   prot opt in   out   source      destination         
      665  670K MARK     tcp  --  *    *     0.0.0.0/0   0.0.0.0/0     DSCP match 0x0c MARK set 0x1
    

 
 

No comments: