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
- Open a terminal window.
- Update the package index and install WireGuard:
sudo apt update
sudo apt install wireguard
Step 2: Generate Public and Private Keys
- 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
- 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
- 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
- Install WireGuard on the client machine.
- Generate keys on the client:
umask 077
wg genkey | tee privatekey | wg pubkey | tee publickey
- Copy the public key to the server and vice versa.
Step 6: Connect to the VPN
- On the client, create a configuration file similar to the server’s
wg0.conf
. - Start the WireGuard service on the client.
Integrating AdGuard with WireGuard VPN
Step 1: Install AdGuard
Step 2: Configure AdGuard
- Open AdGuard settings.
- Navigate to the „Filters“ section.
- Enable filters for ads, trackers, malware, etc., to enhance privacy and security.
Step 3: Integrate with WireGuard
- 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.