Wireguard

1. Install WireGuard on the VPS

  1. Update the system:

    sudo apt update && sudo apt upgrade -y
  2. Install WireGuard:

    • On Debian/Ubuntu:

      sudo apt install wireguard -y
    • On CentOS/RHEL:

      sudo yum install epel-release -y
      sudo yum install wireguard-tools -y
    • On Fedora:

       dnf install wireguard-tools -y

2. Generate Keys for the Server

  1. Create the WireGuard directory:

    sudo mkdir /etc/wireguard
    sudo chmod 700 /etc/wireguard
    cd /etc/wireguard
  2. Generate private and public keys:

    umask 077
    wg genkey | tee server_private.key | wg pubkey > server_public.key
  3. Note the keys:

    cat server_private.key
    cat server_public.key

3. Configure the WireGuard Server

  1. Create a WireGuard configuration file:

  2. Add the following content:

    Replace <server_private_key> with the content of server_private.key. Replace <client_public_key> with the public key generated for the client in the next step.

  3. Enable IP forwarding:


4. Generate Keys for the Client

On the VPS, generate client keys:

Retrieve the keys:


5. Add Client Configuration to the Server

Edit the server configuration file /etc/wireguard/wg0.conf and add a new peer block:


6. Start and Enable the WireGuard Service

  1. Start WireGuard:

  2. Enable WireGuard to start on boot:

  3. Check the WireGuard status:


7. Configure the Client Device

On Linux

  1. Install WireGuard:

  2. Create the client configuration file:

  3. Add the following content:

    Replace <client_private_key> with the client private key, <server_public_key> with the server public key, and <server_ip> with the IP of your VPS.

  4. Start WireGuard:


On Windows

  1. Download and install WireGuard for Windows.

  2. Import the client.conf file and connect.


On Android/iOS

  1. Install the WireGuard app from the app store.

  2. Import the client.conf file using QR code or file transfer.

  3. Connect to the server.


8. Verify Connection

On the client device, check your public IP:

The IP should now reflect your VPS's IP, confirming the VPN is active.

Last updated