Skip to content

Instantly share code, notes, and snippets.

@StoneMoe
Last active December 6, 2022 09:18
Show Gist options
  • Save StoneMoe/5c1f4a1d433629785a2369a7268d4f7f to your computer and use it in GitHub Desktop.
Save StoneMoe/5c1f4a1d433629785a2369a7268d4f7f to your computer and use it in GitHub Desktop.
setup tun2socks with script
#!/bin/bash
if [ $UID -ne 0 ]; then
echo Please run as root.
exit 1
fi
GW=$(ip route | grep default | awk '{print $3}')
IF=$(ip route | grep default | awk '{print $5}')
TUN=192.18.0.1
echo Detected Network: $GW $IF
echo Setting TUN device
ip tuntap add mode tun dev tun0
ip addr add $TUN/15 dev tun0
ip link set dev tun0 up
echo Setting route
ip route del default
ip route add default via $TUN dev tun0 metric 1
ip route add default via $GW dev $IF metric 10
echo Starting proxy
/opt/tun2socks-linux-amd64 -proxy protocol://method:password@ip:port -device tun0 -interface $IF
echo Clean up...
ip tuntap del mode tun dev tun0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment