# Default
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
# Accept all incoming traffic
iptables -A INPUT -i lo -j ACCEPT
# A: append; i: interface; j: jump swtich
# Dynamic packet filtering
# Exclude packet with state=NEW
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# -m: load module
# Accept all outgoing traffic
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow DNS query
iptables -A OUTPUT -o eth0 -p udp -m udp --dport 53 -j ACCEPT
# Allow http traffic
iptables -A OUTPUT -o eth0 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
# Allow https traffic
iptables -A OUTPUT -o eth0 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
# Verify
wget http://www.bbc.co.uk
wget https://www.bbc.co.uk
# Switch off the firewall
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
# Disable ipv6
ip6tables -P INPUT DROP
ip6tables -P FORWARD DROP
ip6tables -P OUTPUT DROP