I met some problems when I downloaded some files from GitHub on WSL2. I cannot download files when I connect to GitHub directly. So, I try to use a proxy to solve the problem. I have tried serval solutions which do not work.
Now, there is a way to solve the problem with the following content.
Preparation:
-
Open the function of Allow LAN in your proxy software.
-
Get the port(eg. Clash’s default port is 7890) of the proxy.
Solution:
-
Add the following code at the end of
.bashrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33ipip=$(grep nameserver /etc/resolv.conf | sed 's/nameserver //')
proxy_port=7890
showproxy()
{
echo ''
echo 'Show Proxy:'
echo "http_proxy=$http_proxy"
echo "https_proxy=$https_proxy"
echo "ftp_proxy=$ftp_proxy"
echo "ALL_PROXY=$ALL_PROXY"
echo ''
}
proxy () {
export ALL_PROXY=socks5://${ipip}:${proxy_port}
export ftp_proxy=http://$ipip:$proxy_port/
export http_proxy=http://$ipip:$proxy_port/
export https_proxy=http://$ipip:$proxy_port/
showproxy
curl -vv http://google.com
}
noproxy () {
unset ALL_PROXY
unset ftp_proxy
unset http_proxy
unset https_proxy
showproxy
curl myip.ipip.net
}
proxy -
Enabling environment variables
1
source .bashrc
-
Now, you can use the following command to activate proxy and deactivate proxy in shell.
1
2
3
4
5# activate
proxy
# deactivate
noproxy
And have a nice day!