
My UniFi USG router offers no VPN service suitable for the latest Android versions that a phone could use (for example a Samsung S25+ with One UI 9). So I put a WireGuard server directly on my home NAS running Debian 12 and wrote my own Webmin module to manage it, because I was tired of typing console commands. Forwarding one UDP port on the router is enough, and a phone or laptop can connect securely to the home network from anywhere, with no third-party server and with easy VPN configuration using a generated QR code for each new device.
To make management easy, I wrote two things: a pair of shell scripts and a Webmin module. Webmin has no official WireGuard module, so I wrote my own in Perl, with a multilingual interface. In the browser, in the Webmin environment, you can set up the server, add a device, show its QR code and edit all the necessary parameters. The scripts and the module use the same wg0.conf file, so they can be used interchangeably. Everything is free under the MIT license on GitHub. My setup: a NAS with Debian 12, Webmin 2.670, a UniFi USG router with UI Network 9.2.87 and a Samsung Galaxy S25+ phone.
The solution suits any network where the router cannot provide a VPN connection and a Linux device, such as a NAS, a Raspberry Pi or similar, runs in the LAN behind it. It is verified on Debian 12, and package installation uses apt.
How it works

- The WireGuard app on the phone connects to the public IP address or DDNS name of the router.
- The router forwards your chosen UDP port (for example
51820) to the NAS. - The NAS is the WireGuard server. It terminates the tunnel and sends the traffic on to the LAN.
- LAN devices reply through the NAS, because the NAS replaces the source address with its own when forwarding (masquerade). No routing changes are needed on the router.
Only the home network (for example 192.168.1.0/24) and the tunnel 10.66.66.0/24 go through the VPN, these are listed in AllowedIPs. Other internet traffic goes directly from the phone (split tunnel). To send all traffic through the tunnel, change AllowedIPs to 0.0.0.0/0, ::/0.
Values used in this article (all of them can be changed, the LAN and the port are only examples):
| What | Value |
|---|---|
| Home network (LAN) | your network, for example 192.168.1.0/24 |
| Tunnel IPv4 | 10.66.66.0/24 |
| Tunnel IPv6 | fd42:42:42::/64 |
| NAS in the tunnel | 10.66.66.1, fd42:42:42::1 |
| Devices in the tunnel | 10.66.66.2, .3, … (and fd42:42:42::2, ::3, …) |
| Port | your chosen UDP port, for example 51820 |
What you need
- A NAS, a Raspberry Pi or another Linux device and root access.
- A router that can forward a port, and a real public IP address (not CGNAT, see step 1).
- A fixed LAN IP address for the NAS (a DHCP reservation or a static address), otherwise the port forward stops working when the address changes.
- Webmin on the NAS if you want to use the module. Without it, the scripts are enough (see Without Webmin).
- The WireGuard app on the phone (Google Play) or computer (wireguard.com/install).
Step 1: Check the public IP address
- Compare the WAN IP address of the router (in UniFi: Devices → USG → WAN) with the address shown by ifconfig.me.
- If they differ, your provider uses CGNAT and a port forward from the internet will not work.
- If your public IP address is dynamic, enable DDNS on the router (Settings → Services → Dynamic DNS) and use the DDNS name from now on.
Step 2: Install the Webmin module
- Download
wireguard.wbm.gzfrom the Releases page on GitHub or from the download section. - In Webmin, open Webmin Configuration → Webmin Modules → From uploaded file, choose
wireguard.wbm.gzand click Install Module. - The module appears in the Networking category as WireGuard VPN. If you do not see it, reload the page or use Refresh Modules.

The public address, the port, my LAN addresses and the keys are covered in the screenshots.
Step 3: Set up the server
If there is no server yet, the main page of the module offers the Set up server button.

- Fill in the WAN: the public IP address or DDNS name of the router.
- Enter your chosen UDP port (for example
51820) and check the network card to the LAN (the module detects it) and the server tunnel addresses. - Turn on Install missing packages and leave Configure firewall on.
- Click Set up server.
The module installs the wireguard, qrencode and iptables packages, generates the server key, writes wg0.conf with the firewall rules, enables IP forwarding and starts the wg-quick@wg0 service, which also starts after a reboot. If ufw is active, it allows the port there. At the end it lists the checks step by step, marked [OK] or with an error.
Warning: if a server already exists, setting it up again discards all clients, and the module asks you to confirm first. Back up /etc/wireguard before setting up an existing server again.
Step 4: Forward the port on the router
The module does not configure the router, this part is up to you. In the UniFi controller, open Settings → Routing & Firewall → Port Forwarding → Create New Port Forward Rule:
| Field | Value |
|---|---|
| Name | wireguard |
| From | Anywhere (WAN) |
| Port | your chosen UDP port (for example 51820) |
| Forward IP | LAN IP address of the NAS (for example 192.168.1.10) |
| Forward Port | the same port |
| Protocol | UDP |
Step 5: Add a device
The module detects the home network and the DNS server for devices on its own: the LAN is the subnet of the NAS network card and the DNS is its default gateway (the value auto). If you want other values, open the gear icon on the main page of the module (Module Config) before you add a device and change LAN routed through the tunnel and DNS server for clients.
The main page of the module shows the public address (WAN), the list of devices and a form for adding a new one. The picture shows my Samsung with the time of the last connection (handshake) and the data transferred.

