Advertisement
trishoar

TC Script

Mar 26th, 2014
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.31 KB | None | 0 0
  1. #!/bin/bash
  2. IP-CIDR1=10.0.0.0/16
  3. IP-CIDR2=10.1.0.0/16
  4. IP-CIDR3=10.2.0.0/16
  5. IP-CIDR4=10.3.0.0/16
  6.  
  7. tc qdisc del dev eth0 root
  8.  
  9. tc qdisc add dev eth0 root handle 1: htb default 20
  10. tc class add dev eth0 parent 1: classid 1:1 htb rate 850mbit ceil 900mbit
  11.  
  12. #SSH
  13. tc class add dev eth0 parent 1: classid 1:10 htb rate 2mbit ceil 5mbit prio 1
  14. tc qdisc add dev eth0 parent 1:10 handle 10: sfq perturb 10
  15.  
  16.  
  17. #Legit users
  18. tc class add dev eth0 parent 1: classid 1:20 htb rate 750mbit ceil 900mbit prio 2
  19. tc qdisc add dev eth0 parent 1:20 handle 20: sfq perturb 10
  20.  
  21. #General Abusers
  22. tc class add dev eth0 parent 1: classid 1:30 htb rate 1mbit ceil 1mbit prio 16
  23. tc qdisc add dev eth0 parent 1:30 handle 30: sfq perturb 10
  24.  
  25. #SSH
  26. tc filter add dev eth0 parent 1:0 protocol ip prio 10 u32 match ip sport 22 0xffff flowid 1:10
  27. tc filter add dev eth0 parent 1:0 protocol ip prio 10 u32 match ip dport 22 0xffff flowid 1:10
  28.  
  29.  
  30. #Rate limit subnets to 1MB/s
  31. tc filter add dev eth0 parent 1:0 protocol ip prio 16 u32 match ip dst $IP-CIDR1 flowid 1:30
  32. tc filter add dev eth0 parent 1:0 protocol ip prio 16 u32 match ip dst $IP-CIDR2 flowid 1:30
  33. tc filter add dev eth0 parent 1:0 protocol ip prio 16 u32 match ip dst $IP-CIDR3 flowid 1:30
  34. tc filter add dev eth0 parent 1:0 protocol ip prio 16 u32 match ip dst $IP-CIDR4 flowid 1:30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement