Skip to content

Support us

Authors: fire1ce | Created: 2022-06-25 | Last update: 2022-08-05

Wireguard VPN

WireGuard® is an extremely simple yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more useful than IPsec, while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general purpose VPN for running on embedded interfaces and super computers alike, fit for many different circumstances. Initially released for the Linux kernel, it is now cross-platform (Windows, macOS, BSD, iOS, Android) and widely deployable. It is currently under heavy development, but already it might be regarded as the most secure, easiest to use, and simplest VPN solution in the industry.

Github Repository: wireguard-vyatta-ubnt

A guide on installing and using the WireGuard kernel module and tools on Ubiquiti UnifiOS routers (UDM, UDR, and UXG).


  1. Download the latest release for UnifiOS. Use the correct link in the command below

    curl -Lfo UnifiOS-wireguard.tar.gz${RELEASE}/UnifiOS-${RELEASE}.tar.gz
  2. Extract the files to your data directory and run the setup script.

    • For the UDM/P or UXG-Pro, extract the files into /mnt/data/wireguard

      tar -C /mnt/data -xvf UnifiOS-wireguard.tar.gz
    • For the UDM-SE or UDR, extract the files into /data/wireguard

      tar -C /data -xvf UnifiOS-wireguard.tar.gz
  3. The setup script will load the wireguard module, and setup the symbolic links for the wireguard tools (wg-quick and wg). You can run dmesg to verify the kernel module was loaded. You should see something like the following:

    [13540.520120] wireguard: WireGuard 1.0.20210219 loaded. See for information.
    [13540.520126] wireguard: Copyright (C) 2015-2019 Jason A. Donenfeld <>. All Rights Reserved.

Now you should be able to create a wireguard interface. Please see usage below.


The wireguard module and tools included in this package have been tested on the following Ubiquiti devices:

  • Unifi Dream Machine (UDM) and UDM-Pro 0.5.x, 1.9.x, 1.10.x, 1.11.x.
  • UDM-SE and Unifi Dream Router (UDR) 2.2.x
  • UniFi Next-Gen Gateway (UXG-Pro) 1.11.x

Note that for the UDM, UDM Pro, and UXG-Pro, Ubiquiti includes the wireguard module in the official kernel since firmware 1.11.0-14, but doesn't include the WireGuard tools. The setup script in this package will try to load the built-in wireguard module if it exists first.


  1. Unload the wireguard module.

    rmmod wireguard
  2. Re-install wireguard by following the Installation instructions above to get the latest version.


  1. Delete the wireguard files from your data directory.

    rm -rf /mnt/data/wireguard
  2. Delete the wireguard tools and any boot scripts.

    rm /usr/bin/wg /usr/bin/wg-quick


Read the documentation on for general WireGuard concepts. Here is a simple example of a wireguard server configuration for UnifiOS.

  1. Create the server and client public/private key pairs by running the following. This will create the files privatekey_server, publickey_server and privatekey_client1, publickey_client1. These contain the public and private keys. Store these files somewhere safe.

    wg genkey | tee privatekey_server | wg pubkey > publickey_server
    wg genkey | tee privatekey_client1 | wg pubkey > publickey_client1
  2. On your UDM/UDR, create a wireguard config under /etc/wireguard named wg0.conf. Here is an example server config. Remember to use the correct server private key and the client public key.

    Address =
    PrivateKey = <server's privatekey>
    ListenPort = 51820
    PublicKey = <client's publickey>
    AllowedIPs =
  3. For your client, you will need a client config like the following example. Remember to use the correct client private key and the server public key.

Address =
PrivateKey = <client's privatekey>

PublicKey = <server's publickey>
Endpoint = <server's ip>:51820
AllowedIPs =
  • Adjust Address to change the IP of the client.
  • Adjust AllowedIPs to set what your client should route through the tunnel. Set to,::/0 to route all the client's Internet through the tunnel. See the WireGuard documentation for more information.
  • Note each different client requires their own private/public key pair, and the public key must be added to the server's WireGuard config as a separate Peer.
  1. To bring the tunnel up, run wg-quick up <config>. Verify the tunnel received a handshake by running wg.
