If you have set up a proxy in Windows, but inside WSL2 the commands apt update,
curl or docker pull
still hang with a timeout — the problem is not with the proxy, but with the architecture of WSL2. We analyze the cause and provide working configurations for Linux, apt.conf, and Docker daemon.
Why WSL2 does not see the Windows proxy
WSL1 worked as a system call translation layer and directly used the Windows network stack, so the proxy set in the system settings was automatically picked up inside the distribution. WSL2 is structured differently: it is a full-fledged virtual machine with its own Linux kernel and a separate virtual network adapter (Hyper-V vEthernet). The Linux subsystem receives its IP address in a private NAT subnet and does not have direct access to the Windows registry, host environment variables, or system proxy settings from "Settings → Network & Internet → Proxy".
Because of this, any tool inside WSL2 — whether it is apt,
pip,
curl, or Docker — accesses the internet directly through the NAT gateway of the virtual machine, completely ignoring the Windows proxy. If you are working in a corporate network where internet access is only possible through a proxy, or you are using external proxy servers for geolocation testing and scraping, you need to manually duplicate the configuration inside the Linux environment itself.
An additional complication: each time WSL2 is restarted, the virtual machine may receive a new IP address from the Windows host in the NAT subnet, so a statically defined proxy address may "drop" after a reboot. More on this in the automation section.
How to find out the current Windows proxy settings
Before configuring Linux, you need to know the address and port of the proxy that Windows is using. If the proxy is set manually, you can view it in PowerShell:
netsh winhttp show proxy
For a system proxy set through the "Settings" interface, open the registry or run:
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable
If you are using a separate proxy server (residential, mobile, or data center) that is not configured in the Windows system settings, but in a specific application or anti-detect browser, you need to get the address and port from the provider's personal account or from the configuration of the tool itself. This pair host:port will be specified in WSL2.
Setting environment variables in WSL2
The basic way to inform Linux tools of the proxy address is through the environment variables http_proxy,
https_proxy, and no_proxy.
Open the WSL2 terminal (Ubuntu or another distribution) and execute:
export http_proxy="http://127.0.0.1:7890"
export https_proxy="http://127.0.0.1:7890"
export no_proxy="localhost,127.0.0.1,::1"
If the proxy is running on Windows itself (for example, through the Clash application, V2Ray, or an anti-detect browser with a local proxy port), you need to replace 127.0.0.1 with the IP address of the Windows host visible from WSL2. You can obtain it with the command:
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'
This IP is the address of the Hyper-V gateway, which is also the address of the Windows host system for WSL2. To ensure that the environment variables are preserved after restarting the terminal, add the export to ~/.bashrc or ~/.zshrc.
Automatic proxy forwarding on each launch
Since the IP address of the Windows host in the NAT subnet may change after restarting the computer, a static entry in .bashrc will eventually stop working. The solution is to dynamically determine the address at each shell launch. Add the following block to ~/.bashrc:
export WSL_HOST=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
export http_proxy="http://${WSL_HOST}:7890"
export https_proxy="http://${WSL_HOST}:7890"
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
export no_proxy="localhost,127.0.0.1,::1"
export NO_PROXY="$no_proxy"
This construction automatically substitutes the current IP of the Windows host each time you open a new WSL2 terminal and works reliably even after system reboots or Windows updates. If the proxy port on the Windows side changes, you only need to adjust the number 7890 to the current one.
Configuring apt to work through a proxy
Environment variables help most CLI utilities, but the package manager apt in Debian/Ubuntu sometimes ignores them, especially when run with sudo, which by default clears the environment. To ensure apt uses the proxy, create a separate configuration file:
sudo nano /etc/apt/apt.conf.d/95proxies
And write inside:
Acquire::http::Proxy "http://172.x.x.x:7890/";
Acquire::https::Proxy "http://172.x.x.x:7890/";
Replace 172.x.x.x with the actual IP of the Windows host from the previous section. After saving the file, run sudo apt update — if the proxy is configured correctly, the package list will update without timeout errors. To preserve environment variables when using sudo, you can also add the line Defaults env_keep += "http_proxy https_proxy" to the /etc/sudoers file via visudo.
Proxy for Docker inside WSL2
Docker in conjunction with WSL2 requires proxy configuration at two levels: for the Docker daemon itself (downloading images) and for the containers that will access the network from within. For the daemon, create a file /etc/systemd/system/docker.service.d/http-proxy.conf:
[Service]
Environment="HTTP_PROXY=http://172.x.x.x:7890"
Environment="HTTPS_PROXY=http://172.x.x.x:7890"
Environment="NO_PROXY=localhost,127.0.0.1"
After creating the file, apply the changes:
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl restart docker
To pass the proxy inside the containers themselves (so that the application inside also goes through the proxy), configure the file ~/.docker/config.json:
{
"proxies": {
"default": {
"httpProxy": "http://172.x.x.x:7890",
"httpsProxy": "http://172.x.x.x:7890",
"noProxy": "localhost,127.0.0.1"
}
}
}
This is especially relevant for those who run headless browsers or scripts for scraping marketplaces and testing ads from different regions in Docker containers. If you need an external proxy server with real geolocation instead of the local Windows proxy — for example, to check how Facebook Ads or TikTok Ads are displayed in a specific country — you can substitute the external proxy data in this config instead of the Windows host address.
Which type of proxy to choose for development and testing
If the task is not limited to internet access from a corporate network, but requires testing applications under different geolocations or scraping external resources from Docker containers in WSL2, it is important to choose the right type of proxy server.
| Type of Proxy | When to use in WSL2/Docker | Speed |
|---|---|---|
| Data Center Proxies | API scraping, CI/CD pipelines, load testing in containers | High |
| Residential Proxies | Geo-targeted ad testing, content verification from different countries within Docker scripts | Medium |
| Mobile Proxies | Emulating mobile traffic when testing Facebook Ads and TikTok Ads from containers | Below average |
For most tasks inside WSL2 — updating packages, accessing internal company APIs, building Docker images — the same proxy configured in Windows is sufficient. However, if you are running scripts to check advertisements, monitor prices on Wildberries or Ozon from different regions, or testing how a website delivers content to users from different IPs, it makes sense to connect a separate external proxy with the required geolocation and specify its address in the apt and Docker configs described above.
Common errors and their solutions
Error 1: apt still hangs with a timeout. Most often, the reason is the Windows firewall, which blocks incoming connections from the WSL2 virtual machine to the proxy port on the host. You need to create a rule in Windows Defender Firewall allowing incoming TCP connections on the used proxy port (for example, 7890) for the Hyper-V subnet.
Error 2: the proxy works, but stops after rebooting the computer. This is a classic case of the host's IP address changing in the NAT subnet. It is solved by a dynamic script in .bashrc, as described in the automation section, instead of a hardcoded IP.
Error 3: Docker builds images without errors, but containers do not see the internet. Check that ~/.docker/config.json contains the current IP, not a cached old address — Docker Desktop sometimes caches proxy settings until the Docker Desktop itself is restarted, not just the daemon.
Error 4: git clone hangs, although apt and curl work. Git uses its own proxy config, which is not directly related to environment variables in some versions. Explicitly set: git config --global http.proxy http://172.x.x.x:7890 and similarly for https.
Proxy setup checklist in WSL2
- Identified the IP and port of the Windows proxy via
netsh winhttp show proxy - Added dynamic export of environment variables to
~/.bashrc - Created
/etc/apt/apt.conf.d/95proxiesfor correct apt operation under sudo - Configured systemd override for the Docker daemon
- Specified the proxy in
~/.docker/config.jsonfor containers - Opened the required port in the Windows firewall for the Hyper-V subnet
- Configured the proxy separately for git if repository cloning is used
Conclusion
WSL2 does not inherit Windows proxy settings automatically due to the isolated virtual network based on Hyper-V, so the proxy must be specified separately at the level of environment variables, apt.conf, and Docker configuration. The main nuance is to dynamically determine the IP of the Windows host, as it may change after a reboot, and also not to forget about the firewall, which blocks connections from the host machine by default.
If the task goes beyond corporate internet access and is related to testing ads from different countries, scraping marketplaces, or checking content under different geolocations directly from Docker containers in WSL2, it is worth connecting a separate external proxy. For stable scraping and CI/CD tasks, data center proxies are well-suited, while for simulating real user traffic when testing geo-targeting — residential proxies with IPs from real home connections.