Skip to content

Instantly share code, notes, and snippets.

@iwinux
Created November 16, 2012 17:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwinux/4089326 to your computer and use it in GitHub Desktop.
Save iwinux/4089326 to your computer and use it in GitHub Desktop.
gotunnel on Android

Directory structure:

/data/gotunnel/
- gotunnel
- iptables
- redsocks/
-- config
-- redsocks
- start.sh
- stop.sh

Use Scripter app to run start.sh and stop.sh

base {
log_debug = on;
log_info = on;
log = "file:/data/gotunnel/redsocks/log";
daemon = off;
redirector = iptables;
}
redsocks {
local_ip = 127.0.0.1;
local_port = 8118;
ip = 127.0.0.1;
port = 9999;
type = socks5;
}
#!/system/bin/sh
DIR=/data/gotunnel
PATH=$DIR:$PATH
cd $DIR
[ -e log ] && rm log
busybox nohup ./gotunnel -key iwinuxrocks -server 147.8.196.52:38808 -port 127.0.0.1:9999 > log &
cd $DIR/redsocks
[ -e log ] && rm log
./redsocks -c config -p pid &
echo "adding iptables rules"
iptables -t nat -N GOTUNNEL
iptables -t nat -F GOTUNNEL
# excluding internal ips
iptables -t nat -A GOTUNNEL -d 0.0.0.0/8 -j RETURN
iptables -t nat -A GOTUNNEL -d 10.0.0.0/8 -j RETURN
iptables -t nat -A GOTUNNEL -d 127.0.0.0/8 -j RETURN
iptables -t nat -A GOTUNNEL -d 192.168.0.0/16 -j RETURN
iptables -t nat -A GOTUNNEL -d 172.16.0.0/12 -j RETURN
iptables -t nat -A GOTUNNEL -d 172.20.0.0/12 -j RETURN
# excluding known hosts
iptables -t nat -A GOTUNNEL -d 147.8.196.52/32 -j RETURN
iptables -t nat -A GOTUNNEL -d 106.187.52.122/32 -j RETURN
iptables -t nat -A GOTUNNEL -d 66.175.223.101/32 -j RETURN
iptables -t nat -A GOTUNNEL -d 50.116.15.227/32 -j RETURN
iptables -t nat -A GOTUNNEL -d 50.116.5.82/32 -j RETURN
# redirect anything else to port 8118
# iptables -t nat -A GOTUNNEL -p tcp -j REDIRECT --to-ports 8118
iptables -t nat -A GOTUNNEL -p tcp --dport 80 -j REDIRECT --to-ports 8118
iptables -t nat -A GOTUNNEL -p tcp --dport 443 -j REDIRECT --to-ports 8118
iptables -t nat -A GOTUNNEL -p tcp --dport 5228 -j REDIRECT --to-ports 8118
iptables -t nat -A OUTPUT -p tcp -j GOTUNNEL
echo "done"
#!/system/bin/sh
DIR=/data/gotunnel
cd $DIR
killall -9 gotunnel
cd $DIR/redsocks
[ -e pid ] && kill -TERM `cat pid` && rm pid || killall -9 redsocks
echo "removing iptables rules"
iptables -t nat -D OUTPUT -p tcp -j GOTUNNEL
iptables -t nat -F GOTUNNEL
iptables -t nat -X GOTUNNEL
echo "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment