All pastes #24123 Raw Edit

Anonymous

public text v1 · immutable
#24123 ·published 2005-09-28 16:10 UTC
rendered paste body
#!/bin/sh
# TC shaping 
# ADVANCED_SHAPING
# Version 1.002-htb

echo ======================================================================

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin

iptables -t mangle -F  2>/dev/null      
iptables -t mangle -X  2>/dev/null 
iptables -t mangle -N markov
iptables -t mangle -I PREROUTING -j markov            
iptables -t mangle -N markov2
iptables -t mangle -I POSTROUTING -j markov2

unalias a 
unalias s 
unalias d
echo 'clear; tc -s class sh dev eth0 | grep p'> /usr/bin/a
echo 'clear; tc -s class sh dev eth1 | grep p'> /usr/bin/s
echo 'clear; tc -s class sh dev eth2 | grep p'> /usr/bin/d
chmod +x /usr/bin/a /usr/bin/s /usr/bin/d
alias s0='clear; tc -s class sh dev eth0 | grep p'
alias s1='clear; tc -s class sh dev eth1 | grep p'
alias s2='clear; tc -s class sh dev eth2 | grep p'
alias s3='clear; tc -s class sh dev eth3 | grep p'
alias z='clear; tc -s class sh dev '
 

tc qdisc del dev eth0 root >/dev/null 2>&1
tc qdisc del dev eth1 root >/dev/null 2>&1
tc qdisc del dev eth1.2 root >/dev/null 2>&1
tc qdisc del dev eth1.3 root >/dev/null 2>&1
tc qdisc del dev eth0 root >/dev/null 2>&1
tc qdisc del dev eth1 root >/dev/null 2>&1

# cely interface eth0 - 1024 kbps

tc qdisc add dev eth0 root handle 10: htb default 20
tc class add dev eth0 parent 10: classid 10:2 \
 htb rate 1024Kbit 


tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
  match ip protocol 1 0xff match ip dst 212.24.132.66 match ip src 10.1.2.82 flowid 10:1
tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
   match ip sport 22 0xffff match ip dst 212.24.132.66 match ip src 10.1.2.82 flowid 10:1
tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
   match ip sport 12865 0xffff match ip dst 212.24.132.66 match ip src 10.1.2.82 flowid 10:1
tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
   match ip sport 8764 0xffff match ip dst 212.24.129.30 match ip src 10.1.2.82 flowid 10:1
tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
   match ip sport 123 0xffff match ip dst 212.24.132.2 match ip src 10.1.2.82 flowid 10:1
tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
         match ip dst 0.0.0.0/0 flowid 10:2


# Odchozi podtrida pro eth1 - 1024 kbps
tc class add dev eth0 parent 10:2 classid 10:21 \
htb rate 1024Kbit 

# Do ni dle marku
tc filter add dev eth0 parent 10:2 protocol ip prio 1 \
handle 1 fw classid 10:21

echo eth0 '-->' from eth1 total 1024 kbps, weight 102, 

# nejrychlejsi
tc class add dev eth0 parent 10:21 classid 10:421 htb \
rate 256Kbit ceil 10000Kbit prio 1
tc qdisc add dev eth0 parent 10:421 pfifo

# stredni
tc class add dev eth0 parent 10:21 classid 10:521 htb \
rate 256Kbit ceil 10000Kbit prio 3 
tc qdisc add dev eth0 parent 10:521 sfq perturb 15

# Filtry
tc filter add dev eth0 parent 10: protocol ip prio 1 u32 \
	 match ip dst 0.0.0.0/0 flowid 10:21
# 0x8 u ssh - scp do stredni
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip sport 22 0xffff match ip tos 0x8 0xff  match ip dst 0.0.0.0/0 flowid 10:521
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip dport 22 0xffff match ip tos 0x8 0xff  match ip dst 0.0.0.0/0 flowid 10:521
# ICMP
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip protocol 1 0xff  match ip dst 0.0.0.0/0 flowid 10:421 \
# TOS 0x10 a 0x20 do 1.tridy
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
     match ip tos 0x10 0xff  match ip dst 0.0.0.0/0 flowid 10:421
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
     match ip tos 0x20 0xff  match ip dst 0.0.0.0/0 flowid 10:421
