VPS/VDS Hosting

Install WireGuard VPN on a VPS

Complete guide to install and configure WireGuard VPN on your VPS server using a simplified script. Create your own private VPN network.

intermediate~4 min read

This guide will teach you how to install WireGuard VPN on your VPS server using a simplified installation script. WireGuard is a modern, fast, and secure VPN that will allow you to create your own private virtual network.

📋 Prerequisites

  • A VPS server with root or sudo access
  • An active SSH connection
  • Ubuntu/Debian (the script works with these distributions)
  • UFW installed and configured (see the tutorial Install UFW)

📥 WireGuard Installation

Download the installation script

We will use the automatic installation script that greatly simplifies the configuration:

Bash
# Download the installation script curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh # Make the script executable chmod +x wireguard-install.sh

Run the installation script

Bash
sudo ./wireguard-install.sh

Interactive configuration

The script will ask you a few questions. Here are the recommended answers:

  1. Public address: IPv4 or IPv6 address detected automatically; press Enter to keep it
  2. Public interface: detected from the default route (often eth0); press Enter to keep it
  3. WireGuard interface name: wg0 (default)
  4. Server WireGuard IPv4: 10.66.66.1 (default), i.e. the 10.66.66.0/24 subnet
  5. Server WireGuard IPv6: fd42:42:42::1 (default)
  6. Server WireGuard port: a random port between 49152 and 65535 is proposed; keep it or enter your own (1-65535), and note it down: you will need it for the firewall
  7. DNS resolvers: 1.1.1.1 then 1.0.0.1 (Cloudflare, default)
  8. Allowed IPs: 0.0.0.0/0,::/0 (default): all of the client's traffic goes through the VPN
  9. Client name: name of your first client: letters, digits, _ or -, 15 characters maximum (e.g., my-pc, laptop, smartphone)
  10. Client WireGuard IPv4 and IPv6: proposed automatically (10.66.66.2 and fd42:42:42::2 for the first client); press Enter

The script will:

  • Install WireGuard automatically
  • Generate private and public keys
  • Configure the server
  • Create your first client

📱 Client Configuration

Retrieve the configuration file

After installation, the script generates a client configuration file. To retrieve it:

Bash
# Display the configuration file content sudo cat ~/wg0-client-[client-name].conf # Example: if you named your client "my-pc" sudo cat ~/wg0-client-my-pc.conf # Or download it to your own computer (run this on your computer) scp user@your-vps-ip:wg0-client-my-pc.conf .

The file is named wg0-client-<name>.conf (WireGuard interface name, then client name) and is written in the home directory of the user who ran the script: /home/<user> if you used sudo from a regular account, /root if you are root. The script prints its exact path at the end, and also displays the configuration as a QR code in the terminal (if qrencode is installed), ready to scan from the mobile app.

Configuration file example

The file will look like this:

[Interface]
PrivateKey = [your-private-key]
Address = 10.66.66.2/32,fd42:42:42::2/128
DNS = 1.1.1.1,1.0.0.1

[Peer]
PublicKey = [server-public-key]
PresharedKey = [preshared-key]
Endpoint = [your-vps-ip]:<PORT>
AllowedIPs = 0.0.0.0/0,::/0

Install the client on your device

On Windows

  1. Download WireGuard from wireguard.com
  2. Install the application
  3. Open WireGuard and click "Add Tunnel" > "Add empty tunnel"
  4. Copy-paste the content of the .conf file
  5. Save and activate the connection

On macOS

  1. Download WireGuard from the App Store or wireguard.com
  2. Install the application
  3. Open WireGuard and click "Add Tunnel" > "Create from file" or "Create from clipboard"
  4. Import your configuration file
  5. Activate the connection

On Linux (Ubuntu/Debian)

Bash
# Install WireGuard sudo apt update sudo apt install wireguard -y # Copy the configuration file sudo cp wg0-client-my-pc.conf /etc/wireguard/wg0.conf # Enable WireGuard sudo wg-quick up wg0 # Enable on boot sudo systemctl enable wg-quick@wg0

