12

As in title, I want to make Ubuntu 20.04 LTS WSL use proxied connections; I am in China, behind the infamous Great Firewall of China, if that doesn't ring any bells, just Google it.

Fortunately I know how to bypass it freely(as in "free of charge"), currently I use Lantern, its http proxy port is 1053, I had set it to "manage system proxy" and "proxy all traffic", I had run these commands:

netsh winhttp set proxy 127.0.0.1:1053
reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d "127.0.0.1:1053" /f

And made Lantern proxy PowerShell traffic in addition to browsers and downloaders.

Now, I enabled Windows Subsystem for Linux, installed wsl_update_x64.msi, installed Ubuntu 20.04, and ran this:

sudo apt update

And it downloads files from archive.ubuntu.com and security.ubuntu.com with astonishingly slow speed: several (below 10)KB/s, my connection is 100mbps PPPoE(translates to 11.920928955078125MiB/s download speed), undoubtly it isn't being proxied, so how can I proxy its traffic?

Ξένη Γήινος
  • 3,902
  • 13
  • 45
  • 84

4 Answers4

13

Never mind, I had just solved it, again, and found sometimes Google really can be useful, well, I said SOMETIMES.

I just found this: https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-the-proxy-for-apt-for-ubuntu-18-04/

I used these:

sudo touch /etc/apt/apt.conf.d/proxy.conf
sudo vi /etc/apt/apt.conf.d/proxy.conf
Acquire::http::Proxy "http://127.0.0.1:1053/";
:wq

(AND I closed Ubuntu)

Now its speed is much more resonable.

Ξένη Γήινος
  • 3,902
  • 13
  • 45
  • 84
6

This worked for me too..

For other general HTTP access you can set proxy as follow

export http_proxy=<proxyUrl>:<proxyPort>

You can also have this in bash profile so that you do not have to set it each time.

2

I am able to resolve this issue of my Python code by following code

export https_proxy=<proxyUrl>:<proxyPort> && export http_proxy=$https_proxy && no_proxy=.<domainUrl>,127.0.0.1,localhost

You can set this to your bash profile for future usage.

Vishnu
  • 121
1
  1. Run cat /etc/resolv.conf, you will get:

    # [network]
    # generateResolvConf = false
    nameserver 172.19.48.1
    

    172.19.48.1 is your windows IP. Copy it.

  2. add this to your ~/.bashrc or ~/.zshrc.

    function proxy {
      export http_proxy=socks5://172.19.48.1:7890; export https_proxy=socks5://172.19.48.1:7890; export all_proxy=socks5://172.19.48.1:7890;
      export HTTP_PROXY=socks5://172.19.48.1:7890; export HTTPS_PROXY=socks5://172.19.48.1:7890; export ALL_PROXY=socks5://172.19.48.1:7890;
      echo -e "proxy on"
    }
    function unproxy {
      unset http_proxy https_proxy all_proxy
      unset HTTP_PROXY HTTPS_PROXY ALL_PROXY
      echo -e "proxy off"
    }
    

    function proxygit { git config --global https.proxy socks5://172.19.48.1:7890 git config --global http.proxy socks5://172.19.48.1:7890 git config --global ssh.proxy socks5://172.19.48.1:7890 echo -e "git: proxy on" }

    function unproxygit { git config --global --unset https.proxy git config --global --unset http.proxy git config --global --unset ssh.proxy echo -e "git: proxy off" }

  3. In your proxy software installed on windows, go to its settings, make sure it allows connections from LAN.

  4. Open a new WSL2 terminal and run proxy then test your network like curl google.com. Run unproxy to turn it off.

proxygit, unproxygit updates git proxy config in ~/.gitconfig file, so run once, it works in every open terminal tab.

ref: HTTPS_PROXY vs https_proxy

shrekuu
  • 111
  • 3