hmm i've made this script for the firewall...
rc.firewall
# usage: rc.firewall start|stop|status
#
# Simple firewall disallowing all incomming connections
# but allowing all traffic on localhost (lo device)
# and allowing all outgoing traffic for $ALLOWED_PORTS
Code:
#!/bin/bash
#
# enter ports with spaces between eg: "21 80 443"
ALLOWED_TCP_PORTS=""
ALLOWED_UDP_PORTS=""
#-----------------------------------------------------------
# Avoid using root's TMPDIR
unset TMPDIR
# Source networking configuration.
# /etc/sysconfig/network
# Start the firewall
test -x /usr/sbin/iptables || {
echo "Iptables not properly installed"
exit 1
}
start() {
KIND="Iptables"
echo -n $"Starting $KIND services: "
SYSCTLW="/sbin/sysctl -q -w"
IPTABLES="/usr/sbin/iptables"
# Disable routing triangulation. Respond to queries out
# the same interface, not another. Helps to maintain state
# Also protects against IP spoofing
$SYSCTLW net.ipv4.conf.all.rp_filter=1
# Enable logging of packets with malformed IP addresses,
# Disable redirects,
# Disable source routed packets,
# Disable acceptance of ICMP redirects,
# Turn on protection from Denial of Service (DOS) attacks,
# Disable responding to ping broadcasts,
# Enable IP routing. Required if your firewall is protecting a network, NAT included
$SYSCTLW net.ipv4.conf.all.log_martians=1
$SYSCTLW net.ipv4.conf.all.send_redirects=0
$SYSCTLW net.ipv4.conf.all.accept_source_route=0
$SYSCTLW net.ipv4.conf.all.accept_redirects=0
$SYSCTLW net.ipv4.tcp_syncookies=1
$SYSCTLW net.ipv4.icmp_echo_ignore_broadcasts=1
# $SYSCTLW net.ipv4.ip_forward=1
# Firewall initialization, remove everything, start with clean tables
$IPTABLES -F # remove all rules
$IPTABLES -X # delete all user-defined chains
$IPTABLES -P OUTPUT ACCEPT # allow all outgoing packets
$IPTABLES -P FORWARD DROP # drop all forward packets
$IPTABLES -P INPUT DROP # drop all incomming packets
# allow everything for loop device
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -j ACCEPT
# allow DNS in all directions
# $IPTABLES -A INPUT -p udp --dport 53 -j ACCEPT
# $IPTABLES -A INPUT -p udp --sport 53 -j ACCEPT
# Allow previously established connections
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# allowed ports
for PORT in $ALLOWED_TCP_PORTS; do
$IPTABLES -A INPUT -p tcp --dport $PORT -j ACCEPT
done
for PORT in $ALLOWED_UDP_PORTS; do
$IPTABLES -A INPUT -p udp --dport $PORT -j ACCEPT
done
# Create a chain for logging all dropped packets
$IPTABLES -N LOG_DROP
# $IPTABLES -A LOG_DROP -j LOG --log-prefix "Attack log: "
$IPTABLES -A LOG_DROP -j DROP
$IPTABLES -A INPUT -j LOG_DROP # drop all incomming
$IPTABLES -A FORWARD -j LOG_DROP # drop all forwarded
echo $KIND services started...
RETVAL=0
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/iptables
return $RETVAL
return 0
}
stop() {
KIND="Iptables"
echo -n $"Shutting down $KIND services: "
IPTABLES="/usr/sbin/iptables"
$IPTABLES -F
$IPTABLES -X
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P INPUT ACCEPT
#test -f /var/lock/subsys/iptables && kill `cat /var/lock/subsys/iptables`
RETVAL=$?
#sleep 4
if [ "$RETVAL" == "0" ]; then
rm -f /var/lock/subsys/iptables
echo $KIND services stopped successfully
else
echo Failed! Could not stop $KIND services...
fi
echo
return 0
}
rhstatus() {
echo "-----------------------------------------------------------------------------------------------------------------"
IPTABLES="/usr/sbin/iptables"
$IPTABLES -L -v
echo "-----------------------------------------------------------------------------------------------------------------"
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
*)
echo "Usage: rc.FireWall {start|stop|status}"
exit 1
esac
exit $?