#!/bin/bash
#
# ics.sh
# This script sets up internet connection sharing using two network interfaces.
# It uses iptables to set up ics. The script needs to be run as root.
# There are three mandatory arguments required:
# -i Internet Interface i.e ethernet
# -e Sharing Interface i.e wifi in AP mode
# -a Sharing Interfaces ip address
# The script assumes that your broadcast address is in the form of x.y.z.255
# and your network is range is x.y.z.a/24
#
# It is intended as a wrapper for Easy Firewall Generator script output
# http://easyfwgen.morizot.net/gen/index.php
#####
# Check if any arguments are given, otherwise send out help message.
if [ -z "$1" ]; then
printf "Usage: $0 -i [Internet Interface] -e [Sharing Interface] -a [Sharing IP Address]\\n"
printf "i.e: $0 -i eth0 -e wlan0 -a 10.0.0.1\\n"
exit 1
fi
# File arguments to correct parameters using getopts
while getopts "a:e:i:" opt
do
case $opt in
a ) LOCAL_IP=${OPTARG};;
e ) LOCAL_IFACE=${OPTARG};;
i ) INET_IFACE=${OPTARG};;
\\?) printf "Usage: $0 -i [Internet Interface] -e [Sharing Interface] -a [Sharing IP Address]\\n"
exit 1;;
* ) printf "Usage: $0 -i [Internet Interface] -e [Sharing Interface] -a [Sharing IP Address]\\n"
exit 1;;
esac
done
#
# Check if root.
#
if [ "$(id -u)" != "0" ]; then
printf "This script must be run as root\\n" 1>&2
exit 1
fi
#
# Check if all arguments are entered.
#
if [ -z "$LOCAL_IP" ] || [ -z "$LOCAL_IFACE" ] || [ -z "$INET_IFACE" ]; then
printf "Missing Argument/s!\\nUsage: $0 -i [Internet Interface] -e [Local Interface] -a [Local IP Address]\\n"
exit 1
fi
LOCAL_BCAST=$(echo $LOCAL_IP | sed \'s/\\.[0-9]*$/.255/\')
LOCAL_NET=$(echo $LOCAL_IP | sed \'s/\\.[0-9]*$/.1\\/24/\')
printf "Local IP is $LOCAL_IP\\n"
printf "Local network Inteface is $LOCAL_IFACE\\n"
printf "Internet Interface is $INET_IFACE\\n"
printf "Local broadcast IP is $LOCAL_BCAST\\n"
printf "Local IP network range is $LOCAL_NET\\n"
printf "Starting iptables configuration...\\n"
exit
######
# Paste your generated IPTables script from easyfwgen.morizot.net here, just remember to comment out
# "Local Interface Information" and # Internet Interface sections so the above
# script can insert your values into the firewall.
######