/etc/init.d/firewall_host
#! /bin/bash
#--------------------------------------------------------------------------------------
clear_all() {
# Zezwalam na caly ruch
iptables -F
iptables -X
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t mangle -F
iptables -t mangle -X
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
}
#--------------------------------------------------------------------------------------
set_input() {
# Konfiguracja ruchu przychodzacego do serwera
#
# Zamykam caly ruch
iptables -P INPUT DROP
iptables -F INPUT
# zezwalam na caly ruch wewnatrz serwera
iptables -A INPUT -i lo -j ACCEPT
# eth0 karta przeznaczona dla zwyklego ruchu
iptables -A INPUT -i eth0 -p icmp -j ACCEPT
iptables -A INPUT -i eth0 -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
# eth1 karta przeznaczona dla sieci wewnetrznej (serwer dns, serwer ssh)
iptables -A INPUT -i eth1 -p icmp -j ACCEPT
iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A INPUT -p udp --dport 53 -j ACCEPT
iptables -A INPUT -p tcp --sport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
}
#--------------------------------------------------------------------------------------
set_output() {
# Konfiguracja ruchu wychodzacego z serwera
#
# Zamykam caly ruch
iptables -P OUTPUT DROP
iptables -F OUTPUT
# zezwalam na caly ruch wewnatrz serwera
iptables -A OUTPUT -o lo -j ACCEPT
# eth0 karta przeznaczona dla zwyklego ruchu
iptables -A OUTPUT -o eth0 -p icmp -j ACCEPT
# eth1 karta przeznaczona dla sieci wewnetrznej
iptables -A OUTPUT -o eth1 -p icmp -j ACCEPT
# Ustawiam czas zycia pakietow wychodzacych z serwera na 128 przeskokow
iptables -t mangle -F OUTPUT
iptables -t mangle -A OUTPUT -j TTL --ttl-set 128
iptables -A OUTPUT -p udp --sport 53 -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
}
#--------------------------------------------------------------------------------------
case "$1" in
start|"")
set_input
set_output
exit 3
;;
stop)
clear_all
exit 3
;;
restart)
clear_all
set_input
set_output
exit 3
;;
*)
echo "Usage: firewall_host [start|stop|restart]" >&2
exit 3
;;
esac
: