I am trying to set up a wireguard VPN (not mullvad) on qubes 4.1
I followed this guide by mullvad (using a fedora 34 template for the ProxyVM) and I also tried this guide (using a debian 11 template as ProxyVM).
Both left me with the same problem: DNS
In my resulting sys-wireguard ProxyVM everything seems fine, I can use DNS and I am connected to the VPN server.
However, in my AppVM, I cannot connect to any URL, just IP-addresses (which can be inconvinient at times…).
I did not find any reports of that issue in this forum, so I guess it is me who made a mistake.
Can you explain how to change the DNS and anti-leak firewall rules when using my own wireguard configuration? This could be the problem…
The result of this DNS-problem led me to setting up the VPN connection right inside the templateVM I use for creating my AppVMs (and setting the AppVM’s networking VM to sys-firewall). This worked fine for some time, but now I face the same DNS problem using this fix aswell. Running sudo dpkg-reconfigure resolvconf in the AppVM fixes that until the next reboot (found this temporary fix somewhere on stackoverflow).
It is worth mentioning that my wireguard configuration already contains some iptables:
PostUp = iptables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT && ip6tables -I OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
PreDown = iptables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT && ip6tables -D OUTPUT ! -o %i -m mark ! --mark $(wg show %i fwmark) -m addrtype ! --dst-type LOCAL -j REJECT
I do not know in detail what this gibberish does, it is somehow used to create a kill-switch…
I would love to have a sys-wireguard because this is what makes Qubes great: compartmentalization (the workaround with sudo dpkg-reconfigure resolvconf is a pain…).
Yes, this is your problem. You need to configure DNS requests redirect.
To change the config in /rw/config/qubes-ip-change-hook for you server you need to change these lines:
NS_MULLVAD_PRIVATE - your wireguard server address in VPN network.
NS_MULLVAD_PUBLIC - DNS server used by your wireguard server. If you have none then you can set it to public dns like 9.9.9.9 or 8.8.8.8.
The problem persists: I set $NS_MULLVAD_PRIVATE to the local IP-address of my VPN server and I set $NS_MULLVAD_PUBLIC to the global address of my VPN server (my VPN server handles DNS requests, too, to avoid leaking my IP-address via DNS). Even setting $NS_MULLVAD_PUBLIC to 8.8.8.8 did not resolve the DNS-issues.
Maybe the issue is not with my VPN setup, but with the forwarding of DNS requests from my AppVM to my ProxyVM, because in my ProxyVM everything works as expected. In my AppVM I still cannot perform DNS requests.
You need to have default DNS servers 10.139.1.1/10.139.1.2 in AppVM for these rulse to work.
You can check the packet counters in your ProxyVM to see if the DNS requests from your AppVM are redirected by iptables: sudo iptables -t nat -L PR-QBS -n -v
Also on second look NS_MULLVAD_PRIVATE doesn’t seem to be used so you can just remove it from script.
You don’t have the needed DNS rules.
Did you create /rw/config/qubes-ip-change-hook and made it executable sudo chmod +x /rw/config/qubes-ip-change-hook like the guide says? QubesOS R4: Wireguard VPN
You can run it manually: sudo /rw/config/qubes-ip-change-hook
And check if it’ll apply the rules: sudo iptables -t nat -L PR-QBS -n -v
The hook is executable (-rwxr-xr-x 1 root root).
When executing the hook manually, all entries in your above snippet in the destination column change to my VPN server’s local IP-address.
In the column right to the destination column, the IP-addresses changed to my VPN server’s public address (eg. $NS_MULLVAD_PUBLIC).
After executing the hook manually, the DNS problem persists.
Edit: Putting sudo /rw/config/ip-change-hook into my /rw/config/rc.local after the wg-quick command seems to make these changes persistent. DNS problems persist however.
I changed the script and replaced x.x.x.x with my VPN server’s local IP address which made it work after explicitly executing the qubes-ip-change-hook.
Putting sudo /rw/config/qubes-ip-change-hook after wg-quick up myInterface in /rw/config/rc.local fixes the issues.
I can use DNS in my AppVM!!!
Thanks a lot mate!
But isn’t the qubes-ip-change-hook supposed to execute on its own (eg. without putting it into /rw/config/rc.local)?
Yes, you’ll need to run DNS over TLS resolver like stubby in sys-vpn that’ll listen on 127.0.0.1:53 for DNS queries and you’ll need to redirect the DNS queries from connected to sys-vpn qubes to 127.0.0.1:53 with iptables in sys-vpn: