Skip to content

Instantly share code, notes, and snippets.

@imannms000
Last active January 11, 2024 22:52
Show Gist options
  • Save imannms000/dbe16d0b14cd2193fd77b81027b5e932 to your computer and use it in GitHub Desktop.
Save imannms000/dbe16d0b14cd2193fd77b81027b5e932 to your computer and use it in GitHub Desktop.
How To Use Proxy on WSL2 Ubuntu for APT, etc.
@imannms000
Copy link
Author

imannms000 commented Oct 14, 2023

How To Set Proxy on WSL2 Ubuntu for APT, etc.

  1. Add the ip address of your host machine and the port that the proxy runs on to .bashrc:
// .bashrc

export http_proxy="http://proxy:port"
export https_proxy="http://proxy:port"
  1. Add the proxy and port to /etc/apt/apt.conf.d/proxy.conf as well:
    sudo touch /etc/apt/apt.conf.d/proxy.conf
    sudo nano /etc/apt/apt.conf.d/proxy.conf
// proxy.conf

Acquire::http::Proxy "http://987.654.32.1:1234/";
Acquire::https::Proxy "http://987.654.32.1:1234/";
  1. And finally, add an appropriate rule to the Windows Firewall on port 1234 (else, WSL2 is unable to communicate with the proxy). Be careful here!

Windows Defender:
Allow Port to Inbound and Outbound rules.

DONE.

Example

CURL

curl --proxy http://proxy:port --url www.google.com

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