wg-quick up /etc/wireguard/wg0.conf
  1. To bring down the tunnel, run wg-quick down <config>.
wg-quick down /etc/wireguard/wg0.conf
  1. In your UniFi Network settings, add a WAN_LOCAL (or Internet Local) firewall rule to ACCEPT traffic destined to UDP port 51820 (or your ListenPort if different). Opening this port in the firewall is needed so remote clients can access the WireGuard server.


The AllowedIPs parameter in the wireguard config allows you to specify which destination subnets to route through the tunnel.

If you want to route router-connected clients through the wireguard tunnel based on source subnet or source VLAN, you need to set up policy-based routing. Currently, there is no GUI support for policy-based routing in UnifiOS, but it can be set up in SSH by using ip route to create a custom routing table, and ip rule to select which clients to route through the custom table.

For a script that makes it easy to set-up policy-based routing rules on UnifiOS, see the split-vpn project.


Prebuilt binaries are available under releases.

The binaries are statically linked against musl libc to mitigate potential issues with UnifiOS' glibc.

Persistence on Reboot

The setup script must be run every time the system is rebooted to link the wireguard tools and load the module. This can be accomplished with a boot script.

  • For the UDM or UDM Pro, install UDM Utilities on-boot-script by following the instructions here, then create a boot script under /mnt/data/on_boot.d/ and fill it with the following contents. Remember to run chmod +x /mnt/data/on_boot.d/ afterwards.

    Click here to see the boot script.

  • For the UDM-SE or UDR, create a systemd boot service to run the setup script at boot. Create a service file under /etc/systemd/system/setup-wireguard.service and fill it with the following contents. After creating the service, run systemctl daemon-reload && systemctl enable setup-wireguard to enable the service on boot.

    Click here to see the boot service.

    Description=Run wireguard setup script
    ExecStart=sh -c 'WGDIR="$(find /mnt/data/wireguard /data/wireguard -maxdepth 1 -type d -name "wireguard" 2>/dev/null | head -n1)"; "$WGDIR/"'
  • Note this only adds the setup script to start at boot. If you also want to bring your wireguard interface up at boot, you will need to add another boot script with your wg-quick up command.


Setup script returns error "Unsupported Kernel version XXX" * The wireguard package does not contain a wireguard module built for your firmware or kernel version, nor is there a built-in module in your kernel. Please open an issue and report your version so we can try to update the module.
wg-quick up returns error "unable to initialize table 'raw'" * Your kernel does not have the iptables raw module. The raw module is only required if you use `` or `::/0` in your wireguard config's AllowedIPs. A workaround is to instead set AllowedIPs to `,` for IPv4 or `::/1,8000::/1` for IPv6. These subnets cover the same range but do not invoke wg-quick's use of the iptables raw module.


Original work to compile WireGuard on UnifiOS by @tusc (wireguard-kmod).

"WireGuard" and the "WireGuard" logo are registered trademarks of Jason A. Donenfeld.

The built-in gateway DNS does not reply to requests from the WireGuard tunnel

  • The built-in dnsmasq on UnifiOS is configured to only listen for requests from specific interfaces. The wireguard interface name (e.g.: wg0) needs to be added to the dnsmasq config so it can respond to requests from the tunnel. You can run the following to add wg0 to the dnsmasq interface list:
echo "interface=wg0" > /run/dnsmasq.conf.d/custom_listen.conf
killall -9 dnsmasq
  • You can also those commands to PostUp in your wireguard config's Interface section to automatically run them when the tunnel comes up, e.g.:
 PostUp = echo "interface=%i" > /run/dnsmasq.conf.d/custom_listen.conf; killall -9 dnsmasq
 PreDown = rm -f /run/dnsmasq.conf.d/custom_listen.conf; killall -9 dnsmasq