Bash on Ubuntu on Windows - could not resolve host using VPN
I'm using Windows for my development purposes and I'm accessing my company's resources using VPN which is set up on my machine. I mainly use it to access company's private git repositories.
I recently started using Bash on Ubuntu on Windows for development purposes and I've been experiencing problems accessing the repositories.
For example, when I'm connected to VPN and use Git Bash on Windows to clone a repository it works perfectly fine. But when I use git in the Bash on Ubuntu on Windows it spits out an error:
fatal: unable to access 'https://link.to.the.repository.net/Project/Repository/': Could not resolve host: link.to.the.repository.net
Is there a way to let the Bash on Ubuntu on Windows access such resource?
Automated steps: https://gist.github.com/matthiassb/9c8162d2564777a70e3ae3cbee7d2e95
First run on powershell:
Get-DnsClientServerAddress -AddressFamily IPv4 | Select-Object -ExpandPropert ServerAddresses
Then run bash on windows with either ubuntu
or bash
commands (depending on your installation)
Edit the /etc/resolv.conf
and replace all nameserver {ip}
with the ones generated by the top one.
You should have internet and intranet back now. Remove the first line to make it permanent but be aware if you change networks it will not update anymore. (back it up first maybe?)
For me, the issue was that my VPN had internal nameservers. These nameservers were present on the windows machine, but didn't make it into the linux subsystem. Steps to fix:
- Run ipconfig /all on Windows. There should be a block for your VPN connection that contains one or more DNS Servers.
- Open bash and open /etc/resolv.conf
- If your situation is like mine, you will see the nameservers for your main internet adapter, but NOT the nameservers from the VPN adapter above. Simply add the VPN's DNS names in addition to what's there (I added mine above the existing entries if that matters), save the file, and try to access the repo again.
It seems there are no name server(s) to resolve the host name. Inside Ubuntu bash, edit the file /etc/resolv.conf so that it contains:
nameserver X.Y.Z.W
I am assuming you are using IPv4. The address above is just an example. You'll have to find out your actual DNS address your ISP is using or choose a public DNS server. You can use multiple name servers if you like.