DNS not working with OpenVPN

I have set up OpenVPN as described here

It successfully connects, but DNS resolution is not working. I’m not able to reach any of our internal services without the hacky workaround of adding

networking.extraHosts = ''<IP> <domain>'';

to my configuration.nix. I think there is yet another person with a similar problem.

I’m kinda new to Linux and NixOS. I expected this to work “out of the box”, but it seems something is missing. Do you have any hints as to what I can try to make DNS resolution for internal services succeed?

I had the same problem with my company VPN.

sudo nmcli connection modify id VPN-NAME ipv4.dns-search '~.' ipv4.dns-priority -5
services.openvpn.servers = {
  officeVPN = {
    autoStart = true;
    config = '' config /root/nixos/openvpn/officeVPN.conf '';
    updateResolvConf = true; # maybe this line could fix it
  };
};
1 Like

Yes, indeed, that seems to have done the trick, completely hack-free. Thanks heaps! I added this line to the docs

1 Like

That’s great, but what if you would like to run it directly from the binary cli and not as a service, what then?

never tried but maybe this could help you