[debian] Sample iptables configuration script

#!/bin/sh

IPT="/sbin/iptables"

# Flush old rules, old custom tables
$IPT --flush
$IPT --delete-chain

# Set default policies for all three default chains
$IPT -P INPUT DROP
$IPT -P FORWARD DROP
$IPT -P OUTPUT ACCEPT

# Enable free use of loopback interfaces
$IPT -A INPUT -i lo -j ACCEPT
$IPT -A OUTPUT -o lo -j ACCEPT

# All TCP sessions should begin with SYN
$IPT -A INPUT -p tcp ! --syn -m state --state NEW -s 0.0.0.0/0 -j DROP

# Allow established and related packets
$IPT -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# SSH
$IPT -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT

# HTTP
$IPT -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT

#HTTPS
$IPT -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT

Source iptables script generator: http://www.mista.nu/iptables/

Iptables ipv6 rules

#
# ip6tables
#
IPT6='/sbin/ip6tables'

$IPT6 --flush
$IPT6 --delete-chain

$IPT6 -P INPUT DROP
$IPT6 -P FORWARD DROP
$IPT6 -P OUTPUT ACCEPT

# Enable free use of loopback interfaces
$IPT6 -A INPUT -i lo -j ACCEPT
$IPT6 -A OUTPUT -o lo -j ACCEPT

# All TCP sessions should begin with SYN
$IPT6 -A INPUT -p tcp ! --syn -m state --state NEW -j DROP

# Allow established and related packets
$IPT6 -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

$IPT6 -A INPUT -p icmpv6 -j ACCEPT

# SSH
$IPT6 -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT

# HTTP
$IPT6 -A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT

# HTTPS
$IPT6 -A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT

Automatically loading iptables rules

nano /etc/network/if-up.d/iptables
# copy script in file
chmod +x /etc/network/if-up.d/iptables

Source: http://rackerhacker.com/2009/11/16/automatically-loading-iptables-on-debianubuntu/