
/usr/local/sbin/vpn-killswitch and make it executable:
chmod +x /usr/local/sbin/vpn-killswitch
/etc/NetworkManager/dispatcher.d/
PostUp = /path/to/vpn-killswitch on %i PostDown = /path/to/vpn-killswitch off %iWorks with any interface name, such as
wg0 or cs-poland.
/path/to/vpn-killswitch on /path/to/vpn-killswitch on cs-poland /path/to/vpn-killswitch on tun0 /path/to/vpn-killswitch off /path/to/vpn-killswitch statusThe interface name is optional if the script can clearly auto-detect the active tunnel.
VPN_HOST or VPN_ENDPOINT_V4 / VPN_ENDPOINT_V6 for standalone to work.
script-security 2 up /path/to/vpn-killswitch down /path/to/vpn-killswitchYou can use this when starting OpenVPN from the console, or by putting those lines directly into your
.ovpn config file so the kill switch is handled automatically.
BACKEND="auto" — automatically use nftables if available, otherwise iptablesMODE="system" or MODE="user" — apply the kill switch system-wide, or only to one specific user accountKS_USER="justme" — the username to protect when using MODE="user"ALLOW_LAN=1 or ALLOW_LAN=0 — whether local network access is allowed outside the tunnelALLOW_LAN=1 to allow access to directly connected LAN devices such as printers, NAS boxes, and routers.
ALLOW_LAN=0 blocks LAN access too, which gives stricter isolation and helps protect against TunnelCrack-style attacks and similar tricks that rely on traffic escaping through local or non-tunneled routes.
ALLOW_LAN=1 is the easier choice. Users who want the strictest possible behavior should change it to 0.
DNS_V4="10.31.33.7"DNS_V6="2001:db8::7"
DNS_V4="10.31.33.8"DNS_V6="2001:db8::8"