#!/bin/bash I=iptables group_trusted="192.168.101.0/24" # Dennis group_ssh="212.120.89.188" group_ftp="212.120.89.188" group_samba="212.120.89.188" $I -P INPUT ACCEPT echo 1 $I -P OUTPUT ACCEPT echo 2 $I -P FORWARD ACCEPT echo 3 $I -F echo 4 $I -X echo 5 if [ "$1" = "stop" ] then echo "Firewall completely flushed! Now running without firewall!" exit 0 fi $I -A INPUT -i lo -j ACCEPT echo 6 $I -A INPUT -m state --state INVALID -j DROP echo 7 $I -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT echo 7 $I -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT echo 7 $I -N trusted echo 8 for line in ${group_trusted} ; do $I -A trusted -s $line -j ACCEPT echo "adding $line to trusted" done echo 9 $I -N ssh for line in ${group_ssh} ; do $I -A ssh -s $line -j ACCEPT echo "adding $line to ssh" done $I -A ssh -j trusted echo 10 $I -N ftp for line in ${group_ftp} ; do $I -A ftp -s $line -j ACCEPT echo "adding $line to ftp" done $I -A ftp -j trusted echo 11 $I -N samba for line in ${group_samba} ; do $I -A samba -s $line -j ACCEPT echo "adding $line to samba" done $I -A samba -j trusted echo 12 ##### Enable the rules for every group #ssh $I -A INPUT -m state --state NEW -p TCP --dport 22 -j ssh echo 13 $I -A INPUT -m state --state NEW -p TCP --dport 21 -j ftp echo 14 #samba $I -A INPUT -m state --state NEW -p UDP --dport 137 -j samba echo 15 $I -A INPUT -m state --state NEW -p UDP --dport 138 -j samba echo 16 $I -A INPUT -m state --state NEW -p TCP --dport 139 -j samba echo 17 $I -A INPUT -m state --state NEW -p TCP --dport 445 -j samba echo 18 $I -A INPUT -p TCP --dport 80 -j ACCEPT echo 19 $I -A INPUT -p TCP --dport 113 -j REJECT echo 20 $I -A INPUT -p TCP --dport 10022 -j ACCEPT echo 21 $I -P INPUT DROP echo 22 $I -P OUTPUT ACCEPT echo 23 $I -P FORWARD DROP echo 24 -------------------------- 1 2 3 4 5 6 iptables: No chain/target/match by that name 7 iptables: No chain/target/match by that name 7 8 adding 192.168.101.0/24 to trusted 9 adding 212.120.89.188 to ssh 10 adding 212.120.89.188 to ftp 11 adding 212.120.89.188 to samba 12 iptables: No chain/target/match by that name 13 iptables: No chain/target/match by that name 14 iptables: No chain/target/match by that name 15 iptables: No chain/target/match by that name 16 iptables: No chain/target/match by that name 17 iptables: No chain/target/match by that name 18 19 20 21 22 23 24