DNS not working in Bash (Ubuntu) on Windows using VPN

11,181

It's a routing problem, not a bug of WSL. It's very likely that your local subnet is the same as the remote subnet. And I assume you use the bridged VPN.

I have encountered the same issue. I use OpenVPN to connect my office(remote) and my home(local). The two subnets are both 192.168.1.0, which is the most common one where you would find on many routers.

I eventually resolved the issue with the following config. My goal is to use tun in order to reduce overhead and only redirect the traffic where the destination is at the office. However, this would also work with the bridged VPN.

;make the dhcp-option works on Windows 10.
script-security 2
;do not accept any pushed route command.
route-nopull
;make sure the connection still go through my home router. This line may not be necessary. You can try to remove this line and see it the VPN works.
route 192.168.1.1 255.255.255.0 net_gateway
;redirect the traffic where the destination is within the 192.168.1.0 subnet to OpenVPN gateway.
route 192.168.1.128 255.255.255.128
route 192.168.1.0 255.255.255.128
;set the DNS server which is in the office
dhcp-option DNS 192.168.1.254
dhcp-option DNS 192.168.1.253
dhcp-option DOMAIN my.company.domain
Share:
11,181

Related videos on Youtube

Aleksander Akerø
Author by

Aleksander Akerø

Updated on September 18, 2022

Comments

  • Aleksander Akerø
    Aleksander Akerø over 1 year

    I've just started testing out "Bash on Ubuntu on Windows", and I like it!

    Just, the problem is that I need to use VPN in order to access our backend and developer servers. And when trying to (for example) ssh to our dev server with the Windows Bash shell it cannot resolve the hostname.

    Note that I am able to ssh using the ip-address, and also these hostnames work just fine elsewhere in Windows. Like with putty, regular cmd, File Explorer etc.

    I did also check the /etc/resolv.conf and can see our work nameserver listed there.

    From here on my networking skills fall short, especially with Linux, so please help :D

    • Hugh
      Hugh over 6 years
      I've just hit on the same issue. Did you manage to resolve the issue elsewhere?
    • kraego
      kraego almost 3 years
      I had similar issues an got them fixed, also posted my fixes here: stackoverflow.com/a/68573952/11473934
  • Ramhound
    Ramhound over 7 years
    "but would really like to know how to properly set up the network interfaces for Bash on Ubuntu on Windows so that establishing a VPN connection in Windows automatically configures DNS." - You should remove this commentary from your answer.