On Android/iOS

  1. Install the WireGuard app from Google Play Store or App Store
  2. Open the app and click the "+" button
  3. Choose "Create from file" or "Create from QR code"
  4. Import your configuration file
  5. Activate the connection

🔐 Add a new client

To add a new client later (e.g., for another device):

Bash
sudo ./wireguard-install.sh

When the script asks what you want to do, choose option 1) Add a new user.

Enter a name for the new client, and the script will automatically generate a new configuration file named wg0-client-<name>.conf in the same home directory (e.g., ~/wg0-client-laptop.conf)

The same menu also offers 2) List all users, 3) Revoke existing user and 4) Uninstall WireGuard (which removes the whole /etc/wireguard directory).

🚀 Useful WireGuard commands

Service management

Bash
# Start WireGuard sudo systemctl start wg-quick@wg0 # Stop WireGuard sudo systemctl stop wg-quick@wg0 # Restart WireGuard sudo systemctl restart wg-quick@wg0 # Service status sudo systemctl status wg-quick@wg0 # Enable on boot sudo systemctl enable wg-quick@wg0 # Disable on boot sudo systemctl disable wg-quick@wg0

Connection information

Bash
# View WireGuard information sudo wg show # View transfer statistics sudo wg show wg0 transfer # View current configuration sudo wg show wg0 dump

Logs

Bash
# View logs in real-time sudo journalctl -u wg-quick@wg0 -f # View last entries sudo journalctl -u wg-quick@wg0 -n 50

🔐 Allow WireGuard in UFW

Important: Don't forget to allow the WireGuard port in UFW after installation, otherwise your VPN won't work.

After installing WireGuard, allow the port in UFW:

Bash
# Read the port chosen during the installation (random by default) sudo wg show wg0 listen-port # or: sudo grep ListenPort /etc/wireguard/wg0.conf # Allow the WireGuard port (replace <PORT> with the value found above) sudo ufw allow <PORT>/udp # Reload UFW sudo ufw reload # Verify that the rule is active sudo ufw status | grep <PORT>

✅ Verification

Verify that WireGuard is working

Bash
# Check service status sudo systemctl status wg-quick@wg0 # Check active connections sudo wg show # Verify that the port is open sudo ss -ulnp | grep <PORT>

Test from your client

Once connected from your client:

  1. Check your public IP: curl ifconfig.me (should display your VPS IP)
  2. Test connectivity: ping 8.8.8.8
  3. Verify that you are connected to the VPN from your network interface

🆘 Troubleshooting

WireGuard won't start

Bash
# Check logs sudo journalctl -u wg-quick@wg0 -n 50 # Check configuration sudo wg-quick down wg0 sudo wg-quick up wg0 # Verify that the port is available sudo ss -ulnp | grep <PORT>

Cannot connect from my client

  1. Check that the port is open in UFW:

    Bash
    sudo ufw status | grep <PORT>
  2. Check that the server is listening on the port:

    Bash
    sudo ss -ulnp | grep <PORT>
  3. Check your client configuration: Make sure your server IP in Endpoint is correct

  4. Check server-side logs:

    Bash
    sudo journalctl -u wg-quick@wg0 -f

Installation script fails

If the installation script encounters errors:

  1. Verify that you have root or sudo rights
  2. Check your internet connection
  3. Make sure your system is up to date: sudo apt update && sudo apt upgrade -y
  4. Try downloading the script again:
    Bash
    rm wireguard-install.sh curl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh chmod +x wireguard-install.sh

📚 Additional resources

❓ Frequently Asked Questions

Q: Can I use multiple clients simultaneously?
A: Yes, WireGuard supports multiple clients connected at the same time. Simply add a new client with the script.

Q: What is WireGuard's speed?
A: WireGuard is one of the fastest VPNs available, with performance close to native speed.

Q: Is WireGuard secure?
A: Yes, WireGuard uses modern encryption and has been audited for security.

Q: Can I change the WireGuard port after installation?
A: Yes, but you'll need to modify the configuration manually. It's simpler to reinstall with the script if necessary.


Good configuration! 🚀

Latest tutorials

Stay up to date with the latest offers, discounts and special promotions.

View promotions

We use cookies

We use cookies to measure and improve our site. Privacy policy