Line 1... |
Line 1... |
1 |
#!/bin/sh
|
1 |
#!/bin/sh
|
2 |
# $Id: alcasar-iptables.sh 493 2011-02-14 06:46:55Z franck $
|
2 |
# $Id: alcasar-iptables.sh 498 2011-02-24 20:56:27Z richard $
|
3 |
# script de mise en place des regles du parefeu d'Alcasar (mode normal)
|
3 |
# script de mise en place des regles du parefeu d'Alcasar (mode normal)
|
4 |
# Rexy - 3abtux - CPN
|
4 |
# Rexy - 3abtux - CPN
|
5 |
# there are three channels for log : 1 (default) for tracability, 2 for secure admin (ssh), 3 for exterior access attempts,
|
5 |
# there are three channels for log :
|
- |
|
6 |
# 1 (default) for tracability;
|
- |
|
7 |
# 2 for secure admin (ssh);
|
- |
|
8 |
# 3 for exterior access attempts.
|
6 |
|
9 |
|
7 |
IPTABLES="/sbin/iptables"
|
10 |
IPTABLES="/sbin/iptables"
|
8 |
FILTERING="no"
|
11 |
FILTERING="no"
|
9 |
QOS="no"
|
12 |
QOS="no"
|
10 |
EXTIF="eth0"
|
13 |
EXTIF="eth0"
|
11 |
INTIF="eth1"
|
14 |
INTIF="eth1"
|
12 |
TUNIF="tun0"
|
15 |
TUNIF="tun0"
|
13 |
PRIVATE_NETWORK_MASK="192.168.182.0/24"
|
16 |
PRIVATE_NETWORK_MASK="192.168.182.0/24"
|
14 |
PRIVATE_IP="192.168.182.1"
|
17 |
PRIVATE_IP="192.168.182.1"
|
- |
|
18 |
DNSSERVERS="208.67.220.220,208.67.222.222"
|
15 |
|
19 |
|
- |
|
20 |
# Effacement des règles existantes
|
16 |
# Flush all existing rules
|
21 |
# Flush all existing rules
|
17 |
$IPTABLES -F
|
22 |
$IPTABLES -F
|
18 |
$IPTABLES -t nat -F
|
23 |
$IPTABLES -t nat -F
|
19 |
$IPTABLES -t mangle -F
|
24 |
$IPTABLES -t mangle -F
|
20 |
$IPTABLES -F INPUT
|
25 |
$IPTABLES -F INPUT
|
21 |
$IPTABLES -F FORWARD
|
26 |
$IPTABLES -F FORWARD
|
22 |
$IPTABLES -F OUTPUT
|
27 |
$IPTABLES -F OUTPUT
|
23 |
$IPTABLES -N SYN-FLOOD
|
- |
|
24 |
|
28 |
|
- |
|
29 |
# Suppression des chaines utilisateurs sur les tables filter et nat
|
- |
|
30 |
# Flush non default rules on filter and nat tables
|
- |
|
31 |
$IPTABLES -X
|
- |
|
32 |
$IPTABLES -t nat -X
|
- |
|
33 |
|
- |
|
34 |
# Stratégies par défaut
|
25 |
# Default policies
|
35 |
# Default policies
|
26 |
$IPTABLES -P INPUT DROP
|
36 |
$IPTABLES -P INPUT DROP
|
27 |
$IPTABLES -P FORWARD DROP
|
37 |
$IPTABLES -P FORWARD DROP
|
28 |
$IPTABLES -P OUTPUT ACCEPT
|
38 |
$IPTABLES -P OUTPUT DROP
|
29 |
$IPTABLES -t nat -P PREROUTING ACCEPT
|
39 |
$IPTABLES -t nat -P PREROUTING ACCEPT
|
30 |
$IPTABLES -t nat -P POSTROUTING ACCEPT
|
40 |
$IPTABLES -t nat -P POSTROUTING ACCEPT
|
31 |
$IPTABLES -t nat -P OUTPUT ACCEPT
|
41 |
$IPTABLES -t nat -P OUTPUT ACCEPT
|
32 |
|
42 |
|
33 |
# Flush non default rules on filter and nat tables
|
43 |
# Création des chaînes utilisateur
|
34 |
$IPTABLES -X
|
44 |
# User defined chains
|
35 |
$IPTABLES -t nat -X
|
45 |
$IPTABLES -N SYN-FLOOD
|
36 |
|
46 |
|
- |
|
47 |
# Tout passe sur loopback
|
37 |
# accept all on loopback
|
48 |
# accept all on loopback
|
38 |
$IPTABLES -A INPUT -i lo -j ACCEPT
|
49 |
$IPTABLES -A INPUT -i lo -j ACCEPT
|
39 |
|
50 |
|
- |
|
51 |
# Blocage des tentatives de spoofing de l'adresse de loopback
|
40 |
# Block all attempts to spoof the loopback address
|
52 |
# Block all attempts to spoof the loopback address
|
41 |
$IPTABLES -A INPUT -s 127.0.0.0/8 -j DROP
|
53 |
$IPTABLES -A INPUT -s 127.0.0.0/8 -j DROP
|
42 |
$IPTABLES -A INPUT -d 127.0.0.0/8 -j DROP
|
54 |
$IPTABLES -A INPUT -d 127.0.0.0/8 -j DROP
|
43 |
|
55 |
|
- |
|
56 |
# Blocage des tentatives de spoofing de l'adresse IP côté interne
|
44 |
# Block all attempts to spoof the local IP address
|
57 |
# Block all attempts to spoof the local IP address
|
45 |
$IPTABLES -A INPUT -s $PRIVATE_IP -j DROP
|
58 |
$IPTABLES -A INPUT -s $PRIVATE_IP -j DROP
|
46 |
|
59 |
|
- |
|
60 |
# Blocage des attaques de type SYN FLOOD
|
47 |
# Block Syn Flood attacks
|
61 |
# Block Syn Flood attacks
|
48 |
$IPTABLES -A INPUT -p tcp -m tcp --syn -j SYN-FLOOD
|
62 |
#$IPTABLES -A INPUT -p tcp -m tcp --syn -j SYN-FLOOD
|
49 |
|
- |
|
50 |
# Syn flood filtering chain
|
- |
|
51 |
$IPTABLES -A SYN-FLOOD -m limit --limit 1/s --limit-burst 4 -j RETURN
|
63 |
#$IPTABLES -A SYN-FLOOD -m limit --limit 1/s --limit-burst 4 -j RETURN
|
52 |
$IPTABLES -A SYN-FLOOD -j DROP
|
64 |
#$IPTABLES -A SYN-FLOOD -j DROP
|
53 |
|
65 |
|
- |
|
66 |
# On élimine les paquets "NEW not SYN"
|
54 |
# Ensure that TCP connections start with syn packets
|
67 |
# Ensure that TCP connections start with syn packets
|
55 |
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
|
68 |
$IPTABLES -A INPUT -p tcp -m tcp ! --syn -m state --state NEW -j DROP
|
56 |
|
69 |
|
57 |
#############################
|
70 |
#############################
|
58 |
# INTIF rules #
|
71 |
# INTIF rules #
|
59 |
#############################
|
72 |
#############################
|
- |
|
73 |
# les requètes dhcp entrantes sont acceptées
|
60 |
# accept dhcp
|
74 |
# accept dhcp
|
61 |
$IPTABLES -A INPUT -i $INTIF -p udp -m udp --sport bootpc --dport bootps -j ACCEPT
|
75 |
$IPTABLES -A INPUT -i $INTIF -p udp -m udp --sport bootpc --dport bootps -j ACCEPT
|
- |
|
76 |
|
- |
|
77 |
# La règle suivante interdit la sortie par INTIF. Elle n'est utile que lorsque chilli est arrêté.
|
62 |
# INTIF is closed (all by TUNIF)
|
78 |
# INTIF is closed (all by TUNIF)
|
63 |
$IPTABLES -A INPUT -i $INTIF -j ULOG --ulog-prefix "RULE Protect1 -- REJECT "
|
79 |
$IPTABLES -A INPUT -i $INTIF -j ULOG --ulog-prefix "RULE Protect1 -- REJECT "
|
64 |
$IPTABLES -A INPUT -i $INTIF -j REJECT
|
80 |
$IPTABLES -A INPUT -i $INTIF -j REJECT
|
65 |
|
81 |
|
66 |
#############################
|
82 |
#############################
|
67 |
# Local protection rules #
|
83 |
# Local protection rules #
|
68 |
#############################
|
84 |
#############################
|
- |
|
85 |
# On stoppe les tentatives de NULLSCAN et XMAS (tous flags à 1)
|
69 |
# Drop XMAS & NULLscans
|
86 |
# Drop XMAS & NULLscans
|
70 |
$IPTABLES -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
|
87 |
$IPTABLES -A INPUT -p tcp --tcp-flags FIN,URG,PSH FIN,URG,PSH -j DROP
|
71 |
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
|
88 |
$IPTABLES -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
|
72 |
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
|
89 |
$IPTABLES -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
|
73 |
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
|
90 |
$IPTABLES -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
|
- |
|
91 |
|
- |
|
92 |
# On stoppe les broadcasts et multicast
|
74 |
# Drop broadcast & multicast
|
93 |
# Drop broadcast & multicast
|
75 |
$IPTABLES -A INPUT -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
|
94 |
$IPTABLES -A INPUT -m addrtype --dst-type BROADCAST,MULTICAST -j DROP
|
- |
|
95 |
|
- |
|
96 |
# Règles d'antispoofing
|
76 |
# Antispoofing rules with log
|
97 |
# Antispoofing rules with log
|
77 |
$IPTABLES -A INPUT -i $TUNIF ! -s $PRIVATE_NETWORK_MASK -j ULOG --ulog-prefix "RULE Antispoof1 -- DENY "
|
98 |
$IPTABLES -A INPUT -i $TUNIF ! -s $PRIVATE_NETWORK_MASK -j ULOG --ulog-prefix "RULE Antispoof1 -- DENY "
|
78 |
$IPTABLES -A INPUT -i $TUNIF ! -s $PRIVATE_NETWORK_MASK -j DROP
|
99 |
$IPTABLES -A INPUT -i $TUNIF ! -s $PRIVATE_NETWORK_MASK -j DROP
|
79 |
$IPTABLES -A INPUT -i $EXTIF -s $PRIVATE_NETWORK_MASK -j ULOG --ulog-prefix "RULE Antispoof2 -- DENY "
|
100 |
$IPTABLES -A INPUT -i $EXTIF -s $PRIVATE_NETWORK_MASK -j ULOG --ulog-prefix "RULE Antispoof2 -- DENY "
|
80 |
$IPTABLES -A INPUT -i $EXTIF -s $PRIVATE_NETWORK_MASK -j DROP
|
101 |
$IPTABLES -A INPUT -i $EXTIF -s $PRIVATE_NETWORK_MASK -j DROP
|
- |
|
102 |
|
- |
|
103 |
# On laisse passer les ICMP echo-request et echo-reply en provenance du LAN
|
81 |
# Allow ping (icmp N°0 & 8) from LAN
|
104 |
# Allow ping (icmp N°0 & 8) from LAN
|
82 |
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp --icmp-type 0 -j ACCEPT
|
105 |
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp --icmp-type 0 -j ACCEPT
|
83 |
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp --icmp-type 8 -j ACCEPT
|
106 |
$IPTABLES -A INPUT -i $TUNIF -s $PRIVATE_NETWORK_MASK -p icmp --icmp-type 8 -j ACCEPT
|
84 |
|
107 |
|
- |
|
108 |
# Insertion de règles locales
|
85 |
# Here, we add local rules (i.e. ssh from Internet)
|
109 |
# Here, we add local rules (i.e. ssh from Internet)
|
86 |
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
|
110 |
if [ -f /usr/local/etc/alcasar-iptables-local.sh ]; then
|
87 |
. /usr/local/etc/alcasar-iptables-local.sh
|
111 |
. /usr/local/etc/alcasar-iptables-local.sh
|
88 |
fi
|
112 |
fi
|
89 |
|
113 |
|
- |
|
114 |
# Rejet des tentatives de création de tunnels DNS (même pour les utilisateurs authentifiés)
|
90 |
# Deny forward DNS (even for authenticated users ...)
|
115 |
# Deny forward DNS (even for authenticated users ...)
|
91 |
$IPTABLES -A FORWARD -i $TUNIF -p udp --dport domain -j REJECT --reject-with icmp-port-unreachable
|
116 |
$IPTABLES -A FORWARD -i $TUNIF -p udp --dport domain -j REJECT --reject-with icmp-port-unreachable
|
92 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport domain -j REJECT --reject-with tcp-reset
|
117 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport domain -j REJECT --reject-with tcp-reset
|
93 |
|
118 |
|
- |
|
119 |
# On autorise les retours de connexions légitimes par FORWARD
|
94 |
# Conntrack on forward
|
120 |
# Conntrack on forward
|
95 |
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
|
121 |
$IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
|
96 |
|
122 |
|
97 |
#####################################
|
123 |
#####################################
|
98 |
# If protocols filter is activate #
|
124 |
# If protocols filter is activate #
|
99 |
#####################################
|
125 |
#####################################
|
100 |
if [ $FILTERING = "yes" ]; then
|
126 |
if [ $FILTERING = "yes" ]; then
|
- |
|
127 |
# Mise en place des exceptions (adresses IP des machines ne faisant pas l'objet de filtrage)
|
101 |
# Compute exception IP
|
128 |
# Compute exception IP
|
102 |
nb_exceptions=`wc -w /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
|
129 |
nb_exceptions=`wc -w /usr/local/etc/alcasar-filter-exceptions | cut -d" " -f1`
|
103 |
if [ $nb_exceptions != "0" ]
|
130 |
if [ $nb_exceptions != "0" ]
|
104 |
then
|
131 |
then
|
105 |
while read ip_exception
|
132 |
while read ip_exception
|
106 |
do
|
133 |
do
|
107 |
echo $ip_exception
|
- |
|
108 |
$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ULOG --ulog-prefix "RULE IP-exception -- ACCEPT "
|
134 |
$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ULOG --ulog-prefix "RULE IP-exception -- ACCEPT "
|
109 |
$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ACCEPT
|
135 |
$IPTABLES -A FORWARD -i $TUNIF -s $ip_exception -m state --state NEW -j ACCEPT
|
- |
|
136 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -s $ip_exception -d $PRIVATE_IP --dport domain -j REDIRECT --to-port 54
|
110 |
done < /usr/local/etc/alcasar-filter-exceptions
|
137 |
done < /usr/local/etc/alcasar-filter-exceptions
|
111 |
fi
|
138 |
fi
|
- |
|
139 |
# Autorisation de protocoles non commentés
|
112 |
# Allow non comment protocols
|
140 |
# Allow non comment protocols
|
113 |
while read svc_line
|
141 |
while read svc_line
|
114 |
do
|
142 |
do
|
115 |
svc_on=`echo $svc_line|cut -b1`
|
143 |
svc_on=`echo $svc_line|cut -b1`
|
116 |
if [ $svc_on != "#" ]
|
144 |
if [ $svc_on != "#" ]
|
Line 124... |
Line 152... |
124 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport $svc_port -m state --state NEW -j ULOG --ulog-prefix "RULE F_$svc_name -- ACCEPT "
|
152 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport $svc_port -m state --state NEW -j ULOG --ulog-prefix "RULE F_$svc_name -- ACCEPT "
|
125 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport $svc_port -m state --state NEW -j ACCEPT
|
153 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp --dport $svc_port -m state --state NEW -j ACCEPT
|
126 |
fi
|
154 |
fi
|
127 |
fi
|
155 |
fi
|
128 |
done < /usr/local/etc/alcasar-services
|
156 |
done < /usr/local/etc/alcasar-services
|
- |
|
157 |
# Rejet explicite (vers le LAN) des autres protocoles
|
129 |
# reject the others
|
158 |
# reject the others
|
130 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp -j ULOG --ulog-prefix "RULE F_filter -- REJECT "
|
159 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp -j ULOG --ulog-prefix "RULE F_filter -- REJECT "
|
131 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
|
160 |
$IPTABLES -A FORWARD -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
|
132 |
$IPTABLES -A FORWARD -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
|
161 |
$IPTABLES -A FORWARD -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
|
133 |
$IPTABLES -A FORWARD -i $TUNIF -p icmp -j REJECT
|
162 |
$IPTABLES -A FORWARD -i $TUNIF -p icmp -j REJECT
|
Line 138... |
Line 167... |
138 |
########################
|
167 |
########################
|
139 |
if [ $QOS = "yes" ] && [ -e /usr/local/etc/alcasar-iptables-qos.sh ]; then
|
168 |
if [ $QOS = "yes" ] && [ -e /usr/local/etc/alcasar-iptables-qos.sh ]; then
|
140 |
. /usr/local/etc/alcasar-iptables-qos.sh
|
169 |
. /usr/local/etc/alcasar-iptables-qos.sh
|
141 |
fi
|
170 |
fi
|
142 |
|
171 |
|
- |
|
172 |
# Autorisation des connections sortant du LAN
|
143 |
# Allow forward connections with log
|
173 |
# Allow forward connections with log
|
144 |
$IPTABLES -A FORWARD -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE F_all -- ACCEPT "
|
174 |
$IPTABLES -A FORWARD -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE F_all -- ACCEPT "
|
145 |
$IPTABLES -A FORWARD -i $TUNIF -m state --state NEW -j ACCEPT
|
175 |
$IPTABLES -A FORWARD -i $TUNIF -m state --state NEW -j ACCEPT
|
146 |
|
176 |
|
147 |
####################################################################################
|
177 |
###########################################################################################
|
148 |
# Imput from local network (dns, ntp, https, http, ssh and 3990 (user disconnect) #
|
178 |
# Direct input from local network (dns, ntp, https, http, ssh and 3990 (user disconnect) #
|
149 |
####################################################################################
|
179 |
###########################################################################################
|
150 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p udp --dport domain -j ACCEPT
|
180 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p udp --dport domain -j ACCEPT # dnsmasq pour tous
|
151 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p udp --dport ntp -j ACCEPT
|
181 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p udp --dport ntp -j ACCEPT
|
152 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport https -j ACCEPT
|
182 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport https -j ACCEPT
|
153 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport http -j ACCEPT
|
183 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport http -j ACCEPT
|
154 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport ssh -m state --state NEW -j ULOG --ulog-nlgroup 2 --ulog-prefix "RULE ssh-from-LAN -- ACCEPT"
|
184 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport ssh -m state --state NEW -j ULOG --ulog-nlgroup 2 --ulog-prefix "RULE ssh-from-LAN -- ACCEPT"
|
155 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
|
185 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport ssh -j ACCEPT
|
156 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport 3990 -j ACCEPT
|
186 |
$IPTABLES -A INPUT -i $TUNIF -d $PRIVATE_IP -p tcp --dport 3990 -j ACCEPT
|
157 |
|
187 |
|
- |
|
188 |
# On autorise les retours de connexions légitimes par INPUT
|
158 |
# Conntrack on INPUT
|
189 |
# Conntrack on INPUT
|
159 |
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
|
190 |
$IPTABLES -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
|
160 |
|
191 |
|
- |
|
192 |
# On interdit les connexions directes au port utilisé par DansGuardian (8080) et par dnsmasq-forward (54)
|
- |
|
193 |
# Les packets concernés ont fait l'objet d'un marquage dans la table mangle
|
- |
|
194 |
# lors d'une règle de PREROUTING (voir plus bas)
|
161 |
# Deny direct connections on DansGuardian port (8080)
|
195 |
# Deny direct connections on DansGuardian port (8080) and on dnsmasq-forward port (54)
|
162 |
# The concerned paquets are marked by a pre-routing rule (see further)
|
196 |
# The concerned paquets are marked by a pre-routing rule (see further)
|
163 |
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j DROP
|
197 |
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m mark --mark 1 -j DROP
|
- |
|
198 |
$IPTABLES -A INPUT -i $TUNIF -p udp --dport 54 -m mark --mark 1 -j DROP
|
- |
|
199 |
# Autorisation des connexions à DansGuardian et dnsmasq-forward
|
164 |
# Allow connections for DansGuardian
|
200 |
# Allow connections for DansGuardian and forward-mode dnsmasq
|
165 |
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
|
201 |
$IPTABLES -A INPUT -i $TUNIF -p tcp --dport 8080 -m state --state NEW --syn -j ACCEPT
|
- |
|
202 |
$IPTABLES -A INPUT -i $TUNIF -p udp --dport 54 -j ACCEPT
|
166 |
|
203 |
|
- |
|
204 |
# Journalisation des requètes HTTP (seulement des paquets SYN)
|
167 |
# Log HTTP requests (only syn)
|
205 |
# Log HTTP requests (only syn)
|
168 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp ! -d $PRIVATE_IP --dport http -m state --state NEW -j ULOG --ulog-prefix "RULE F_http -- ACCEPT "
|
206 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp ! -d $PRIVATE_IP --dport http -m state --state NEW -j ULOG --ulog-prefix "RULE F_http -- ACCEPT "
|
- |
|
207 |
# On redirige les requêtes HTTP vers DansGuardian (transparent pour les utilisateurs)
|
169 |
# Redirect HTTP request in DansGuardian (transparent proxy)
|
208 |
# Redirect HTTP request in DansGuardian (transparent proxy)
|
170 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp ! -d $PRIVATE_IP --dport http -j REDIRECT --to-port 8080
|
209 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp ! -d $PRIVATE_IP --dport http -j REDIRECT --to-port 8080
|
- |
|
210 |
# Journalisation et marquage des paquets qui tentent d'accéder directement à DansGuardian et à dnsmasq-forward
|
- |
|
211 |
# pour pouvoir les supprimer en INPUT (voir plus haut)
|
171 |
# Mark the dansguardian bypass attempts
|
212 |
# Mark the dansguardian or dnsmasq bypass attempts
|
172 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j ULOG --ulog-prefix "RULE direct-proxy -- DENY "
|
213 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j ULOG --ulog-prefix "RULE direct-proxy -- DENY "
|
- |
|
214 |
$IPTABLES -A PREROUTING -t nat -i $TUNIF -p udp -d $PRIVATE_IP -m udp --dport 54 -j ULOG --ulog-prefix "RULE direct-dns -- DENY "
|
173 |
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j MARK --set-mark 1
|
215 |
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -p tcp -d $PRIVATE_IP -m tcp --dport 8080 -j MARK --set-mark 1
|
- |
|
216 |
$IPTABLES -A PREROUTING -t mangle -i $TUNIF -p udp -d $PRIVATE_IP -m udp --dport 54 -j MARK --set-mark 1
|
174 |
|
217 |
|
- |
|
218 |
# Journalisation et rejet des connexions (autres que celles autorisées) effectuées depuis le LAN
|
175 |
# Deny and log on INPUT from the LAN
|
219 |
# Deny and log on INPUT from the LAN
|
176 |
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE rej-int -- REJECT "
|
220 |
$IPTABLES -A INPUT -i $TUNIF -m state --state NEW -j ULOG --ulog-prefix "RULE rej-int -- REJECT "
|
177 |
$IPTABLES -A INPUT -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
|
221 |
$IPTABLES -A INPUT -i $TUNIF -p tcp -j REJECT --reject-with tcp-reset
|
178 |
$IPTABLES -A INPUT -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
|
222 |
$IPTABLES -A INPUT -i $TUNIF -p udp -j REJECT --reject-with icmp-port-unreachable
|
179 |
|
223 |
|
- |
|
224 |
# Journalisation et rejet des connexions initiées depuis le réseau extérieur (test des effets du paramètre --limit en cours)
|
180 |
# On EXTIF, the access attempts are log in channel 2 (we should test --limit option to avoid deny of service)
|
225 |
# On EXTIF, the access attempts are log in channel 2 (we should test --limit option to avoid deny of service)
|
181 |
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW -j ULOG --ulog-nlgroup 3 --ulog-qthreshold 10 --ulog-prefix "RULE rej-ext -- DROP"
|
226 |
$IPTABLES -A INPUT -i $EXTIF -m state --state NEW -j ULOG --ulog-nlgroup 3 --ulog-qthreshold 10 --ulog-prefix "RULE rej-ext -- DROP"
|
182 |
# Drop on EXTIF
|
- |
|
183 |
$IPTABLES -A INPUT -i $EXTIF -j DROP
|
- |
|
184 |
|
227 |
|
- |
|
228 |
#############################
|
- |
|
229 |
# filtering outside OUTPUT. #
|
- |
|
230 |
#############################
|
- |
|
231 |
|
- |
|
232 |
# On laisse tout sortir sur toutes les cartes sauf celle qui est connectée sur l'extérieur
|
- |
|
233 |
# Everything is allowed but traffic through outside network interface
|
- |
|
234 |
$IPTABLES -A OUTPUT ! -o $EXTIF -j ACCEPT
|
- |
|
235 |
|
- |
|
236 |
# On autorise le parefeu à requêter les DNS externes
|
- |
|
237 |
# Allow DNS requests to identified DNS servers
|
- |
|
238 |
$IPTABLES -A OUTPUT -o $EXTIF -d $DNSSERVERS -p udp --dport domain -m state --state NEW -j ACCEPT
|
- |
|
239 |
|
- |
|
240 |
# On autorise les requêtes http sortantes
|
- |
|
241 |
# HTTP requests are allowed
|
- |
|
242 |
$IPTABLES -A OUTPUT -o $EXTIF -p tcp --dport http -j ACCEPT
|
- |
|
243 |
|
- |
|
244 |
# On autorise les requêtes ntp
|
- |
|
245 |
# NTP requests are allowed
|
- |
|
246 |
$IPTABLES -A OUTPUT -o $EXTIF -p udp --dport ntp -j ACCEPT
|
- |
|
247 |
|
- |
|
248 |
# Traduction dynamique d'adresse en sortie
|
185 |
# Dynamic NAT on EXTIF
|
249 |
# Dynamic NAT on EXTIF
|
186 |
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
|
250 |
$IPTABLES -A POSTROUTING -t nat -o $EXTIF -j MASQUERADE
|
187 |
|
251 |
|
188 |
# Save all rules
|
252 |
# Save all rules
|
189 |
/etc/init.d/iptables save
|
253 |
/etc/init.d/iptables save
|