4

I have a Windows 10 machine that connects to internet via px-proxy using localhost and port 1234 without login what works just fine; PowerShell & Co. can successfully connect to the internet. Now I'm using Ubuntu 20.04 LTS over WSL2 and from there I'm unable to connect to the internet.

I tried

> more etc/resolv.conf
nameserver 8.8.8.8
> tail .bashrc
...
export http_proxy="123.456.78.9:1234";
export https_proxy="123.456.78.9:1234";
> more /etc/apt/apt.conf.d/proxy.conf
Acquire {
  HTTP::proxy "http://123.456.78.9:1234";
  HTTPS::proxy "http://123.456.78.9:1234";
}
netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=123.456.78.9

and combinations of. I made sure the IP of the host...

> ipconfig
...
Ethernet adapter vEthernet (WSL):
   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 123.456.78.9
   Subnet Mask . . . . . . . . . . . : abc.abc.abc.a
   Default Gateway . . . . . . . . . :

... matches those of WSL2 Ubuntu:

> ip route
default via 123.456.78.9 dev eth0
123.456.78.9/10 dev eth0 proto kernel scope link src xyz.xyz.ba.b

Now I am lost with the various possibilities and not sure, if I am doing something obviously wrong here or if I am overlooking something. Thank you in advance for any hints! :)

2 Answers2

1

Uff figured it out, finally :)

So, to reach the internet through a proxy from a Ubuntu distro on WSL2:

First, catch the ip adress of the host machine:

> ipconfig
...
Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : reddog.microsoft.com IPv4 Address. . . . . . . . . . . : 987.654.32.1 Subnet Mask . . . . . . . . . . . : xyz.xyz.xyz.z Default Gateway . . . . . . . . . : 11.111.111.1

  • /etc/resolv.conf remains as is
  • Add the ip adress of your host machine and the port that the proxy runs on to .bashrc:
export http_proxy="987.654.32.1:1234"
export https_proxy="987.654.32.1:1234"
  • Add the proxy and port to /etc/apt/apt.conf.d/proxy.conf as well:
Acquire::http::Proxy "http://987.654.32.1:1234/";
Acquire::https::Proxy "http://987.654.32.1:1234/";
  • 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!
0

in your ~/.profile try

WINDOWS_IP=$(powershell.exe -Command '(Get-NetIPAddress -AddressFamily IPv4 -InterfaceAlias "vEthernet (WSL)").IPAddress | Write-Host')
export http_proxy="http://${WINDOWS_IP}:3128"
export https_proxy=$http_proxy

check the port