This guide is for creating Nym VPN template that can be used to create app qubes based on it and run Nym VPN app in the app qubes.
Create Nym VPN template qube
Install debian-13-minimal template using “Qubes Template Manager” tool if you don’t have it already.
Clone debian-13-minimal and name it d13m-nym.
Configure Nym VPN template
Start d13m-nym and open its root terminal using this command in dom0 terminal:
qvm-run -u root d13m-nym xterm &
Run the following commands in d13m-nym root terminal:
You can paste the clipboard content into the xterm using Shift+Insert shortcut or by clicking on the middle mouse button inside the xterm window.
apt update
apt dist-upgrade -y
apt install -y qubes-core-agent-networking systemd-resolved mate-polkit
python3 -c $'import urllib.request\nurllib.request.install_opener(urllib.request.build_opener(urllib.request.ProxyHandler({"https": "127.0.0.1:8082"})))\nurllib.request.urlretrieve("https://apt-ppa.nym.com/pool/main/n/nym-repo-setup/nym-repo-setup_2.0.1_all.deb", "/tmp/nym-repo-setup.deb")'
apt install -y /tmp/nym-repo-setup.deb
apt install -y nym-vpn-app
systemctl stop nym-vpnd
mkdir -p /etc/systemd/system/nym-vpnd.service.d/
cat << 'EOF' | tee /etc/systemd/system/nym-vpnd.service.d/override.conf > /dev/null
[Unit]
ConditionPathExists=!/var/run/qubes/this-is-templatevm
EOF
mkdir -p /etc/qubes-bind-dirs.d
cat << 'EOF' | tee /etc/qubes-bind-dirs.d/50_nym.conf > /dev/null
binds+=( '/etc/nym' )
binds+=( '/var/lib/nym-vpnd' )
EOF
cat << 'EOF' | tee /etc/systemd/system/dnat-to-ns.service > /dev/null
[Unit]
Description=Run /usr/lib/qubes/qubes-setup-dnat-to-ns and /usr/sbin/nym-fix.sh
StartLimitIntervalSec=0
[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart systemd-resolved
ExecStart=/usr/lib/qubes/qubes-setup-dnat-to-ns
ExecStart=/usr/sbin/nym-fix.sh
EOF
cat << 'EOF' | tee /etc/systemd/system/dnat-to-ns.path > /dev/null
[Unit]
Description=Run /usr/lib/qubes/qubes-setup-dnat-to-ns when /etc/resolv.conf changes
[Path]
PathChanged=/etc/resolv.conf
Unit=dnat-to-ns.service
[Install]
WantedBy=multi-user.target
EOF
mkdir /etc/systemd/system/systemd-resolved.conf.d/
cat << 'EOF' | tee /etc/systemd/system/systemd-resolved.conf.d/override.conf > /dev/null
[Unit]
StartLimitIntervalSec=0
EOF
systemctl enable dnat-to-ns.path
mkdir -p /etc/qubes-bind-dirs.d
cat << 'EOF' | tee /usr/sbin/nym-fix.sh > /dev/null
#!/bin/bash
# Allow from vif to tun and DNS
if nft list table inet nym >/dev/null 2>&1; then
if ! nft list chain inet nym forward 2>/dev/null |
grep -qF 'iifname "vif*" oifname "tun*" accept'; then
nft insert rule inet nym forward iifname "vif*" oifname "tun*" accept
fi
if ! nft list chain inet nym input 2>/dev/null |
grep -qF 'iifname "vif*" meta l4proto {tcp, udp} th dport 5353 accept'; then
nft insert rule inet nym input iifname "vif*" meta l4proto {tcp, udp} th dport 5353 accept
fi
if ! nft list chain inet nym output 2>/dev/null |
grep -qF 'oifname "vif*" meta l4proto {tcp, udp} th sport 5353 accept'; then
nft insert rule inet nym output oifname "vif*" meta l4proto {tcp, udp} th sport 5353 accept
fi
fi
# Fix for MTU issue:
# https://github.com/nymtech/nym-vpn-client/issues/6465
ip link set tun0 mtu 1340
ip link set tun1 mtu 1280
ip route replace 10.1.0.1 dev tun0 table 333 mtu 1340
ip route replace default dev tun1 table 333 mtu 1280
EOF
chmod +x /usr/sbin/nym-fix.sh
cat << 'EOF' | tee /etc/systemd/system/custom-early-vm-config.service > /dev/null
[Unit]
Description=Run /usr/sbin/custom-early-vm-config.sh
ConditionPathExists=!/var/run/qubes/this-is-templatevm
Requiress=qubes-iptables.service
After=qubes-iptables.service
Before=network-pre.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/custom-early-vm-config.sh
[Install]
RequiredBy=network-pre.target
EOF
systemctl enable custom-early-vm-config.service
cat << 'EOF' | tee /usr/sbin/custom-early-vm-config.sh > /dev/null
#!/bin/sh
nft add chain ip qubes nym-dnat-dns '{ type nat hook prerouting priority dstnat - 1; policy accept; }'
nft add rule ip qubes nym-dnat-dns iifname "vif*" meta l4proto {tcp, udp} th dport 53 redirect to :5353
nft add rule ip qubes custom-input iifname "vif*" meta l4proto {tcp, udp} th dport 5353 accept
nft add rule qubes custom-forward oifname eth0 counter drop
nft add rule ip6 qubes custom-forward oifname eth0 counter drop
nft add rule ip qubes custom-forward tcp flags syn / syn,rst tcp option maxseg size set rt mtu
EOF
chmod +x /usr/sbin/custom-early-vm-config.sh
mkdir -p /etc/systemd/resolved.conf.d
cat << 'EOF' | tee /etc/systemd/resolved.conf.d/listen.conf > /dev/null
[Resolve]
DNSStubListenerExtra=0.0.0.0:5353
EOF
Add Nym VPN App menu shortcut to the newly created qubes by default
To add the Nym VPN App menu shortcut to the newly created qubes you need to set default-menu-items feature for Nym VPN template.
Open dom0 terminal and run these commands to set the default App menu items for qubes based on this template:
qvm-features d13m-nym default-menu-items "NymVPN.desktop debian-xterm.desktop"
qvm-sync-appmenus d13m-nym
At this point the template is configured and ready to be used.
Now you can create a new app qube based on the d13m-nym template with “Provides network access to other qubes” enabled in the “Advanced Options” and start the NymVPN app in this qube from Qubes OS menu.