WSL icon indicating copy to clipboard operation
WSL copied to clipboard

While connected to VPN the curl command hangs up

Open Darkside81 opened this issue 7 years ago • 36 comments

OK: From our office and from home remotely, we can use the VPN connection, curl succeeds. OK: While visiting our customer's office, without using the VPN connection, curl also succeeds. FAIL: While visiting our customer's office, when using the VPN connection, curl hangs as follows:

$ curl ifconfig.co; curl -vvv https://testlink.limelightbox.com 
198.199.107.195 
* Rebuilt URL to: https://testlink.limelightbox.com/ 
* Trying 52.39.78.238... 
* TCP_NODELAY set 
* Connected to testlink.limelightbox.com (52.39.78.238) port 443 (#0) 
* ALPN, offering h2 
* ALPN, offering http/1.1 
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH 
* successfully set certificate verify locations: 
* CAfile: /etc/ssl/cert.pem 
CApath: none 
* TLSv1.2 (OUT), TLS handshake, Client hello (1):

Above simply hangs.

Can someone assist with advice

Darkside81 avatar Sep 17 '19 22:09 Darkside81

What build of Windows are you using? And are you using WSL 1 or WSL 2?

craigloewen-msft avatar Sep 17 '19 22:09 craigloewen-msft

Also maybe try Windows curl.exe with the VPN up and see if that takes, just for the datapoint. Eliminates WSL if it doesn't work. Points finger at WSL if it does.

therealkenc avatar Sep 18 '19 00:09 therealkenc

This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment. Thank you for your contributions to WSL!

ghost avatar Sep 25 '19 19:09 ghost

I'm having a similar issue with our VPN.

Git and SSH both hang over the VPN from WSL but both work just fine from within Windows.

Windows version: Microsoft Windows [Version 10.0.18990.1]

The VPN client is Shrew Soft standard edition version 2.2.2.

By the way, I've been using this VPN client version with a VMware Linux VM for years just fine, NATing through windows.

zot avatar Oct 01 '19 15:10 zot

I'm using WSL 2

Darkside81 avatar Oct 01 '19 16:10 Darkside81

@Darkside81 and @zot could you please take networking logs of the issue that you're seeing? Instructions on how to do so are here. Please comment back on this thread with a link to your feedback item and we can take a look at what might be causing it! Thanks!

craigloewen-msft avatar Oct 01 '19 19:10 craigloewen-msft

OK, here's the link.

In the test, I was able to make a regular HTTP connection (we don't have HTTPS running internally) through our VPN but I could not SSH.

zot avatar Oct 07 '19 13:10 zot

I'm able to use services on our VPN by port-forwarding with SSH from within Windows-land. Maybe other people with this problem can use a similar technique. Here's my script (run it from git-bash/msys/cygwin):

#!/bin/sh
MAIL_HOST=YOUR-MAIL-HOST
SSH_USER=YOUR-USER-NAME
SSH_HOST=YOUR-VPN-SSH-HOST
ADDR=$(ipconfig|sed '/WSL/ {N;N;N;N;s/\n//g;s/^.*: \([^:]*\)$/\1/;p};d')
echo $ADDR
exec ssh -L $ADDR:11000:$MAIL_HOST:110 -L $ADDR:2500:$MAIL_HOST:25 $SSH_USER@$SSH_HOST

It just finds the ip addr of the WSL adapter, prints it out, and uses SSL to port-forward 11000->110 and 2500->25 on it.

Configure your Linux email client to use the printed IP address and port 11000 for pop, 2500 for outgoing.

Note that the WSL switch changes IP every time you boot: https://github.com/microsoft/WSL/issues/4150

I have a second workaround for this, I created a NAT switch Hyper-V Manager and I actually use that instead of the WSL adapter (my script uses Ethernet NAT instead of WSL). It has a static IP, so it doesn't change every time I boot.

zot avatar Oct 10 '19 08:10 zot

I'm able to use services on our VPN by port-forwarding with SSH from within Windows-land. Maybe other people with this problem can use a similar technique. Here's my script (run it from git-bash/msys/cygwin):

#!/bin/sh
MAIL_HOST=YOUR-MAIL-HOST
SSH_USER=YOUR-USER-NAME
SSH_HOST=YOUR-VPN-SSH-HOST
ADDR=$(ipconfig|sed '/WSL/ {N;N;N;N;s/\n//g;s/^.*: \([^:]*\)$/\1/;p};d')
echo $ADDR
exec ssh -L $ADDR:11000:$MAIL_HOST:110 -L $ADDR:2500:$MAIL_HOST:25 $SSH_USER@$SSH_HOST

It just finds the ip addr of the WSL adapter, prints it out, and uses SSL to port-forward 11000->110 and 2500->25 on it.

Configure your Linux email client to use the printed IP address and port 11000 for pop, 2500 for outgoing.

Note that the WSL switch changes IP every time you boot: #4150

I have a second workaround for this, I created a NAT switch Hyper-V Manager and I actually use that instead of the WSL adapter (my script uses Ethernet NAT instead of WSL). It has a static IP, so it doesn't change every time I boot.

How can you set the WSL VM use the "NAT Switch" you have created?

timesnewmen avatar Oct 11 '19 07:10 timesnewmen

I'm able to use services on our VPN by port-forwarding with SSH from within Windows-land. Maybe other people with this problem can use a similar technique. Here's my script (run it from git-bash/msys/cygwin):

#!/bin/sh
MAIL_HOST=YOUR-MAIL-HOST
SSH_USER=YOUR-USER-NAME
SSH_HOST=YOUR-VPN-SSH-HOST
ADDR=$(ipconfig|sed '/WSL/ {N;N;N;N;s/\n//g;s/^.*: \([^:]*\)$/\1/;p};d')
echo $ADDR
exec ssh -L $ADDR:11000:$MAIL_HOST:110 -L $ADDR:2500:$MAIL_HOST:25 $SSH_USER@$SSH_HOST

It just finds the ip addr of the WSL adapter, prints it out, and uses SSL to port-forward 11000->110 and 2500->25 on it. Configure your Linux email client to use the printed IP address and port 11000 for pop, 2500 for outgoing. Note that the WSL switch changes IP every time you boot: #4150 I have a second workaround for this, I created a NAT switch Hyper-V Manager and I actually use that instead of the WSL adapter (my script uses Ethernet NAT instead of WSL). It has a static IP, so it doesn't change every time I boot.

How can you set the WSL VM use the "NAT Switch" you have created?

I'm not setting the WSL VM to use the NAT switch. I'm using a vanilla WSL 2 Ubuntu setup except that I'm limiting the memory usage (currently to 8G). The NAT switch just happens to work for forwarding because it has a static IP and it's part of my Windows setup (I actually used the NAT switch earlier with a Hyper-V VM that I don't use anymore).

zot avatar Oct 11 '19 11:10 zot

How can you set the WSL VM use the "NAT Switch" you have created?

Maybe my last comment wasn't so helpful. I just used a virtual switch I already had lying around. It's not actually connected to WSL 2 or any other VM. To make one, open the Hyper-V Manager and click "Virtual Switch Manager...". Then create a new virtual switch like this, hooking it into your ethernet or wifi network, whichever one you use:

image

Once you've created it, use ipconfig to see the IP address Windows has assigned to it. Mine uses a dynamic IP but Windows has given it the same IP every time I've booted, so far.

I tried using Default Switch, because I wanted it to work with both ethernet and wifi but that didn't work for me. Once you've made the switch, make your SSH tunnel listen on its address, like in my script, above.

zot avatar Oct 16 '19 06:10 zot

I'm having the exact same problem, I can't work when connected to my company network. The network does not seem to work in some scenarios. DNS resolution works. Curl does not work, either with http or https.

This is what I get on http:

❯ curl --verbose http://www.google.com
*   Trying 172.217.29.132:80...
* TCP_NODELAY set
* Connected to www.google.com (172.217.29.132) port 80 (#0)
> GET / HTTP/1.1
> Host: www.google.com
> User-Agent: curl/7.65.3
> Accept: */*
>
* Recv failure: Connection reset by peer
* Closing connection 0
curl: (56) Recv failure: Connection reset by peer

On https the log is the same as from this issue, but I'm on TLS 1.3:

❯ curl --verbose https://www.google.com
*   Trying 172.217.29.132:443...
* TCP_NODELAY set
* Connected to www.google.com (172.217.29.132) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: none
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to www.google.com:443
* Closing connection 0
curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to www.google.com:443

I'll report the logs as explained earlier, as well.

I'm on Windows Version 10.0.19041.207, WSL 2, Ubuntu 18.10 (but it also repros on Suse).

curl.exe works on Windows normally.

curl works when the vpn is not being used.

giggio avatar Apr 26 '20 02:04 giggio

I have same issue as @giggio except that my curl works for public addresses such as google.com. Any internal resource inside company private network I get the same behavior as @giggio. Windows side works fine. Check Point Mobile VPN client opened in Windows that to my knowledge should route ALL traffic via company network.

I made the feedback as @craigloewen-msft instructed and it can be found here. Hope it helps.

kaskii avatar Apr 28 '20 14:04 kaskii

I'm having the same issue with WSL2+VPN:

  • ping company website domain - ok
  • curl/wget company website from wsl2 - hangs
  • curl/wget external website from wsl2 - ok
  • curl/wget company website from cmd.exe - ok

To get around this problem, I'm redirecting http(s)/ssh requests in wsl2 through a proxy set up in Windows-land, and curl/wget/git are working properly now. Hope it helps.

FallenMax avatar Apr 30 '20 05:04 FallenMax

@FallenMax how did you do that? Please share, that would be very useful to me right now.

giggio avatar Apr 30 '20 12:04 giggio

@giggio Here's my setup:

1. Setup a HTTP or SOCKS5 proxy in Windows-land

I'm using cow, as I already have it installed (you can use whatever proxy software works). My cow config rc.txt is as below:

listen = http://0.0.0.0:7777

It does nothing other than proxying traffic from port 7777 to Windows network.

2. Setup curl/wget/git in WSL2 to use the Windows proxy above

  • for curl/wget, I'm using proxychains-ng, a software that forces any linux program use specified proxy. But if you only need curl or wget, just setting up http_proxy and https_proxy environment variable should be enough. e.g. export http_proxy=http://${your windows local IP}:7777
  • for git (that uses ssh protocol), add these config to ~/.ssh/config:
Host git.yourcompany.com
User git
ProxyCommand nc -X connect -x 192.168.2.171:7777  %h %p

replace git.yourcompany.com with your company's Gitlab host, and replace 192.168.2.171 with your Windows machine's local IP (see ipconfig.exe) and it's done.

FallenMax avatar Apr 30 '20 13:04 FallenMax

Thanks, @FallenMax, this works perfectly. Cow is a cool project, it's a pity I can't understand most of it because of the Chinese. But it will solve other issues for me, so thanks for that too.

I hope someone from the WSL team is able to investigate this in the meantime.

giggio avatar May 01 '20 17:05 giggio

@giggio Thank you, glad it helps! English version of Cow's README.md and example config are available if needed.

FallenMax avatar May 02 '20 03:05 FallenMax

May this could be a fix for you: Set MTU to the value of the VPN interface: sudo ifconfig eth0 mtu 1350

neseih avatar May 14 '20 15:05 neseih

@neseih this actually solves the problem. What exactly is going on? How do I find out the 1350 number, is it on Windows somewhere? And thanks for that.

giggio avatar May 14 '20 15:05 giggio