- Add the following code to
.bashrc
. - Run
source .bashrc
to reload. - Run
proxy
to setup proxy, andunproxy
to unproxy.
function getip {
export winip=$(ip route | grep default | awk '{print $3}')
export wslip=$(hostname -I | awk '{print $1}')
echo "WIN IP: ${winip}"
echo "WSL IP: ${wslip}"
export PROXY_HTTP="http://${winip}:7890" # SET YOUR HTTP PORT
export PROXY_SOCKS5="socks5://${winip}:7890" # SET YOUR SOCKS PORT
}
function proxy {
getip
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_PROXY="${PROXY_HTTP}"
export all_proxy="${PROXY_SOCKS5}"
export ALL_PROXY="${PROXY_SOCKS5}"
echo "http: ${PROXY_HTTP}"
echo "socks5: ${PROXY_SOCKS5}"
echo "DONE!"
}
function unproxy {
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset all_proxy
unset ALL_PROXY
echo "DONE!"
}