Skip to content

Instantly share code, notes, and snippets.

@aucker
Last active March 27, 2023 06:46
Show Gist options
  • Save aucker/d0fce5477e02cdd7fa76c1c81a87a610 to your computer and use it in GitHub Desktop.
Save aucker/d0fce5477e02cdd7fa76c1c81a87a610 to your computer and use it in GitHub Desktop.

Use proxy in WSL2:rocket:

TL;DR

Every time windows reboots, the IPv4 address will change, FXXK!!!:sweat_smile:

In .zshrc or .bashrc file, write the following commands:

export HTTP_PROXY=http://xxx.xxx.xxx.xxx:port

I found a better way:

# proxy
proxy () {
  export http_proxy="http://xxx.xxx.xxx.xxx:port"
  export https_proxy=$http_proxy
  echo "HTTP Proxy on"
}
# no proxy
noproxy () {
  unset http_proxy 
  unset https_proxy
  echo "HTTP Proxy off"
}

Now a even better way:

Shell is awesome!😘 Add the following code in the ~/.profile, 😊

host_ip=$(cat /etc/resolv.conf | grep "nameserver" | cut -f 2 -d " ")
export ALL_PROXY="http://$host_ip:7890"

After this, I can use git normally, curl works sometimes, but it seems that wget still not working. Dont know why. The following command works well,

➜  ~ curl https://raw.githubusercontent.com/aucker/VimConfig/master/.vimrc -o .vimrc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  4759  100  4759    0     0   4684      0  0:00:01  0:00:01 --:--:--  4684

but when I use wget, I got the error:

➜  ~ wget https://raw.githubusercontent.com/aucker/VimConfig/master/.vimrc
--2022-08-25 17:23:30--  https://raw.githubusercontent.com/aucker/VimConfig/master/.vimrc
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 0.0.0.0, ::
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|0.0.0.0|:443... failed: Connection refused.
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|::|:443... failed: Connection refused.

This use computer IPv4 address and clash port.

Windows10/11: image

In clash, enable the ALLOW LAN.

image

@Corner430
Copy link

Add the following line to /etc/hosts
185.199.108.133 raw.githubusercontent.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment