# Define variables IPT=/usr/sbin/iptables # change if needed EXT_IF=eth0 # external interface (connected to internet) # Enable TCP SYN Cookie Protection if [ -e /proc/sys/net/ipv4/tcp_syncookies ]; then echo 1 > /proc/sys/net/ipv4/tcp_syncookies fi # Disable ICMP Redirect Acceptance echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects # Do not send Redirect Messages echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects # Enable bad error message protection echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses # Enable broadcast echo protection echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts # Disable source-routed packets echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route # Set default policy to DROP $IPT -P INPUT DROP $IPT -P OUTPUT DROP $IPT -P FORWARD DROP # Flush old rules $IPT -F # Allow loopback traffic $IPT -A INPUT -i lo -j ACCEPT $IPT -A OUTPUT -o lo -j ACCEPT # Allow packets of established connections and those # which are related to established connections $IPT -A INPUT -i $EXT_IF -p all -m state --state ESTABLISHED,RELATED -j ACCEPT # Allow all outgoing packets $IPT -A OUTPUT -o $EXT_IF -j ACCEPT # Allow incoming ssh from internet (uncomment the line below if needed) #$IPT -A INPUT -i $EXT_IF -p tcp --destination-port 22 --syn -m state --state NEW -j ACCEPT