Enable Proxy in WSL2 on windows 11

I have used windows 11 several weeks ago for work.

There have some reasons for me why from Mac to windows:

1, WSL 2 provide full Linux support

2, Windows Laptop has Nvidia Geforce 3070 GPU and 64GB memory

I was working for blockchain development, such as Filecoin Lotus, Cosmos, Polkadot, BSC, etc.

Though I am going to develop a new chain for our new business.

Cause Windows every reboot, the wsl2 network IP address will be changed. so I need to update the proxy setting, so I can normally work, I am living in China.


host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
echo $host_ip

export ALL_PROXY="socks5://$host_ip:51837"
export HTTP_PROXY="http://$host_ip:1087"
export HTTPS_PROXY="http://$host_ip:1087"

put the above lines in the bash script file, and source it.

If you want to add it into bashrc,

. "$HOME/enable_proxy.sh"

use env command to ensure the proxy settings successfully.

Leave a Reply

Your email address will not be published.