Last active
July 21, 2023 06:10
-
-
Save ssrlive/08b0b4535bcf1b284b20449ccd83befc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/bash | |
| # Please set the following parameters according to your environment | |
| BYPASS_IP=123.45.67.89 | |
| PROXY_IP=127.0.0.1 | |
| PROXY_PORT=1080 | |
| PROXY_TYPE=SOCKS5 | |
| # check if user is root | |
| function is_root() { | |
| if [ $(id -u) -eq 0 ]; then | |
| echo true | |
| else | |
| echo false | |
| fi | |
| } | |
| # get current user | |
| function get_user() { | |
| if [ $(is_root) = true ]; then | |
| # echo $SUDO_USER | |
| echo "root" | |
| else | |
| echo $USER | |
| fi | |
| } | |
| function restore() { | |
| sudo ip link del tun0 | |
| echo "tun0 deleted" | |
| sudo systemctl restart systemd-resolved.service | |
| echo "restored DNS settings" | |
| } | |
| function main() { | |
| user_name=$(get_user) | |
| sudo ip tuntap add name tun0 mode tun user ${user_name} | |
| sudo ip link set tun0 up | |
| sudo ip route add "$BYPASS_IP" $(ip route | grep '^default' | cut -d ' ' -f 2-) | |
| sudo ip route add 128.0.0.0/1 dev tun0 | |
| sudo ip route add 0.0.0.0/1 dev tun0 | |
| sudo ip route add ::/1 dev tun0 | |
| sudo ip route add 8000::/1 dev tun0 | |
| sudo sh -c "echo nameserver 198.18.0.1 > /etc/resolv.conf" | |
| read -n 1 -s -r -p "Press any key to exit this script..." | |
| echo "" | |
| # trap 'echo "" && echo "tun2proxy exited with code: $?" && restore' EXIT | |
| # ./target/debug/tun2proxy --tun tun0 --proxy "$PROXY_TYPE://$PROXY_IP:$PROXY_PORT" | |
| sudo ip link del tun0 | |
| sudo systemctl restart systemd-resolved.service | |
| } | |
| main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment