Wireguard VPN setup revisions

Go back to topic: Wireguard VPN setup

  1. v22 anchor; v22 full version
  2. v21 anchor; v21 full version
  3. v20 anchor; v20 full version
  4. v19 anchor; v19 full version
  5. v18 anchor; v18 full version
  6. v17 anchor; v17 full version
  7. v16 anchor; v16 full version
  8. v15 anchor; v15 full version
  9. v14 anchor; v14 full version
  10. v13 anchor; v13 full version
  11. v12 anchor; v12 full version
  12. v11 anchor; v11 full version
  13. v10 anchor; v10 full version
  14. v9 anchor; v9 full version
  15. v8 anchor; v8 full version
  16. add "provides network access to other qubes" v7 anchor; v7 full version
  17. v6 anchor; v6 full version
  18. v5 anchor; v5 full version
  19. v4 anchor; v4 full version
  20. v3 anchor; v3 full version
  21. v2 anchor; v2 full version

Revision #22

Edited on
2024-11-05
Edited by user
solene
Add the rules below in `/rw/config/qubes-firewall-user-script` in `sys-vpn`: Add the rules below in `/rw/config/qubes-firewall-user-script` in `sys-vpn`, make sure the qube service "qubes-firewall" is enabled in the qube settings:
These firewall rules will prevent (at the qube level) routing traffic of the NetVM child qubes through the sys-vpn NetVM. In other words, it blocks network traffic for qubes using sys-vpn as a NetVM if the VPN is not up/working. If sys-vpn qube is compromised, it is possible to remove that rule from the qube (hence the "qube level" rule) and leak the traffic, although if this happens, it is also possible to directly listen to the network traffic going through sys-vpn. A better killswitch solution is to use the qube firewall to block all traffic except the host:port destination required to establish the VPN. The firewall rules are applied on sys-vpn NetVM and can't be modified from sys-vpn itself. Although this is better, it still won't protect a compromised sys-vpn to listen to the traffic passing there (it's is actually impossible to protect).

Revision #21

Edited on
2024-09-23
Edited by user
user111
In the settings windown that popped up, go to the <kbd>Services</kbd>, select `network-manager` from the drop-down list and click <kbd>:heavy_plus_sign: add</kbd>. Then save the settings by clicking <kbd>OK</kbd>. In the settings window that popped up, go to the <kbd>Services</kbd>, select `network-manager` from the drop-down list and click <kbd>:heavy_plus_sign: add</kbd>. Then save the settings by clicking <kbd>OK</kbd>.
Go your VPN provider and either get a download a configuration file **for wireguard** (e.g.: `vpn.conf`) Go your VPN provider and download a configuration file **for wireguard** (e.g.: `vpn.conf`)
> :information_source: This is essentially a **killswitch**. It is a fail-safe that ensures that if your VPN connection fails, it does let anything through. > :information_source: This let pass DNS requests to internal Qubes OS DNS servers and also ICMP, see the next section if you need to block everything Open the configuration file in a text editor and take note of the IP address in right next to `Endpoint`. If the line looks like the following, then you take note of the IP address as `1.2.3.4`. > :information_source: This is essentially a **killswitch**. It is a fail-safe that ensures that if your VPN connection fails, it does *NOT* let anything through. > :information_source: This lets pass DNS requests to internal Qubes OS DNS servers and also ICMP, see the next section if you need to block everything Open the configuration file in a text editor and take note of the IP address right next to `Endpoint`. If the line looks like the following, then you take note of the IP address as `1.2.3.4`.

Revision #20

Edited on
2024-09-02
Edited by user
solene
> :information_source: Make sure `fedora-38` template is installed ([instructions](https://www.qubes-os.org/doc/templates/fedora/#installing)) > :information_source: Make sure `fedora-40` template is installed ([instructions](https://www.qubes-os.org/doc/templates/fedora/#installing)) (so far, this works with fedora 38/39/40 and certainly later versions)

Revision #19

Edited on
2024-08-17
Edited by user
solene
> :informations_ource: If you have multiple VPNs configured in the qube, you may want one to be picked randomly at boot to connect to. > :information_source: If you have multiple VPNs configured in the qube, you may want one to be picked randomly at boot to connect to.

Revision #18

Edited on
2024-03-09
Edited by user
solene
``` ``` ## Connect to a random VPN at qube start (optional) > :informations_ource: If you have multiple VPNs configured in the qube, you may want one to be picked randomly at boot to connect to. Make sure no VPN are configured for automatic connection at startup, there is a check box in the first tab of the VPN settings for that, it defaults to automatic connection. Add this code to `/rw/config/rc.local` ``` RANDOM_VPN=$(nmcli connection show | awk '/wireguard/ { print $1 }' | sort -R | head -n 1) nmcli connection up "$RANDOM_VPN" ```

Revision #17

Edited on
2024-03-01
Edited by user
solene
> :information_source: This let pass DNS requests to internal Qubes OS DNS servers and also ICMP, see the next section if you need to block everything
Hit <kbd>OK</KBD> to apply and click <kbd>OK</KBD> again to apply the settings Hit <kbd>OK</KBD> to apply and click <kbd>OK</KBD> again to apply the settings. # Block all traffic outside VPN using command line Qubes OS Firewall To configure killswitch + (DNS) leak protection + ICMP/ping blocking + protection in case of `sys-vpn` compromise, you can alternatively execute a three-liner in `dom0`, no `nft`/`iptables` needed: ``` qvm-firewall sys-vpn reset # (1) qvm-firewall sys-vpn add accept dsthost=1.2.3.4 # (2) qvm-firewall sys-vpn del --rule-no 0 # (3) ``` (1) resets firewall to one single rule `accept`ing everything (2) whitelists specific VPN gateway IP (3) removes rule (1), so there is just one whitelisted IP from (2) left Everything else is blocked safely outside `sys-vpn`.

Revision #16

Edited on
2024-02-09
Edited by user
solene
## What you'll need This guide assumes you are using a VPN service that has wireguard support. For example, ProtonVPN and Mullvad VPN do support it. But you can also follow this guide to add any other (even your own). ## What you'll need This guide assumes you are using a VPN service that has wireguard support, most of them do, but you can also add your own if you have a server. > :information_source: ProtonVPN has a free plan, it has limits but gives you a fully working VPN and they support WireGuard. This provider is recommended on [privacyguides.com for being privacy friendly](https://www.privacyguides.org/en/vpn/#proton-vpn) (no logs)

Revision #15

Edited on
2024-01-16
Edited by user
solene
nft add rule ip qubes forward tcp flags syn tcp option maxseg size set rt mtu nft add rule ip qubes custom-forward tcp flags syn / syn,rst tcp option maxseg size set rt mtu

Revision #14

Edited on
2024-01-12
Edited by user
solene
### Killswitch > :information_source: You may want to force all qubes traffic to go through the VPN and block non-VPN traffic.
> :information_source: You may want to force all qubes traffic to go through the VPN and block non-VPN traffic.
### Prevent DNS leak

Revision #13

Edited on
2023-12-24
Edited by user
solene
> :information_source: TODO explain why this is needed
> :information_source: You may want to force all qubes traffic to go through the VPN and block non-VPN traffic.
iptables -I FORWARD -o eth0 -j DROP iptables -I FORWARD -i eth0 -j DROP ip6tables -I FORWARD -o eth0 -j DROP ip6tables -I FORWARD -i eth0 -j DROP nft add rule qubes custom-forward oifname eth0 counter drop nft add rule ip6 qubes custom-forward oifname eth0 counter drop ``` > :information_source: You may also want to force using a defined DNS server (9.9.9.9 in the current example) and blocking all other DNS servers (this avoids dns leaks) ```
iptables -t nat -A PR-QBS -i vif+ -p udp --dport 53 -j DNAT --to "$DNS" iptables -t nat -A PR-QBS -i vif+ -p tcp --dport 53 -j DNAT --to "$DNS" nft add chain qubes nat { type nat hook prerouting priority dstnat\; } nft add rule qubes nat iifname == "vif*" tcp dport 53 dnat "$DNS" nft add rule qubes nat iifname == "vif*" udp dport 53 dnat "$DNS"

Revision #12

Edited on
2023-11-24
Edited by user
solene
After that you're done :partying_face: After that you're done :partying_face: ## Some websites aren't working This is certainly related to an MTU issue (the packet payload size), I got this issue only with `www.duckduckgo.com` for instance, so it could be very specific. A solution is to force the qubes using the VPN provider qube to use a lower MTU, this can be easily achieved using a firewall rule. Add this to `/rw/config/qubes-firewall-user-script`: ``` nft add rule ip qubes forward tcp flags syn tcp option maxseg size set rt mtu ```

Revision #11

Edited on
2023-11-14
Edited by user
deeplow
- **networking:** sys-firewall (⚠️ make sure it is NOT “(default) sys-firewall” but instead “sys-firewall)
And then <kbd>OK</kbd>. Then the qube settings window should show up (procced to the next step). And then <kbd>OK</kbd>. Then the qube settings window should show up (proceed to the next step).

Revision #10

Edited on
2023-07-29
Edited by user
solene
Maybe instead of show up will be available to be started from upper left Q / Services.

Revision #9

Edited on
2023-07-29
Edited by user
catacombs
And then <kbd>OK</kbd>. Then the qube settings window should show up (procced to the next step). And then <kbd>OK</kbd>. Then the qube settings window should show up (procced to the next step). Maybe instead of show up will be available to be started from upper left Q / Services.

Revision #8

Edited on
2023-07-06
Edited by user
deeplow
`````` <div data-theme-toc="true"> </div>

Revision #7

Edited on
2023-07-06
Edited by user
deeplow
Edit reason
add "provides network access to other qubes"
- ☑️ Launch settings after creation (and proceed to the next step) - ☑️ Launch settings after creation - <kbd>advanced</kbd> (tab) » Provides network access to other qubes And then <kbd>OK</kbd>. Then the qube settings window should show up (procced to the next step).

Revision #6

Edited on
2023-07-01
Edited by user
solene
VPN=9.9.9.9 # Prevent the qube to forward traffic outside of the VPN
iptables -t nat -A PR-QBS -i vif+ -p udp --dport 53 -j DNAT --to "$VPN" iptables -t nat -A PR-QBS -i vif+ -p tcp --dport 53 -j DNAT --to "$VPN" # Redirect all the DNS traffic to the preferred DNS server DNS=9.9.9.9 iptables -t nat -A PR-QBS -i vif+ -p udp --dport 53 -j DNAT --to "$DNS" iptables -t nat -A PR-QBS -i vif+ -p tcp --dport 53 -j DNAT --to "$DNS"

Revision #5

Edited on
2023-06-30
Edited by user
deeplow
Hi, Today I needed to use a WireGuard VPN. Good news, with fedora-38 the network manager supports Wireguard out of the box! The only thing required are extra firewall rules in the VPN qube, as explained in [the community documentation about VPN](https://github.com/Qubes-Community/Contents/blob/master/docs/configuration/vpn.md). Basically * Create a new Qube providing network * Enable service "network-manager" in it * Configure your VPN in the network manager * Use the Qube GUI to set the firewall to the VPN endpoint (this avoids leak) * Add the rules below * Assign a VM to the new Qube network to use the VPN To add in `/rw/config/qubes-firewall-user-script` Good news, with fedora-38 the network manager supports Wireguard out of the box! The only thing required are extra firewall rules in the VPN qube, as explained in [the community documentation about VPN](https://github.com/Qubes-Community/Contents/blob/master/docs/configuration/vpn.md). ## What you'll need This guide assumes you are using a VPN service that has wireguard support. For example, ProtonVPN and Mullvad VPN do support it. But you can also follow this guide to add any other (even your own). ## Create a new qube providing network > :information_source: Make sure `fedora-38` template is installed ([instructions](https://www.qubes-os.org/doc/templates/fedora/#installing)) Menu » Qubes Tools » Create Qubes VM: - **name**: sys-vpn (you pick yours) - **template:** `fedora-38` - **type:** `app qube` (or AppVM) - ☑️ Launch settings after creation (and proceed to the next step) ### Enable service “network-manager” in sys-vpn ![add|690x64, 75%](upload://2r8q1bkftaD2vQhv6yWrswwhllL.png) In the settings windown that popped up, go to the <kbd>Services</kbd>, select `network-manager` from the drop-down list and click <kbd>:heavy_plus_sign: add</kbd>. Then save the settings by clicking <kbd>OK</kbd>. ## Get your wireguard VPN configuration file Go your VPN provider and either get a download a configuration file **for wireguard** (e.g.: `vpn.conf`) On your VPN provider download the **wireguard** configuration for the server you want to connect to. Here are the download pages for some popular VPN services: [Mullvad](https://mullvad.net/en/account/wireguard-config), [ProtonVPN](account.proton.me/u/0/vpn/WireGuard) ## Use the Qube GUI to set the firewall to the VPN endpoint (this avoids leaks) > :information_source: This is essentially a **killswitch**. It is a fail-safe that ensures that if your VPN connection fails, it does let anything through. Open the configuration file in a text editor and take note of the IP address in right next to `Endpoint`. If the line looks like the following, then you take note of the IP address as `1.2.3.4`. > ``` > Endpoint = 1.2.3.4:5555 > ``` Open the qube settings for `sys-vpn` and navigate to the <kbd>Firewall rules</kbd> tab and set <kbd>:radio_button: Limit outgoing connections to</kbd>. ![firewall|690x133](upload://aOddjpqb61Fu1tF3A65GTywvrAk.png) Then click on <kbd> :heavy_plus_sign:</kbd> to add a new firewall and add your saved IP address(es) ![ip|375x172, 75%](upload://rrxJUKcOlwO37Psto41J4KQ1t1C.png) Hit <kbd>OK</KBD> to apply and click <kbd>OK</KBD> again to apply the settings ## Configure your VPN in the Network Manager On the qube on which you downloaded your wireguard configuration (e.g.: `vpn.conf`), open the file explorer where the file was saved. Then right-click a file and <kbd>Copy to another AppVM</kbd> and choose to `sys-vpn` as the target. Open your file manager in `sys-vpn` and find the `<NAME>.conf` file you just copied. It should in the directory `QubesIncoming`. Move it to your home directory. Open the `Terminal` application on your `sys-vpn` qube and run the following command (replacing `<NAME>.conf` with the correct name of the file): ```text nmcli connection import type wireguard file vpn.conf ``` If successful, you should see a notification about successful connection. If that doesn't happen, something may be wrong with your config file: ![oppp|412x210](upload://fQlyyzTGsMXgW1VuY0On9IWm5Ne.png) > :information_source: You should also see an icon with a padlock ![oppp(1)|22x22](upload://kRH6Pr00qtxThM8rkJIosNbq3EL.png) in the top-right corner of your screen (system tray). This indicates that your VPN connection is active. Without a padlock, means that it failed to connect. ## Assign a VM to the new Qube network to use the VPN Now that the VPN is configured, for each qube that you want to connect to the VPN, open its settings and set `networking` to `sys-vpn`. If you want this to be the default net qube, then you can set it in the Qubes Global Settings. After that you're done :partying_face: ## Hardening (optional) > :information_source: TODO explain why this is needed Add the rules below in `/rw/config/qubes-firewall-user-script` in `sys-vpn`:
``` I’d be glad to contribute to a solid documentation about VPN qubes, but I’m not sure to understand where to put the efforts.```

Revision #4

Edited on
2023-06-30
Edited by user
deeplow

Revision #3

Edited on
2023-06-05
Edited by user
solene
* Use the Qube GUI to set the firewall to the VPN endpoint (this avoids leak)
`````` I’d be glad to contribute to a solid documentation about VPN qubes, but I’m not sure to understand where to put the efforts.

Revision #2

Edited on
2023-06-05
Edited by user
solene
The only thing required are extra firewall rules in the VPN qube, as explained in [the community documentation about VPN](https://github.com/Qubes-Community/Contents/blob/master/docs/configuration/vpn.md). The only thing required are extra firewall rules in the VPN qube, as explained in [the community documentation about VPN](https://github.com/Qubes-Community/Contents/blob/master/docs/configuration/vpn.md). Basically * Create a new Qube providing network * Enable service "network-manager" in it * Configure your VPN in the network manager * Add the rules below * Assign a VM to the new Qube network to use the VPN