- In the Add client section, enter the device name (letters, digits,
_,-) and the last number of the IP address. The module fills in the first free one. - Click Create client. The module generates the keys and the PSK and adds the device to
wg0.conf. It loads the change withwg syncconf, so the other devices stay connected. - Phone: in the WireGuard app tap + → Scan from QR code, scan the code and name the tunnel.
- Windows: the app cannot scan a QR code. Click Download configuration file and use Add Tunnel → Import tunnel(s) from file in the app.
- Close the page. The private key of the device is not stored anywhere, the server only has the public key. If you lose it, use Regenerate keys.

The QR code in the picture is only a sample with invalid keys and example addresses, you cannot connect with it. The keys and LAN addresses in the text are covered. A real QR code contains the private key of the device, so do not show it to anyone.
Step 6: Test the connection
- Turn off Wi-Fi on the phone and test on mobile data.
- Switch the tunnel on in the WireGuard app.
- Open the address of a LAN device in the browser (for example
http://192.168.1.20). - The client list in the module should show a recent last handshake and non-zero transferred data. The same is shown by this command on the NAS:
sudo wg show
Managing the server in the module
The main page shows the tunnel state, addresses, port and server public key. Buttons start, stop and restart the tunnel and enable start at boot.

Edit server settings changes the port, the tunnel addresses, the network card and the server key. Before saving, the module always creates a backup wg0.conf.bak.<date-time> and shows the list of changes. After changing the port, the addresses or the key, every device must be regenerated, and after changing the port the forward on the router must be updated too.

Installation shows whether the packages are installed, whether the kernel supports WireGuard, whether a configuration exists and whether the tunnel is running. One button installs the missing packages.

The same page offers uninstall with cleanup. It can create a backup first, and if the backup fails, nothing is deleted. It overwrites private keys (shred) before deleting them and removes only its own files. To confirm, you type the interface name wg0.

Without Webmin: the scripts
Two scripts in the scripts/ folder of the repository do the same job. Run them on the NAS as root:
sudo apt install wireguard iptables qrencode chmod +x scripts/*.sh sudo ./scripts/regen-wg.sh # server + first device, shows a QR code sudo ./scripts/add-wg-client.sh # every further device
Note that regen-wg.sh discards all existing clients, so add further devices only with add-wg-client.sh. The QR code is printed in the terminal and the files with the key are securely deleted at the end. The full procedure, including a manual configuration, is in docs/setup.en.md.
Using it on the phone
- Quick switch: add the WireGuard tile to the quick panel. One tap turns the last used tunnel on or off.
- Switch the tunnel off on home Wi-Fi. With the tunnel on, LAN traffic goes through it, and if the router cannot do hairpin NAT (connecting to its own public IP address from inside), the connection fails and the LAN is not reachable.
- Always-on VPN: Android can do this, but do not turn on Block connections without VPN, otherwise normal internet outside the tunnel stops working.
- Android allows only one VPN app at a time.
Troubleshooting
| Problem | Cause and solution |
|---|---|
| No handshake | Check the port forward (your chosen UDP port to the right NAS IP address), the public IP address or DDNS name, and CGNAT (step 1). Check that the NAS is listening with ss -ulnp | grep <port>. |
| Handshake works, but the LAN is not reachable | sysctl net.ipv4.ip_forward must return 1. PostUp must contain the right network card name and AllowedIPs on the phone must contain your LAN. |
| The tunnel is not running after a NAS reboot | sudo systemctl enable --now wg-quick@wg0, check the state with systemctl status wg-quick@wg0. |
| An error in the checks after the server setup | Look at journalctl -u wg-quick@wg0. Most often the port is taken or iptables is missing. |
| “Security Warning” when opening a module page | Webmin blocks direct links (referer check). Open the module by clicking through the menu Networking → WireGuard VPN. Do not change the referers_none setting because of this. |
| The module does not appear in the menu | Use Refresh Modules and check the user's rights in Webmin Users. |
| The QR code is not shown | Check that qrencode is installed, or use the configuration download link. |
| The public address has changed | Update the WAN on the main page of the module. Existing devices still have the old address in their configuration, so regenerate them. |
Security
- The module runs with the rights of Webmin, which means root. Give access only to trusted accounts through Webmin Users, and protect Webmin with a strong password and 2FA.
- Use Webmin only over HTTPS. The page shown after a device is created contains its private key, so close it after scanning.
- Values from the forms end up in
PostUpcommands that root runs. The module therefore validates them strictly and rejects, for example,;or$(...). - The backup created on uninstall contains private keys. It belongs to root, and when you no longer need it, delete it with
shred -u. - Never publish
wg0.conf, client.conffiles or keys.
Testing status
The main procedure in this article is verified live on Webmin 2.670 on Debian 12: installing the module, server setup, the server overview, the installation status, adding a device including its actual connection, and deleting a device. Other devices stayed connected during client changes.
Saving server settings, uninstall, package installation and ufw are verified only in a simulated environment with stand-in commands. I have not yet tried regenerating keys or the start and stop buttons on the live server. The scripts are syntax-checked (bash -n). If you plan to use them, try them on a test machine first.
Result
The phone reaches the home network through my own encrypted tunnel, which runs only on my NAS. One UDP port is forwarded on the router, and I add a new device in the browser: a name, a QR code and that is it. Normal internet traffic still goes directly from the phone.
Sources
GitHub – Webmin module and scripts
Detailed module documentation
WireGuard
WireGuard – installation and apps
Webmin