
Build Your Own VPN: A Step-by-Step Guide to Installing WireGuard with a Web UI on Ubuntu
In an age of increasing concern over digital privacy and data security, a Virtual Private Network (VPN) has become an essential tool. While commercial VPN services are popular, setting up your own VPN server offers unparalleled control, privacy, and performance. WireGuard is a modern, incredibly fast, and secure VPN protocol that has become the gold standard.
However, managing WireGuard through the command line can be intimidating. This is where WireGuard-UI comes in—a clean, web-based interface that simplifies server and client management.
This guide will walk you through the complete process of setting up a secure WireGuard VPN server managed by a user-friendly web UI on an Ubuntu system.
What You’ll Need Before You Begin
To get started, you will need the following:
- An Ubuntu server (version 20.04 or newer is recommended). This can be a cloud instance or a physical machine.
- Root or sudo access to the server.
- The public IP address of your server.
- Basic familiarity with the Linux command line.
Step 1: Prepare Your System and Install WireGuard
First, it’s crucial to ensure your server’s software packages are up to date. This helps prevent security vulnerabilities and ensures compatibility.
Open your terminal and run the following commands:
sudo apt update
sudo apt upgrade -y
Once the system is updated, you can install the core WireGuard package. It’s available directly from Ubuntu’s default repositories.
sudo apt install wireguard -y
This simple command installs all the necessary tools and kernel modules to run a WireGuard server.
Step 2: Install the WireGuard-UI Management Interface
WireGuard-UI is not available in the standard Ubuntu repositories, so we will download the latest release directly from its official source.
First, download the latest binary. Be sure to check the project’s GitHub page for the most recent version and adjust the URL if necessary. We will download it for the amd64 architecture, which is standard for most servers.
wget https://github.com/ngoduykhanh/wireguard-ui/releases/latest/download/wireguard-ui-amd64.tar.gz
Next, extract the downloaded archive:
tar -xvzf wireguard-ui-amd64.tar.gz
Finally, move the extracted binary into a system-wide accessible directory like /usr/local/bin and give it the proper permissions. This makes it easy to run from anywhere on the system.
sudo mv wireguard-ui /usr/local/bin/
sudo chmod +x /usr/local/bin/wireguard-ui
Step 3: Create a Systemd Service to Run WireGuard-UI Automatically
To ensure the web interface runs reliably and starts automatically whenever the server boots, we will create a systemd service file.
Create a new service file using a text editor like nano:
sudo nano /etc/systemd/system/wireguard-ui.service
Copy and paste the following configuration into the file. This tells the system how to start, stop, and manage the WireGuard-UI process.
[Unit]
Description=WireGuard-UI
After=network.target
[Service]
User=root
Type=simple
WorkingDirectory=/etc/wireguard
ExecStart=/usr/local/bin/wireguard-ui -s
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
Save the file and exit the editor (in nano, press CTRL+X, then Y, then Enter).
Now, enable and start the new service:
sudo systemctl enable wireguard-ui.service
sudo systemctl start wireguard-ui.service
You can check its status to ensure it’s running correctly:
sudo systemctl status wireguard-ui.service
You should see an “active (running)” status in the output.
Step 4: Configure Your Firewall for Secure Access
A firewall is essential for securing your server. We will use ufw (Uncomplicated Firewall), the default firewall tool for Ubuntu.
First and most importantly, allow SSH access. If you fail to do this, you could lock yourself out of your server.
sudo ufw allow ssh
Next, allow traffic on the port used by the WireGuard-UI web interface, which is port 5000/tcp by default.
sudo ufw allow 5000/tcp
Finally, allow traffic for the WireGuard VPN itself. The standard port is 51820/udp. Note that WireGuard uses UDP, not TCP.
sudo ufw allow 51820/udp
Now, enable the firewall:
sudo ufw enable
Type y and press Enter to confirm. Your firewall is now active and configured.
Step 5: Initial Setup via the Web Interface
With the backend running and the firewall configured, you can now access the web UI.
Open your web browser and navigate to: http://your_server_ip:5000
You will be prompted to create a new username and password for the web interface. Choose a strong, unique password to secure your VPN management panel.
After logging in, you’ll see a clean dashboard. The first step is to configure the server settings.
- Click on “WireGuard Server Settings” in the UI.
- The Server IP Address, Listen Port (51820), and PostUp/PostDown Scripts are usually pre-filled with sensible defaults. The scripts are crucial as they configure the network address translation (NAT) that allows your VPN clients to access the internet through the server.
- Click “Save” and then “Apply Config” at the top of the page to generate the server’s configuration and private keys.
Step 6: Creating and Connecting Your First VPN Client
Now for the final step: creating a configuration for your devices (like a laptop or smartphone).
- In the web UI, click on “New Client”.
- Give the client a descriptive name (e.g.,
MyLaptoporAndroidPhone). - Click “Submit”.
The system will automatically generate all the necessary cryptographic keys and configuration settings for this client. You will now see two easy ways to connect your device:
- QR Code: This is the easiest method for mobile devices. Simply install the official WireGuard app on your phone, choose to create a tunnel from a QR code, and scan the code shown in the web UI.
- Download Config File: For desktops (Windows, macOS, Linux), click the “Download” button. This will save a
.conffile. Open your desktop WireGuard client and import this configuration file to set up the tunnel.
Once you import the configuration and activate the tunnel on your device, all your internet traffic will be securely routed through your private Ubuntu server.
Final Thoughts
You have successfully deployed a personal, high-speed VPN server using the power of WireGuard and the convenience of a graphical web interface. By hosting your own VPN, you take a significant step toward taking full control of your internet traffic and digital privacy. This setup not only secures your data on public Wi-Fi but also provides a stable, private gateway to the internet that you manage entirely.
Source: https://www.tecmint.com/setup-wireguard-vpn-server-web-ui-ubuntu/


