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