diff --git a/bin/firewall-sosdg b/bin/firewall-sosdg index 7d5d4c9..51846be 100755 --- a/bin/firewall-sosdg +++ b/bin/firewall-sosdg @@ -106,12 +106,16 @@ fi if [[ "$EXTIF" == "auto" ]]; then + if [ ! "$EXTIF_FIND" ]; then + EXTIF=$EXTIF_FIND display_c YELLOW "Found default interface at: ${BLUE}${EXTIF}${DEFAULT_COLOR}" fi if [[ "$EXTIP" == "auto" ]]; then - EXTIP=$EXTIP_FIND + if [ ! "$EXTIP_FIND" ]; then + EXTIP=$(expr "`ifconfig ${EXTIF}`" : '.*inet addr:\([^ ]*\).*') + fi display_c YELLOW "Found default interface IP at: ${BLUE}${EXTIP}${DEFAULT_COLOR}" fi diff --git a/bin/get_default_if b/bin/get_default_if new file mode 100755 index 0000000..6910b18 --- /dev/null +++ b/bin/get_default_if @@ -0,0 +1,3 @@ +#!/bin/bash +ip route | awk '/^default/{print $3}' +#netstat -rn | awk '/^0.0.0.0/{print $8}' diff --git a/bin/get_default_ip b/bin/get_default_ip new file mode 100755 index 0000000..24a2989 --- /dev/null +++ b/bin/get_default_ip @@ -0,0 +1,7 @@ +#!/bin/bash +# Thanks to the people at: +# http://www.linuxquestions.org/questions/programming-9/using-grep-and-awk-to-get-ip-address-627626/ + +echo $(expr "`ifconfig $1`" : '.*inet addr:\([^ ]*\).*') + +#ifconfig ${EXTIF}| awk -F ' *|:' '/inet addr/{print $4}' diff --git a/include/functions b/include/functions index 5b48ad4..c78e170 100755 --- a/include/functions +++ b/include/functions @@ -171,4 +171,4 @@ function write_out_rules { } function write_out_rules_v6 { echo "$*" >> "$RULE_CACHE_V6" -} \ No newline at end of file +} diff --git a/include/static b/include/static index 89a1a3f..177117c 100755 --- a/include/static +++ b/include/static @@ -69,5 +69,5 @@ RULE_CACHE_V6=$BASEDIR/cache/ipt6-rules EXTIP="auto" EXTIF="auto" -EXTIF_FIND=`ip route | awk '/^default/{print $3}'` -EXTIP_FIND=$(expr "`ifconfig ${EXTIF}`" : '.*inet addr:\([^ ]*\).*') \ No newline at end of file +EXTIF_FIND="$BASEDIR/bin/get_default_if" +EXTIP_FIND="$BASEDIR/bin/get_default_ip" \ No newline at end of file diff --git a/options.default b/options.default index 876c54e..e1649b5 100755 --- a/options.default +++ b/options.default @@ -57,22 +57,18 @@ EXTIF="auto" # the primary external IP using the information from EXTIF EXTIP="auto" +# Program/script for finding the default external interface +# Only used if EXTIF is set to auto +# +# If you need to write your own script to find the info, change below +#EXTIF_FIND="$BASEDIR/bin/get_default_if" + # Pattern for finding the default external interface IP address # Only used if EXTIP is set to auto # -# Thanks to the people at: -# http://www.linuxquestions.org/questions/programming-9/using-grep-and-awk-to-get-ip-address-627626/ -# -# Uncomment one of these if the default doesn't work -#EXTIP_FIND=$(expr "`ifconfig ${EXTIF}`" : '.*inet addr:\([^ ]*\).*') -#EXTIP_FIND=`ifconfig ${EXTIF}| awk -F ' *|:' '/inet addr/{print $4}'` - -# Pattern for finding the default external interface -# Only used if EXTIF is set to auto -# -# Uncomment one of these if the default doesn't work -#EXTIF_FIND=`ip route | awk '/^default/{print $3}'` -#EXTIF_FIND=`netstat -rn | awk '/^0.0.0.0/{print $8}'` +# If you need to write your own script to find the info, change below +# note that the script passes the interface from $EXTIF as first option +#EXTIP_FIND="$BASEDIR/bin/get_default_ip" # Internal Interface #INTINF=ppp+