Skip to content

Instantly share code, notes, and snippets.

@sko00o
Last active December 5, 2023 10:25
Show Gist options
  • Save sko00o/a3b2051826f1e5140d0f748f211f2c83 to your computer and use it in GitHub Desktop.
Save sko00o/a3b2051826f1e5140d0f748f211f2c83 to your computer and use it in GitHub Desktop.
set proxy in wsl
#!/usr/bin/env bash
hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
wslip=$(hostname -I | awk '{print $1}')
port=7890
PROXY_HTTP="http://${hostip}:${port}"
proxy_set(){
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_PROXY="${PROXY_HTTP}"
export no_proxy="10.0.0.0/8,192.168.0.0/16,127.0.0.1,172.16.0.0/16,::1"
export NO_PROXY="10.0.0.0/8,192.168.0.0/16,127.0.0.1,172.16.0.0/16,::1"
}
proxy_unset(){
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset no_proxy
unset NO_PROXY
}
proxy_test(){
echo "Host ip: ${hostip}"
echo "WSL ip: ${wslip}"
echo "Current proxy: ${http_proxy}"
}
if [ "$1" = "set" ]; then
proxy_set
elif [ "$1" = "unset" ]; then
proxy_unset
elif [ "$1" = "test" ]; then
proxy_test
else
echo "Unsupported option '$1'"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment