-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfirewall
More file actions
executable file
·184 lines (143 loc) · 2.74 KB
/
Copy pathfirewall
File metadata and controls
executable file
·184 lines (143 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
#
# Author: Jorge Toro
# jolth@esdebian.org
#
# Usage:
# /etc/init.d/firewall [start|stop|restart|status]
#
# VARIABLES DE AMBIENTE
vars(){
echo "VARIABLES "
# Cargando fichero de Configuración:
if test -e /etc/ipt/ipteasy.conf ; then
echo Cargando fichero de configuración
. /etc/ipt/ipteasy.conf
sleep 1
else
echo Error: No existe el fichero de Configuración
echo " /etc/ipt/ipteasy.conf"
echo "Se sale sin configurar las reglas del Firewall"
sleep 1
exit 3
fi
echo " -> OK"
}
# LIMPIA LAS REGLAS CREADAS
limpia(){
echo "LIMPIANDO "
# Remove
$IPT -F
$IPT -F -t nat
# Remove user define chains
$IPT -X
}
# POLITICAS
policy(){
echo "POLITICAS "
echo "Default policy $POLI"
# Policy
$IPT -P INPUT ${POLI[0]}
$IPT -P FORWARD ${POLI[1]}
$IPT -P OUTPUT ${POLI[2]}
echo " -> OK"
}
# REENVIO
reenvio(){
echo "REENVIO "
echo "Activando reenvio ip_forward"
echo $IP_FRD > /proc/sys/net/ipv4/ip_forward
echo $TCP_SYCKS > /proc/sys/net/ipv4/tcp_syncookies
ip_f=`cat /proc/sys/net/ipv4/ip_forward`
if test "$ip_f" -eq "1" ; then
echo ip_forward = $ip_f
echo " -> OK"
else
echo -e "Error: No se pudo modificar. \nip_forward=$ip_f"
sleep 2
echo -n "Sale con errores.... revisar /etc/ipt/ipteasy.conf"
echo -e " o File System"
exit 3
fi
}
# CARGA DE MODULOS NECESARIOS
addmod(){
echo "ADD MODULES"
$DEPMOD -a
for m in `echo ${ADDMODULES[@]}`; do
echo $m
$MODPROBE $m
done
echo " -> OK"
}
# REGLAS DEL FIREWALL
reglas(){
if test -e $REGLAS ; then
# . /etc/ipt/reglas
grep . $REGLAS | sed '/^#/d' | while read LINE;
do
echo "Cargando: ${LINE}"
echo $LINE > $TMREGLAS
. $TMREGLAS
done | nl
else
echo Error: No existe el fichero de reglas
echo " /etc/ipt/reglas"
echo "Se sale sin configurar las reglas del Firewall"
sleep 1
exit 3
fi
}
# CONFIG FIREWALL
start(){
vars # carga variables
addmod # agrega modulos
limpia # Limpia las reglas creadas
policy # establece politicas por defecto
reenvio # activa reenvio
echo "FIREWALL "
echo "usage: $IPT"
echo -e "Configurando el Firewall \n"
reglas # carga las reglas iptables
sreglas=$? # return reglas
if test $sreglas -ne 0 ; then
echo
echo Error: Se Encuentran Errores en las Reglas
echo " /etc/ipt/reglas"
echo "Se sale sin configurar todas las reglas"
echo "Mirar errores más arriba .........."
sleep 1
exit 3
fi
echo
echo " -> OK"
}
# MAIN()
case $1 in
start)
echo -e "\t\t\tSTART"
start
;;
stop)
echo -e "\t\t\tSTOP"
limpia # Limpia las reglas creadas
#delmod
echo stop
;;
restart)
echo -e "\t\t\tRESTART"
$0 stop
$0 start
;;
status)
echo -e "\t\t\tSTATUS"
echo status
;;
*)
echo "No es una entrada valida...."
echo "Usage: /etc/init.d/firewall [start|stop|restart|status]"
exit 1
;;
esac
exit 0
# FIN MAIN