rendered paste body# =================================================
# iptables script (originally for ubuntu 6.10)
# date: 2007-02-02 15:05
# =================================================
# prevent SYN floods from consuming memory resources
echo "1" > /proc/sys/net/ipv4/tcp_syncookies
# no ICMP
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
# echo "1" > /proc/sys/net/ipv4/icmp_echo_ingome_broadcasters
# no spoofing
if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]
then
for filtre in /proc/sys/net/ipv4/conf/*/rp_filter
do
echo 1 > $filtre
done
fi
# set the default policy for each chain
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# flush (remove) all rules from default chains
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
# remove all custom chains
iptables -X
# allow traffic for sessions which are already established
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# open the loopback address
iptables -A INPUT -s 127.0.0.0/8 -d 127.0.0.0/8 -i lo -j ACCEPT
# HTTP
iptables -A INPUT -p tcp -m tcp --source-port 80 --syn -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 80 -j ACCEPT
# DNS (HTTPS will not work without it, and probably other things too)
iptables -A OUTPUT -p udp -m udp --destination-port 53 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 53 -j ACCEPT
# HTTPS
iptables -A INPUT -i eth0 -p udp -m udp --source-port 443 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp -m tcp --source-port 443 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m tcp --destination-port 443 -j ACCEPT
iptables -A OUTPUT -o eth0 -p udp -m udp --destination-port 443 -j ACCEPT
# IRC IDENT (but not DCC)
iptables -A OUTPUT -p tcp -m tcp --destination-port 6667 -j ACCEPT
# POP3S
iptables -A OUTPUT -p udp -m udp --destination-port 995 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 995 -j ACCEPT
# IMAP2
iptables -A OUTPUT -p udp -m udp --destination-port 143 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 143 -j ACCEPT
# IMAP3
iptables -A OUTPUT -p udp -m udp --destination-port 220 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 220 -j ACCEPT
# Newsgroups/Usenet
iptables -A OUTPUT -p tcp -m tcp --destination-port 119 -j ACCEPT
# SMTP
iptables -A OUTPUT -p tcp -m tcp --destination-port 25 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 465 -j ACCEPT
# FTP
iptables -A OUTPUT -p tcp -m tcp --destination-port 21 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --destination-port 20 -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --source-port 1024:65535 --destination-port 102:65535 -j ACCEPT # suspicious line, but lets leave it like this for now
# MSN messenger (Microsoft/Hotmail)
iptables -A OUTPUT -p tcp -m tcp --destination-port 1863 -j ACCEPT
# TELNET (useful for configuring the router)
iptables -A OUTPUT -p tcp -m tcp --destination-port 23 -j ACCEPT
# allow outgoing ICMP requests (PING)
iptables -A OUTPUT -s 192.168.1.0/0 -p ICMP -j ACCEPT
# close ports that opened "accidently"
iptables -A INPUT -p tcp -m tcp --source-port 135 -j DROP
iptables -A INPUT -p tcp -m tcp --source-port 161 -j DROP
iptables -A INPUT -p tcp -m tcp --source-port 162 -j DROP
iptables -A INPUT -p tcp -m tcp --source-port 445 -j DROP
iptables -A OUTPUT -p tcp -m tcp --destination-port 135 -j DROP
iptables -A OUTPUT -p tcp -m tcp --destination-port 161 -j DROP
iptables -A OUTPUT -p tcp -m tcp --destination-port 162 -j DROP
iptables -A OUTPUT -p tcp -m tcp --destination-port 445 -j DROP
# === notes ===
# (1) "--dport" means "--destination-port" but it's not used
# (2) "--sport" means "--source-port" but it's not used
# === appendix ===
# IRC IDENT & DCC
# iptables -A INPUT -p tcp -m tcp --source-port 6667 -j ACCEPT
# iptables -A INPUT -p tcp -m tcp --source-port 113 -j ACCEPT
# iptables -A OUTPUT -p tcp -m tcp --destination-port 6667 -j ACCEPT
# iptables -A OUTPUT -p tcp -m tcp --source-port 1024:65535 --destination-port 1024:65535 -m state --state NEW -j ACCEPT