How to make Windows Subsystem for Linux use proxied connections?
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?
Solution 1:
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.
Solution 2:
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.