# Vybrane sluzby podle portu do 1.tridy
for i in 21 23 53 33434 
do
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip dport $i 0xffff  match ip dst 0.0.0.0/0 flowid 10:421
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip sport $i 0xffff  match ip dst 0.0.0.0/0 flowid 10:421
done

# TCP ACKy bez payloadu - mensi nez 64 bajtu

tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
     match ip protocol 6 0xff \
     match u8 0x10 0xff at nexthdr+13 \
     match u16 0x0000 0xffc0 at 2 \
     flowid 10:421

# Stredne rychle sluzby
for i in 20 80 443 3128 
do
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip sport $i 0xffff  match ip dst 0.0.0.0/0 flowid 10:521
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip dport $i 0xffff  match ip dst 0.0.0.0/0 flowid 10:521
done

# mail
for i in 25 110 143 465 993 995 
do 
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip sport $i 0xffff  match ip dst 0.0.0.0/0 flowid 10:521
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
   match ip dport $i 0xffff  match ip dst 0.0.0.0/0 flowid 10:521
done

# Zbytek do nejpomalejsi
tc filter add dev eth0 parent 10:21 protocol ip prio 4 u32 \
	 match ip dst 0.0.0.0/0 flowid 10:521
echo eth0 '-->' 1024 kbps total

# cely interface eth1 - 1024 kbps

tc qdisc add dev eth1 root handle 11: htb default 20
tc class add dev eth1 parent 11: classid 11:2 \
 htb rate 1024Kbit 


tc filter add dev eth1 parent 11: protocol ip prio 1 u32 \
         match ip dst 0.0.0.0/0 flowid 11:2
# nejrychlejsi
tc class add dev eth1 parent 11:2 classid 11:42 htb \
rate 256Kbit ceil 10000Kbit prio 1
tc qdisc add dev eth1 parent 11:42 pfifo

# stredni
tc class add dev eth1 parent 11:2 classid 11:52 htb \
rate 256Kbit ceil 10000Kbit prio 3 
tc qdisc add dev eth1 parent 11:52 sfq perturb 15

# Filtry
tc filter add dev eth1 parent 11: protocol ip prio 1 u32 \
	 match ip dst 0.0.0.0/0 flowid 11:2
# 0x8 u ssh - scp do stredni
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip sport 22 0xffff match ip tos 0x8 0xff  match ip dst 0.0.0.0/0 flowid 11:52
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip dport 22 0xffff match ip tos 0x8 0xff  match ip dst 0.0.0.0/0 flowid 11:52
# ICMP
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip protocol 1 0xff  match ip dst 0.0.0.0/0 flowid 11:42 \
# TOS 0x10 a 0x20 do 1.tridy
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
     match ip tos 0x10 0xff  match ip dst 0.0.0.0/0 flowid 11:42
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
     match ip tos 0x20 0xff  match ip dst 0.0.0.0/0 flowid 11:42
# Vybrane sluzby podle portu do 1.tridy
for i in 21 23 53 33434 
do
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip dport $i 0xffff  match ip dst 0.0.0.0/0 flowid 11:42
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip sport $i 0xffff  match ip dst 0.0.0.0/0 flowid 11:42
done

# TCP ACKy bez payloadu - mensi nez 64 bajtu

tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
     match ip protocol 6 0xff \
     match u8 0x10 0xff at nexthdr+13 \
     match u16 0x0000 0xffc0 at 2 \
     flowid 11:42

# Stredne rychle sluzby
for i in 20 80 443 3128 
do
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip sport $i 0xffff  match ip dst 0.0.0.0/0 flowid 11:52
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip dport $i 0xffff  match ip dst 0.0.0.0/0 flowid 11:52
done

# mail
for i in 25 110 143 465 993 995 
do 
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip sport $i 0xffff  match ip dst 0.0.0.0/0 flowid 11:52
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
   match ip dport $i 0xffff  match ip dst 0.0.0.0/0 flowid 11:52
done

# Zbytek do nejpomalejsi
tc filter add dev eth1 parent 11:2 protocol ip prio 4 u32 \
	 match ip dst 0.0.0.0/0 flowid 11:52
iptables -t mangle -A markov -i eth1 -j MARK --set-mark 1
echo eth1 '-->' 1024 kbps total
echo ======================================================================