#!/bin/bash ##################################### # Variabili utilizzate nello script # ##################################### IPTABLES="/sbin/iptables" IFLO="lo" IFEXT="ppp0" #Scegli quella in uso: eth0, eth1, ppp0, wlan0 case "$1" in start) ###################### # Attiva il firewall # ###################### echo -n "Sto attivando il firewall: " ############################## # Carica i moduli del kernel # ############################## modprobe ip_tables modprobe iptable_nat modprobe ip_conntrack modprobe ip_conntrack_ftp modprobe ip_nat_ftp modprobe ipt_LOG modprobe ipt_MARK modprobe ipt_MASQUERADE modprobe ipt_REDIRECT modprobe ipt_REJECT modprobe ipt_TOS modprobe ipt_limit modprobe ipt_mac modprobe ipt_mark modprobe ipt_multiport modprobe ipt_state modprobe ipt_tos modprobe iptable_mangle ############################################# # Cancella tutte le precedenti impostazioni # ############################################# $IPTABLES -F $IPTABLES -F -t nat $IPTABLES -F -t mangle $IPTABLES -X $IPTABLES -X -t nat $IPTABLES -X -t mangle ################## # Regole di base # ################## $IPTABLES -P INPUT DROP $IPTABLES -P FORWARD DROP $IPTABLES -P OUTPUT ACCEPT ############################### # Abilita il traffico interno # ############################### $IPTABLES -A INPUT -i $IFLO -j ACCEPT $IPTABLES -A OUTPUT -o $IFLO -j ACCEPT ################################################# # Permette l'ingresso dei pacchetti di risposta # ################################################# $IPTABLES -A INPUT -p tcp -i $IFEXT -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT $IPTABLES -A INPUT -p icmp -i $IFEXT -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT $IPTABLES -A INPUT -p udp -i $IFEXT -m state -s 0/0 --state ESTABLISHED,RELATED -j ACCEPT ################################################# # Permette il programma $nome_del_tuo_programma # ################################################# $IPTABLES -A INPUT -p tcp --dport 1863 -j ACCEPT echo "ok" ;; stop) ######################### # Disattiva il Firewall # ######################### echo -n "Sto disattivando il firewall: " $IPTABLES -F $IPTABLES -F -t nat $IPTABLES -F -t mangle $IPTABLES -X $IPTABLES -X -t nat $IPTABLES -X -t mangle $IPTABLES -P INPUT ACCEPT $IPTABLES -P FORWARD ACCEPT $IPTABLES -P OUTPUT ACCEPT echo "ok" ;; status) ############################## # Display stato del Firewall # ############################## echo -n "Al momento sono in uso le seguenti regole: " $IPTABLES -L ;; restart|reload) $0 stop $0 start ;; *) echo "Per usare questo script, devi specificare un attributo: firewall {start|stop|restart|reload|status}" >&2 exit 1 ;; esac exit 0