Skip to content

Instantly share code, notes, and snippets.

@hongkongkiwi
Last active April 25, 2018 11:25
Show Gist options
  • Save hongkongkiwi/fe938903b4cf1802687e to your computer and use it in GitHub Desktop.
Save hongkongkiwi/fe938903b4cf1802687e to your computer and use it in GitHub Desktop.
A wrapper script to setup shadowsocks using a ddns host. This sort of requires that your domain is reachable using the non-relayed DNS servers.
#!/bin/bash
USAGE="USAGE: $0 server config.json"
SERVER="$1"
CONFIG="$2"
PID_DIR="/var/run"
SS_LOCAL_PID="$PID_DIR/ss-local.pid"
SS_TUNNEL_PID="$PID_DIR/ss-tunnel.pid"
DNS_FORWARD_REMOTE="8.8.8.8:53"
DNS_FORWARD_LOCAL="15353"
if [ $SERVER == "" ]; then
echo "server cannot be empty"
echo $USAGE
exit 0
fi
if [ $CONFIG == "" ]; then
echo "config cannot be empty"
echo $USAGE
exit 0
fi
IP_ADDRESS=`host -t A "$SERVER" | tail -n1 | grep -v "not found" | cut -f4 -d' '`
local_pid=`cat $SS_LOCAL_PID`
# Check if ss-local is running
echo "== Using ShadowSocks Server: $SERVER (${IP_ADDRESS})"
echo "> Downloading latest routes file..."
# Download chinadns routes file here
echo "> Starting SS-Tunnel for ChinaDNS"
echo "ss-tunnel -c $CONFIG -s $IP_ADDRESS -f $PID_DIR/ss-tunnel.pid -L DNS_FORWARD_REMOTE -l $DNS_FORWARD_LOCAL"
ss-tunnel -c "$CONFIG" -s "$IP_ADDRESS" -L "$DNS_FORWARD_REMOTE" -l "$DNS_FORWARD_LOCAL" -u
echo "> Starting ChinaDNS for local/remote route"
# Start ChinaDNS
echo "> Starting SS-Local for traffic redirection"
#ss-local -c "$CONFIG" -s "$IP_ADDRESS" -f "$PID_DIR/ss-local.pid"
#-f "$PID_DIR/ss-tunnel.pid"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment