Simple firewall example ======================= Public domain ******************************************************************************** #!/bin/bash # Internal interface = eth0 # External interface = eth1 # Localnet range = 192.168.0.0/24 # Flushing iptables -t filter -F iptables -t filter -X iptables -t filter -Z # Drop everything iptables -t filter -P INPUT DROP iptables -t filter -P OUTPUT DROP iptables -t filter -P FORWARD DROP # Accept local connections iptables -t filter -A INPUT -i lo -j ACCEPT iptables -t filter -A OUTPUT -o lo -j ACCEPT # Accept dns connections iptables -t filter -A FORWARD -i eth0 -s 192.168.0.0/24 -p udp --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -t filter -A FORWARD -i eth1 -d 192.168.0.0/24 -p udp --sport 53 -m state --state ESTABLISHED -j ACCEPT # Accept http connections iptables -t filter -A FORWARD -i eth0 -s 192.168.0.0/24 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -t filter -A FORWARD -i eth1 -d 192.168.0.0/24 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT # ICMP transit iptables -t filter -A FORWARD -i eth0 -d 192.9.9.3 -p icmp --icmp-type echo-request -j ACCEPT iptables -t filter -A FORWARD -i eth1 -s 192.9.9.3 -p icmp --icmp-type echo-reply -j ACCEPT ******************************************************************************** _BY: Pejman Moghadam_ _TAG: firewall, iptables, bash-script, bash_ _DATE: 2007-07-11 21:40:51_