Oh, you could find the name of the package… There are some existing in the debian repos. Who said you need to compile ?
Now here follows my guide to open to the out world
WARNING:: Be carefull when you expose open ports to the internet. Any bad thing can happen. My advice: use only ssh and tunel everything form inside. Anyway.
Read the stuff about debian repos in the MBL wiki
Install inadyn
# apt-get update
# apt-get install inadyn
Assuming you have account on no-ip.com (read inadyn man for other supported providers)
Config file (replace personal data)
-u <your_username> -p <your_password>
-a <your_domain>
--dyndns_system default@no-ip.com
--update_period_sec 14400 # $((4*3600))
--forced_update_period 172800 #$((48*3600))
--syslog
--background
Here I update every 4 hours and force update every 2 days (in case I can avoid having to manually keep alive the account, NOT TESTED YET). Also this will run as a daemon that will log to syslog (@/var/log/messages in my firmware 02.43.03-022)
Write an init script
#! /bin/sh
#v1.1
#CONFIG
CMD=/usr/sbin/inadyn
NAME=inadyn
check_status()
{
PID=`ps uax | grep "$CMD" | grep -v grep | awk '{print $2}'`
[ -n "$PID" ]
}
#CODE
# . /etc/rc.d/init.d/functions # uncomment/modify for your killproc
case "$1" in
start)
check_status && echo "Already running $NAME" && exit 1
echo "Starting $NAME."
nice $CMD >/dev/null&
;;
stop)
check_status || { echo "Not running $NAME"; exit 1; }
echo "Shutting down $NAME."
PID=`ps uax | grep "$CMD" | grep -v grep | awk '{print $2}'`
[ -n "$PID" ] && kill $PID
;;
status)
check_status && echo "$NAME active" || echo "$NAME inactive"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
chmod a+x /etc/rc2.d/S99inadyn
Test
/etc/rc2.d/S99inadyn start
check logs for success or error msgs
Check daemon is running
/etc/rc2.d/S99inadyn status
NOTE: This will start at every boot as well.
Now as for the upnp port thing. You will need the miniupnp client and then some scripty thing.
# apt-get install miniupnpc
Create the script
#! /bin/sh
# v1.3
#CONFIG
IFACE=eth0
INTP=22
EXTP=7560
SLEEP=$((60*5)) # Sleep for 5 minutes
COUNT=6 # refresh every 30 mins
ERRCOUNT=1 # on error refresh every 5 mins
LOGCOUNT=8 # log successful every 8 attempts (4 hours)
#CODE
IP=$(ifconfig $IFACE | awk '/inet addr/{FS=":";print $2}' | sed 's/[^\.0-9]//g')
ACTCOUNT=$COUNT
STATE=1 # 1 ok, 0 error
PREVSTATE=1
c=$ACTCOUNT # immediate first check
echo "Mapping local $INTP to ext $EXTP (@$IP)"
n=$LOGCOUNT
while :; do
if [ $c -ge $ACTCOUNT ]; then
c=0
else
c=$(($c+1))
fi
if [ $c -eq 0 ]; then
OUT=`upnpc -a $IP $INTP $EXTP tcp 2>&1`
echo upnpc -a $IP $INTP $EXTP tcp
echo "$OUT"
echo "$OUT" | egrep "external [0-9\.]+:$EXTP .*is redirected to internal $IP:$INTP"
if [ ! "$?" -eq "0" ]; then
logger -t upnpc -p daemon.info "Error Refreshing $INTP->$EXTP tcp port mapping: $OUT"
STATE=0
else
# increment successs log count
if [ $n -ge $LOGCOUNT ]; then
n=0
logger -t upnpc -p daemon.info "Refreshed $INTP->$EXTP tcp port mapping ($LOGCOUNT times)"
else
n=$(($n+1))
fi
STATE=1
fi
fi
if [ $STATE != $PREVSTATE ]; then
# when state changes, reset counter
if [ $STATE == 0 ]; then
ACTCOUNT=$ERRCOUNT
# immediate check after this
c=$ACTCOUNT
else
ACTCOUNT=$COUNT
# after count check
c=0
fi
fi
PREVSTATE=$STATE
/bin/sleep $SLEEP
done
chmod a+x /opt/bin/upnp-ssh.sh
Configure by changing directives at the beggining of the script. The most important are INTP= (your internal port) EXTP= (your external, open to the public port)
Setup an init script as well
#! /bin/sh
#v1.1
#CONFIG
CMD=/opt/bin/upnp-ssh.sh
NAME=upnp-ssh
check_status()
{
PID=`ps uax | grep "$CMD" | grep -v grep | awk '{print $2}'`
[ -n "$PID" ]
}
#CODE
# . /etc/rc.d/init.d/functions # uncomment/modify for your killproc
case "$1" in
start)
check_status && echo "Already running $NAME" && exit 1
echo "Starting $NAME."
nice $CMD >/dev/null&
;;
stop)
check_status || { echo "Not running $NAME"; exit 1; }
echo "Shutting down $NAME."
PID=`ps uax | grep "$CMD" | grep -v grep | awk '{print $2}'`
[ -n "$PID" ] && kill $PID
;;
status)
check_status && echo "$NAME active" || echo "$NAME inactive"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
Run
chmod a+x /etc/rc2.d/S99upnpc
Test
/etc/rc2.d/S99upnpc start
check logs
check if daemon is running
/etc/rc2.d/S99upnpc status
This will run your the box starts as well.
What is does, is to periodically advertise the selected port mapping to the local UPNP router device detected. It also logs successful and erroneous attempts to syslog.
Have fun.