We will explain how to configure a cubieboard running debian as a reverese proxy.
The modules that will be used are wvdial
and autossh
Credits goes to:
-
https://wiki.archlinux.org/index.php/3G_and_GPRS_modems_with_pppd
-
Configure wvdial
Then edit your configuration to match your mobile operator requirements.
$ pico /etc/wvdial.conf
Mine looks like this:
[Dialer Defaults]
New PPPD = yes
Dial Command = ATDT
Dial Attempts = 1
Modem = /dev/ttyUSB0
Modem Type = Analog Modem
ISDN = 0
Baud = 460800
Username = user
Password = pass
Init1 = ATZ
Init2 = AT&F E1 V1 X1 &D2 &C1 S0=0
Init3 = AT+CGDCONT=1,"IP","internet"
Phone = *99#
Stupid Mode = 1
Check Def Route = yes
Auto Reconnect = yes
[Dialer wind]
Username = web
Password = web
Init3 = AT+CGDCONT=1,"IP","gint.b-online.gr"
[Dialer cosmote]
Init3 = AT+CGDCONT=1,"IP","internet"
[Dialer vodafone]
Init3 = AT+CGDCONT=1,"IP","internet"
[Dialer MF636]
Modem = /dev/ttyUSB2
[Dialer E169]
Modem = /dev/ttyUSB0
[Dialer E170]
Modem = /dev/ttyUSB0
[Dialer E220]
Modem = /dev/ttyUSB0
[Dialer 0]
Modem = /dev/ttyUSB0
[Dialer 1]
Modem = /dev/ttyUSB1
[Dialer 2]
Modem = /dev/ttyUSB2
- Start 3G connection at boot time.
It’s easy with debian, add the following lines in your /etc/network/interfaces
file:
$ pico /etc/network/interfaces
TIP: place the below lines above eth0
so as to be the default one
# start 3G connection
# pre-up
# wait for at max 20 seconds before connecting for the 3G stick to become connected at [ttyUSB0, ttyUSB1, ttyUSB2]
# 3G stick might not be available immediately
# wait 30 more seconds for the 3G connection to become active
auto ppp0
iface ppp0 inet wvdial
provider vodafone
pre-up /etc/ppp/wait-dialup-hardware ttyUSB0 20
pre-up /etc/ppp/wait-dialup-hardware ttyUSB1 20
pre-up /etc/ppp/wait-dialup-hardware ttyUSB2 20
pre-up sleep 30
post-up echo "3G (ppp0) is online"
- Add scripts that waits for USB to be connected on boot
During boot the USB Dongle is not always available at the moment the network interfaces comes up. For that reason add this file that is being used from step 2 /etc/network/interfaces
file.
$ pico /etc/ppp/wait-dialup-hardware
The file needs to have the below contents:
#!/bin/bash
#INTERFACE="/dev/$(head -1 /etc/ppp/options-mobile)"
INTERFACE="/dev/$1"
MAX_SECONDS_TIMEOUT=$2
dsec=$((${MAX_SECONDS_TIMEOUT} * 10))
for ((retry=0; retry < ${dsec}; retry++))
do
if [ -c ${INTERFACE} ]; then
echo "$0: OK existing required device ${INTERFACE} (in $((retry / 10)).$((100 * (retry % 10) / 10)) seconds)"
logger "$0: OK existing required device ${INTERFACE} (in $((retry / 10)).$((100 * (retry % 10) / 10)) seconds)"
break
else
sleep 0.1
fi
done
if [ ! -c ${INTERFACE} ]; then
echo "$0: ERROR timeout waiting for required device ${INTERFACE}"
logger "$0: ERROR timeout waiting for required device ${INTERFACE}"
exit 1
fi
- Add route for ppp0 on connection
The 3G USB modem is connected but one problem remains: If the Ethernet interface was already up with a default gateway, then no new default route will be added via the ppp0 interface. To fix this, the following file has to be modified: /etc/ppp/peers/wvdial
.
$ pico /etc/ppp/peers/wvdial
The modified file looks like this:
noauth
name wvdial
usepeerdns
defaultroute
replacedefaultroute
- Setup an Autossh deamon
For setting up a deamon for autossh you can use this script that will create a service that will run on boot. You only have to set the script configuration values and call it.
- Add script that checks if 3G connection is active
$ pico /home/username/check-wan-status
The file needs to have the below contents:
#!/bin/sh
#
# Restart network interfaces
# if ppp0 3G connection is down
PING="/bin/ping -q -c1 -W 10 -I ppp0"
HOST=8.8.8.8
${PING} ${HOST}
if [ $? -ne 0 ]; then
echo "3G (ppp0) network is down"
(ifdown ppp0; sleep 5; ifup ppp0) &
fi
- Add script that check autossh status
$ pico /home/username/autossh-keep-alive
Please change the AUTOSSH_SERVICE_NAME
with the name that you have set at step #5.
The file needs to have the below contents:
#!/bin/bash
TUNNEL="/usr/sbin/service AUTOSSH_SERVICE_NAME"
${TUNNEL} status
if [ $? -ne 0 ]; then
echo "NO AUTOSSH DAEMON ACTIVE"
sleep 120
${TUNNEL} start
fi
- Add these files in crontab
$ crontab -e
Add the following in the crontab file:
*/10 * * * * /home/username/check-wan-status
*/10 * * * * /home/username/autossh-keep-alive