#!/bin/bash # # LEARNING IPTABLES SCRIPT # ## Variables ## EXTERNAL_NET="eth0" DMZ_NET="eth1" INTERNAL_NET="eth2" # INTERNAL="192.168.1.0/24" DMZ="172.16.1.0/24" EXTERNAL="192.168.2.0/24" # ## Acquiring the ip address for the devices ## INT_IP=`ifconfig $INTERNAL_NET | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 1` DMZ_IP=`ifconfig $DMZ_NET | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 1` EXT_IP=`ifconfig $EXTERNAL_NET | grep "inet addr" | cut -d ":" -f 2 | cut -d " " -f 1` ## Flush the chains ## iptables -F iptables -F INPUT iptables -F OUTPUT iptables -F FORWARD # ## Setting policies iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP # ## Enable routing ## echo "1" > /proc/sys/net/ipv4/ip_forward # ## Logging ## LOG_LEVEL="notice" # ## FORWARD traffic between INTERNAL and DMZ iptables -A FORWARD -i $INTERNAL_NET -o $DMZ_NET -j ACCEPT iptables -A FORWARD -i $DMZ_NET -o $INTERNAL_NET -j ACCEPT #