On 22 Feb 2006 17:44:52 -0800, "drg" <(E-Mail Removed)> wrote:
>iptables -A INPUT -s 10.0.0.0/24 -d 10.0.0.0/24 -j ACCEPT
>iptables -A INPUT -s 10.0.1.0/24 -d 10.0.1.1/24 -j ACCEPT
>iptables -A INPUT -s 10.0.2.0/24 -d 10.0.0.2/24 -j ACCEPT
>iptables -A INPUT -s 10.0.3.0/24 -d 10.0.0.3/24 -j ACCEPT
>...
>Is there a quicker way to do this or do I really have to type all those
>rules ?
Write a bash script to create the rules from a configuration file.
An example, /etc/rc.d/rc.firewall (Copyright material GPLv2):
....
# blockendropper
# ```````````````
block_entry_count=0
strip_sort_by_ip_address() # input_file, output_file
{
# comment strip source, sort by ip then remove duplicates
sed -e 's/#.*$//' $1 | sort -t. -n -k1,1 -k2,2 -k3,3 -k4,4 | uniq > $2
}
load_iptables_chain_from_file() # input_file, chain, action
{
local addr="" rest=""
block_entry_count=0
while read addr rest; do
[ -z "$addr" ] && continue # ignore blank lines
report " $addr"
iptables -A $2 -p all --src $addr -j $3
(( block_entry_count++ ))
done < $1
}
install_blockendropper() # input_file, chain, action
{
local data_file="$INCLUDE_FILE_PATH/$1" temp_file=""
report " $2 "
block_entry_count=0
if [ -r $data_file ]; then
temp_file="$(mktemp -t fw.XXXXXX)" || exit 2
iptables -N $2
strip_sort_by_ip_address $data_file $temp_file
load_iptables_chain_from_file $temp_file $2 $3
rm -f $temp_file
else
echo "$2: error, cannot read $data_file"; return
fi
report " loaded $block_entry_count blocks"
}
....
install_blockendropper block_host_list drophost DROP
....
Not what you want at all, but outlines a possible approach?
Script context:
http://bugsplatter.mine.nu/bash/firewall/
Grant.
--
.... The computer scientist, who had listened to all of this said,
"Yes, but where do you think the chaos came from?"