Skip to content

Instantly share code, notes, and snippets.

@jailbirt
Last active April 4, 2016 15:15
Show Gist options
  • Save jailbirt/82f7e09c138c0061bd509924fd9079c7 to your computer and use it in GitHub Desktop.
Save jailbirt/82f7e09c138c0061bd509924fd9079c7 to your computer and use it in GitHub Desktop.
Share 4g Internet by using your wlan0 or usb0 trough a raspberry
#!/bin/bash
#CommonPart
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
INTERFACES="usb0 wlan0"
configuredFlag="no"
function configureInterfaces
{
for INET in $INTERFACES
do
echo Configuring $INET
INETIP="$(ifconfig $INET | sed -n '/inet addr/{s/.*addr://;s/ .*//;p}')"
echo " iptables -t nat -A POSTROUTING -o $INET -j SNAT --to-source $INETIP "
iptables -t nat -A POSTROUTING -o $INET -j SNAT --to-source $INETIP
if [ ! -z $INETIP ];then
configuredFlag="yes"
echo "Configured $configured"
break
fi
done
if [ $configuredFlag = "no" ];then
echo "configuredFlag $configuredFlag, sleeping"
sleep 30
configureInterfaces
fi
}
configureInterfaces
@jailbirt
Copy link
Author

jailbirt commented Apr 3, 2016

Its intentended to get connected from wlan or usb. then It shares internet by using other routers devices attached. I get stick with an older router by using this :trollface:

@jailbirt
Copy link
Author

jailbirt commented Apr 4, 2016

some recursion that way If Its not reacheable It would retry in 30seconds.
as a plus If I call this script at /etc/rc.local . On every restart It will keep on listening for sharing internet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment