Installing and configuring WireGuard VPN on Ubuntu 22.04 and integrating AdGuard for enhanced privacy and security.

Installing and Configuring WireGuard VPN on Ubuntu 22.04

Prerequisites:

  • A fresh Ubuntu 22.04 system.
  • Access to a terminal with sudo privileges.

Step 1: Install WireGuard

  1. Open a terminal window.
  2. Update the package index and install WireGuard:
sudo apt update
sudo apt install wireguard

Step 2: Generate Public and Private Keys

  1. Generate the public and private keys for the server:
umask 077
wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

Step 3: Create WireGuard Configuration File

  1. Create a new configuration file:
sudo nano /etc/wireguard/wg0.conf
  • Populate the file with the following configuration (replace <<SERVER_PRIVATE_KEY>> and <<CLIENT_PUBLIC_KEY>> with the generated keys):
[Interface]
Address = 10.0.0.1/24
PrivateKey = <<SERVER_PRIVATE_KEY>>
ListenPort = 51820

[Peer]
PublicKey = <<CLIENT_PUBLIC_KEY>>
AllowedIPs = 10.0.0.2/32

Step 4: Start and Enable WireGuard Service

  1. Start the WireGuard service:
sudo systemctl start wg-quick@wg0
  • Enable the service to start on boot:
sudo systemctl enable wg-quick@wg0

Step 5: Configure Client

  1. Install WireGuard on the client machine.
  2. Generate keys on the client:
umask 077
wg genkey | tee privatekey | wg pubkey | tee publickey
  1. Copy the public key to the server and vice versa.

Step 6: Connect to the VPN

  1. On the client, create a configuration file similar to the server’s wg0.conf.
  2. Start the WireGuard service on the client.

Integrating AdGuard with WireGuard VPN

Step 1: Install AdGuard

(See my other Tutorial)

Step 2: Configure AdGuard

  1. Open AdGuard settings.
  2. Navigate to the „Filters“ section.
  3. Enable filters for ads, trackers, malware, etc., to enhance privacy and security.

Step 3: Integrate with WireGuard

  1. In the WireGuard server configuration (wg0.conf), set AdGuard’s DNS as the DNS server:
[Interface]
Address = 10.0.0.1/24
PrivateKey = <<SERVER_PRIVATE_KEY>>
ListenPort = 51820
DNS = 10.0.0.1

[Peer]
PublicKey = <<CLIENT_PUBLIC_KEY>>
AllowedIPs = 10.0.0.2/32
  • Restart the WireGuard service on the server:
sudo systemctl restart wg-quick@wg0

Now, your WireGuard VPN is set up and integrated with AdGuard for enhanced privacy and security on your Ubuntu 22.04 system.