SHARE
TWEET

ics.sh

a guest Oct 19th, 2013 2,115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. #
  3. # ics.sh
  4. # This script sets up internet connection sharing using two network interfaces.
  5. # It uses iptables to set up ics.  The script needs to be run as root.
  6. # There are three mandatory arguments required:
  7. # -i Internet Interface  i.e ethernet
  8. # -e Sharing Interface  i.e wifi in AP mode
  9. # -a Sharing Interfaces ip address
  10. # The script assumes that your broadcast address is in the form of x.y.z.255
  11. # and your network is range is x.y.z.a/24
  12. #
  13. # It is intended as a wrapper for Easy Firewall Generator script output
  14. # http://easyfwgen.morizot.net/gen/index.php
  15. #####
  16.  
  17. # Check if any arguments are given, otherwise send out help message.
  18. if [ -z "$1" ]; then
  19.         printf "Usage: $0 -i [Internet Interface] -e [Sharing Interface] -a [Sharing IP Address]\n"
  20.         printf "i.e:  $0 -i eth0 -e wlan0 -a 10.0.0.1\n"
  21.         exit 1
  22. fi
  23.  
  24. # File arguments to correct parameters using getopts
  25. while getopts  "a:e:i:" opt
  26.         do
  27.                 case $opt in
  28.                 a ) LOCAL_IP=${OPTARG};;
  29.                 e ) LOCAL_IFACE=${OPTARG};;
  30.                 i ) INET_IFACE=${OPTARG};;
  31.                 \?) printf "Usage: $0 -i [Internet Interface] -e [Sharing Interface] -a [Sharing IP Address]\n"
  32.                         exit 1;;
  33.                 * ) printf "Usage: $0 -i [Internet Interface] -e [Sharing Interface] -a [Sharing IP Address]\n"
  34.                         exit 1;;
  35.                 esac
  36.         done
  37.  
  38. #
  39. # Check if root.
  40. #
  41. if [ "$(id -u)" != "0" ]; then
  42.         printf "This script must be run as root\n" 1>&2
  43.         exit 1
  44. fi
  45.  
  46. #
  47. # Check if all arguments are entered.
  48. #
  49. if [ -z "$LOCAL_IP" ] || [ -z "$LOCAL_IFACE" ] || [ -z "$INET_IFACE" ]; then
  50. printf "Missing Argument/s!\nUsage: $0 -i [Internet Interface] -e [Local Interface] -a [Local IP Address]\n"
  51. exit 1
  52. fi
  53.  
  54. LOCAL_BCAST=$(echo $LOCAL_IP | sed 's/\.[0-9]*$/.255/')
  55. LOCAL_NET=$(echo $LOCAL_IP | sed 's/\.[0-9]*$/.1\/24/')
  56.  
  57. printf "Local IP is $LOCAL_IP\n"
  58. printf "Local network Inteface is $LOCAL_IFACE\n"
  59. printf "Internet Interface is $INET_IFACE\n"
  60. printf "Local broadcast IP is $LOCAL_BCAST\n"
  61. printf "Local IP network range is $LOCAL_NET\n"
  62. printf "Starting iptables configuration...\n"
  63.  
  64. exit
  65.  
  66. ######
  67. # Paste your generated IPTables script from easyfwgen.morizot.net here, just remember to comment out
  68. # "Local Interface Information" and # Internet Interface sections so the above
  69. # script can insert your values into the firewall.
  70. ######
RAW Paste Data
Top