Networking issues while using VPN
I've tried approaching this two different ways.
Create VPN Within Windows
- Instantiate VPN tunnel using AnyConnect VPN client on my Windows laptop, then connect to upstream devices using SSH via Linux subsystem.
- RESULT: DNS was not properly handed off to the linux subsystem, and no hostname resolution is possible.
Create VPN Connection Within Subsystem
- Instantiate VPN tunnel using OpenConnect networking client
- RESULT: Failed to instantiate network tunnel with the following error
mkdir: cannot create directory ‘/dev/net’: No such file or directory
Any help would be greatly appreciated, as I often perform work on VMs which are located behind a firewall of some sort
Same thing with OpenVPN
For the time being, it is possible to manually configure host names in /etc/hosts, but long run this is not a reliable solution unfortunately.
ex:
127.0.0.1 localhost.localdomain
192.168.1.1 my.host.name
192.168.1.2 some.other.host.name
This is an important issue and pretty much the only thing that holds me back from switching from Mac back to Windows
@esabelhaus - Thanks for providing this feedback. Regarding "Create VPN Within Windows" scenario, were the right entries not getting populated in /etc/hosts automatically?
Regarding "VPN Connection Within Subsystem", unfortunately, WSL currently does not support '/dev/net'. If that is an important scenario for you (and @saschagehlich), please help us prioritize that providing that feedback through our User Voice Page.
specifically, when the VPN is running on my windows machine, the linux subsystem was not properly handling host name resolution, while my windows machine was. It would appear to be DNS related at that point.
This symptom occurs both when starting the subsystem before or after I have instantiated my VPN connection. IP addresses do resolve, but the host name resolution eg /etc/hosts does not properly handle the new dns providers which are passed in from the VPN device on windows
@esabelhaus, am I understanding correctly that you were able to get around this issue? If so, could you please elaborate on your fix for someone who isn't as familiar with /etc/hosts and the like?
Here is a decent reference for how /etc/hosts works.
http://www.tldp.org/LDP/solrhe/Securing-Optimizing-Linux-RH-Edition-v1.3/chap9sec95.html
The gist is, you're mapping an IP address to a hostname, and at startup, the Ubuntu based linux subsystem is reading in the configuration file /etc/hosts and using that information to map networking to a hostname. Everything must be routed over TCP/IP, so we're telling the linux host that:
10.0.0.2 my.host.name
would allow me to ssh into 10.0.0.2 using the hostname my.host.name using the command ssh [email protected]
You can sort of understand why this is not a reasonable workaround, because it requires you to manually configure your host configuration for any hostname which you must access within the VPN subnet.
Hope that explanation helps!
-Haus
That definitely helps! Not too complicated at all.
Unfortunately, that didn't fix my issue.
I'm using ruby and net/http to send a POST request to a URL behind the VPN.
While connected to VPN, I used nslookup to find the IP of the host I'm trying to connect to.
I edited /etc/hosts to include that IP and host.
I then run my ruby code (which works through the windows command line).
I get a 404 response in WSL.
Do you see something I might be missing?
try running dig my.host.name on your host, and see whether the IP address is what you have referenced in your /etc/hosts config
Also, if you've got access to the host behind the firewall directly, maybe tail the logs server side to see whether the resource is actually available, going off the 404 error.
For what it's worth, a 404 error means that you did successfully connect to the server in question (which is all that /etc/hosts has control over) but that host is reporting that the particular page that you requested doesn't exist.
Is it possible that you made a typo in the hostname? Or otherwise didn't type it exactly as it appears / is used (including prefixes like "www.", etc). If you did, and if your remote server is using SNI, this would cause it to route you incorrectly.
You could also try using curl or wget, or installing VcXsrv and running firefox, to browse the server manually from within WSL.
Your instructions for installing VcXsrv are fantastic! Thank you for that. I am able to run firefox, but it gets a 404 page as well. I get the same 404 page whether I am connected to VPN or not.
I take the same URL and paste it into Chrome running in Windows, and the page works.
Any other thoughts? Thank you very much for your time, by the way!
@aseering, you were right all along. Firefox from WSL was a big help figuring it out.
In the end it was pretty simple. I put the wrong IP address in /etc/hosts. It was a public URL and not the 192.168... IP. Once I fixed that, I was able to make the connection. Thanks, and I can't wait for @bitcrazed and team to get this particular kink worked out!
One thing you can do, if the software you need is capable of operating entirely through a proxy server, is setup a ssh tunnel with proxy on the host, and then use that. I can use that with Firefox in WSL to connect to sites on my work network .. I have a ssh tunnel setup on localhost that goes through another machine which is actually connected to VPN.
The problem that I have, is that I can't connect with anything but firefox, since there's no real way to force Linux to connect to everything through a SOCKS5 Proxy (unlike with Windows and Mac, there are several softwares out there that make that happen) ... as far as I've ever been able to find ... so every individual piece of software needs to be configured to use it.
So, the configuration that I use:
One (Linux) machine connected to VPN (also handles a host of other tasks, but it's basically a server box -- sits in a closet, and is only operated via remote). My primary Windows computer. Windows computer has a program called MobaXTerm installed, which provides ssh, tunnel, proxy, and X server (among many other things!). Windows also has a program called Proxifier that routes literally everything destined for a host on the other side of the VPN through a ssh tunnel socks5 proxy. Configure a ssh tunnel/socks5 proxy in MobaXTerm to go through the Linux box. Works great in Windows. In WSL, configure Firefox to use the proxy. That also works great, but also sends all traffic through the work VPN, which is not really acceptable, and is part of why I use this configuration.
The part that confuses me, is that WSL is completely unable to see the other side of the VPN tunnel. (Coincidentally, neither is Microsoft Edge -- both seem to bypass the DLL injection that Proxifier does, which makes them kind of bad citizens .. although I can justify it more in my head for WSL than for Edge..)
One primary problem reported by the OP (@esabelhaus) is that DNS changes in Windows (e.g. by a VPN) do not get reflected to the /etc/resolv.conf in real time on WSL. Add to this that WINS resolution isn't configured into WSL at all by default (currently).
Even to veteran linux users, when DNS isn't working, it "feels" like IP networking has failed, and that's how it frequently gets reported, when just fixing DNS would get things going again. Since Windows is providing the routing table and retworking devices (transparently), having /etc/resolv.conf set up once per session, and with the DNS resolver settings of just one network adapter (I think), leads to many situations where DNS fails for WSL and with it the "feeling" that networking is broken.
Here's a suggestion: set up the Windows resolver to allow WSL to use it (connecting via UDP and TCP), so /etc/resolv.conf can list localhost as the resolver. That way all of the networking (devices, pseudo-devices, routing, DNS, etc) would be going through Windows, and problems in WSL would show up as problems in Windows, and fixing them in Windows via Windows tools would resolve them in WSL.
I'd expect that to be a much nicer UX.
Setting things up so WSL is handling all networking (interfaces, iptables/firewall/routing, DNS, VPN, tun/tap, etc; perhaps even dhcp and vpn protocols) is flexible but fairly complex, and, likely, everything on the Windows side would have to be replicated to the WSL side. So I wouldn't be disappointed if the current philosophy of "passing networking off to Windows" was maintained. Letting the local Windows do DNS resolution via /etc/resolv.conf would be straightforward and a "linuxy" way to handle DNS, at least from a user's point of view, and wouldn't require trying to keep /etc/resolv.conf (or /etc/hosts) up to date in real time as things change on the Windows side.
Sounds like a good idea. DNS isn't the root of my problem, unfortunately, but I'd welcome the improvements.
@aseering That's pretty wild ... X Windows on Windows.
Still having the same issue as @esabelhaus (subsystem ignoring any Windows VPN connection), has there been any update on this?
@ewan-fanduel have you tried manually editing your /etc/hosts file?
@jwsloan I can yep, but the hosts I work with change often so it's a bit of hassle to keep updating it manually :/
@ewan-fanduel that sucks, does your router support dynamic DNS[https://en.wikipedia.org/wiki/Dynamic_DNS]?