652 |
richard |
1 |
#!/bin/sh
|
826 |
franck |
2 |
# $Id: alcasar-iptables-qos.sh 827 2012-02-14 23:32:20Z franck $
|
827 |
franck |
3 |
|
652 |
richard |
4 |
# script de mise en place des regles du parefeu d'Alcasar (mode QOS)
|
|
|
5 |
# 3abtux - Rexy
|
|
|
6 |
# Non adapté à ALCASAR car valable pour serveurs disposés dans le réseau LAN internet qui n'est pas notre besoin.
|
|
|
7 |
|
|
|
8 |
# Un peu de config
|
|
|
9 |
TC="/sbin/tc"
|
|
|
10 |
IPTABLES="/sbin/iptables"
|
|
|
11 |
#IPTABLES=`which iptables`
|
|
|
12 |
EXTIF="eth0"
|
|
|
13 |
INTIF="eth1"
|
|
|
14 |
TUNIF="tun0"
|
|
|
15 |
PRIVATE_NETWORK_MASK="192.168.182.0/24"
|
|
|
16 |
PRIVATE_IP="192.168.182.1"
|
|
|
17 |
|
|
|
18 |
# Vitesse max de la connexion internet en Kbit/s
|
|
|
19 |
MAX_UPLOAD="1000"
|
|
|
20 |
MAX_DOWNLOAD="8000"
|
|
|
21 |
|
|
|
22 |
FTP="50"
|
|
|
23 |
WEB="100"
|
|
|
24 |
SMTP="40"
|
|
|
25 |
POP="60"
|
|
|
26 |
DEFAULT="100"
|
|
|
27 |
SPEED=$MAX_UPLOAD
|
|
|
28 |
SLOW="10"
|
|
|
29 |
|
|
|
30 |
BP_MAX=100
|
|
|
31 |
BP_MIN=10
|
|
|
32 |
BP_WEB=$WEB*$MAX_UPLOAD/100
|
|
|
33 |
BP_FTP=$FTP*$MAX_UPLOAD/100
|
|
|
34 |
BP_POP=$POP*$MAX_UPLOAD/100
|
|
|
35 |
BP_SMTP=$SMTP*$MAX_UPLOAD/100
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
################################################
|
|
|
39 |
# Local protection rules sur SSH prioritaire #
|
|
|
40 |
################################################
|
|
|
41 |
$IPTABLES -A PREROUTING -t mangle -p tcp --sport ssh -j TOS --set-tos Minimize-Delay
|
|
|
42 |
|
|
|
43 |
# Netoyage
|
|
|
44 |
$TC qdisc del dev $EXTIF root >/dev/null 2>&1
|
|
|
45 |
$TC qdisc del dev $EXTIF ingress >/dev/null 2>&1
|
|
|
46 |
$TC qdisc del dev $TUNIF root >/dev/null 2>&1
|
|
|
47 |
$TC qdisc del dev $TUNIF ingress >/dev/null 2>&1
|
|
|
48 |
|
|
|
49 |
# Création de la classe parent:
|
|
|
50 |
$TC qdisc add dev $EXTIF root handle 1: htb default 20
|
|
|
51 |
$TC class add dev $EXTIF parent 1: classid 1:1 htb rate ${MAX_UPLOAD}kbit ceil ${MAX_UPLOAD}kbit burst 6k
|
|
|
52 |
|
|
|
53 |
# Download
|
|
|
54 |
$TC qdisc add dev $TUNIF root handle 2: htb
|
|
|
55 |
$TC class add dev $TUNIF parent 2: classid 2:1 htb rate ${MAX_DOWNLOAD}kbit ceil ${MAX_DOWNLOAD}kbit burst 6k
|
|
|
56 |
|
|
|
57 |
# Classe Download LIMIT
|
|
|
58 |
$TC class add dev $TUNIF parent 2:1 classid 2:10 htb rate ${MAX_DOWNLOAD}kbit ceil ${MAX_DOWNLOAD}kbit burst 6k prio 9
|
|
|
59 |
$TC filter add dev $TUNIF parent 2:0 protocol ip prio 9 handle 100 fw flowid 2:10
|
|
|
60 |
$IPTABLES -t mangle -A FORWARD -d $LAN_1 -j MARK --set-mark 100
|
|
|
61 |
$IPTABLES -t mangle -A FORWARD -d $LAN_2 -j MARK --set-mark 100
|
|
|
62 |
$IPTABLES -t mangle -A FORWARD -d $LAN_3 -j MARK --set-mark 100
|
|
|
63 |
$IPTABLES -t mangle -A FORWARD -d $LAN_4 -j MARK --set-mark 100
|
|
|
64 |
$IPTABLES -t mangle -A FORWARD -d $LAN_5 -j MARK --set-mark 100
|
|
|
65 |
|
|
|
66 |
|
|
|
67 |
# Classe par défaut
|
|
|
68 |
$TC class add dev ${EXTIF} parent 1:1 classid 1:20 htb rate ${DEFAULT}kbit ceil ${MAX_UPLOAD}kbit burst 6k prio 3
|
|
|
69 |
|
|
|
70 |
# Classe rapide
|
|
|
71 |
$TC class add dev ${EXTIF} parent 1:20 classid 1:10 htb rate ${SPEED}kbit ceil ${MAX_UPLOAD}kbit burst 6k prio 1
|
|
|
72 |
$TC filter add dev ${EXTIF} parent 1:0 protocol ip prio 1 handle 10 fw flowid 1:10
|
|
|
73 |
$IPTABLES -t mangle -A OUTPUT -p tcp --dport 6667 -j MARK --set-mark 10
|
|
|
74 |
$IPTABLES -t mangle -A FORWARD -p tcp --dport 6667 -j MARK --set-mark 10
|
|
|
75 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 6667 -j MARK --set-mark 10
|
|
|
76 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 7000 -j MARK --set-mark 10
|
|
|
77 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 6668 -j MARK --set-mark 10
|
|
|
78 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 6669 -j MARK --set-mark 10
|
|
|
79 |
$IPTABLES -t mangle -A FORWARD -p icmp -j MARK --set-mark 10
|
|
|
80 |
$IPTABLES -t mangle -A OUTPUT -p icmp -j MARK --set-mark 10
|
|
|
81 |
$IPTABLES -t mangle -A OUTPUT -p tcp --dport 22 -j MARK --set-mark 10
|
|
|
82 |
$IPTABLES -t mangle -A OUTPUT -p tcp --sport 22 -j MARK --set-mark 10
|
|
|
83 |
$IPTABLES -t mangle -A FORWARD -p tcp --dport 22 -j MARK --set-mark 10
|
|
|
84 |
# cs
|
|
|
85 |
$IPTABLES -t mangle -A FORWARD -p udp --sport 27005 -j MARK --set-mark 10
|
|
|
86 |
|
|
|
87 |
# Classe LENTE
|
|
|
88 |
$TC class add dev $EXTIF parent 1:1 classid 1:30 htb rate ${SLOW}kbit prio 5
|
|
|
89 |
$TC filter add dev $EXTIF parent 1:0 protocol ip prio 5 handle 30 fw flowid 1:30
|
|
|
90 |
#$IPTABLES -t mangle -A FORWARD -p tcp --sport 4662 -j MARK --set-mark 30
|
|
|
91 |
#$IPTABLES -t mangle -A FORWARD -p udp --sport 4665 -j MARK --set-mark 30
|
|
|
92 |
#$IPTABLES -t mangle -A FORWARD -p tcp --dport 4662 -j MARK --set-mark 30
|
|
|
93 |
#$IPTABLES -t mangle -A FORWARD -p udp --dport 4665 -j MARK --set-mark 30
|
|
|
94 |
|
|
|
95 |
# Classe WEB
|
|
|
96 |
$TC class add dev $EXTIF parent 1:20 classid 1:21 htb rate ${WEB}kbit prio 2
|
|
|
97 |
$TC filter add dev $EXTIF parent 1:0 protocol ip prio 2 handle 21 fw flowid 1:21
|
|
|
98 |
$IPTABLES -t mangle -A OUTPUT -p tcp --sport 80 -j MARK --set-mark 21
|
|
|
99 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 80 -j MARK --set-mark 21
|
|
|
100 |
|
|
|
101 |
# Classe FTP
|
|
|
102 |
$TC class add dev $EXTIF parent 1:20 classid 1:22 htb rate ${FTP}kbit prio 4
|
|
|
103 |
$TC filter add dev $EXTIF parent 1:0 protocol ip prio 3 handle 22 fw flowid 1:22
|
|
|
104 |
$IPTABLES -t mangle -A OUTPUT -p tcp --sport 21 -j MARK --set-mark 22
|
|
|
105 |
$IPTABLES -t mangle -A FORWARD -p tcp --dport 21 -j MARK --set-mark 22
|
|
|
106 |
|
|
|
107 |
# Classe SMTP
|
|
|
108 |
$TC class add dev $EXTIF parent 1:20 classid 1:23 htb rate ${SMTP}kbit prio 4
|
|
|
109 |
$TC filter add dev $EXTIF parent 1:0 protocol ip prio 4 handle 23 fw flowid 1:23
|
|
|
110 |
$IPTABLES -t mangle -A OUTPUT -p tcp --sport 25 -j MARK --set-mark 23
|
|
|
111 |
$IPTABLES -t mangle -A OUTPUT -p tcp --dport 25 -j MARK --set-mark 23
|
|
|
112 |
$IPTABLES -t mangle -A FORWARD -p tcp --dport 25 -j MARK --set-mark 23
|
|
|
113 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 25 -j MARK --set-mark 23
|
|
|
114 |
|
|
|
115 |
$TC class add dev $EXTIF parent 1:20 classid 1:210 htb rate ${POP}kbit prio 4
|
|
|
116 |
$TC filter add dev $EXTIF parent 1:0 protocol ip prio 4 handle 210 fw flowid 1:210
|
|
|
117 |
|
|
|
118 |
$IPTABLES -t mangle -A FORWARD -p tcp --sport 110 -j MARK --set-mark 210
|
|
|
119 |
|
|
|
120 |
# End of script
|