DEV Community

Cover image for Installing WireGuard VPN on Ubuntu 22.04
Ersin KOÇ
Ersin KOÇ

Posted on

Installing WireGuard VPN on Ubuntu 22.04

Installing WireGuard VPN on Ubuntu 22.04 is relatively straightforward. Here's a step-by-step guide:

  1. Update Package List: First, ensure that your package list is up to date by running:

    sudo apt update
    
  2. Install WireGuard: WireGuard is available in the official Ubuntu repositories, so you can install it using apt:

    sudo apt install wireguard
    
  3. Generate Keys: Generate public and private keys for the server and client. You can do this by using the wg command, which is part of the WireGuard package you just installed. Replace <interface-name> with the name of your WireGuard interface (e.g., wg0):

    umask 077
    wg genkey | tee privatekey | wg pubkey > publickey
    

    This will generate privatekey and publickey files. You'll need to do this for both the server and client.

  4. Configure WireGuard: Now, you'll need to create configuration files for both the server and the client.

    For the server (/etc/wireguard/wg0.conf):

    [Interface]
    Address = 10.0.0.1/24
    PrivateKey = <server-private-key>
    ListenPort = 51820
    
    [Peer]
    PublicKey = <client-public-key>
    AllowedIPs = 10.0.0.2/32
    

    For the client (client.conf):

    [Interface]
    Address = 10.0.0.2/24
    PrivateKey = <client-private-key>
    
    [Peer]
    PublicKey = <server-public-key>
    Endpoint = <server-ip>:51820
    AllowedIPs = 0.0.0.0/0
    

    Replace <server-private-key>, <client-private-key>, <server-public-key>, and <client-public-key> with the respective private and public keys you generated earlier. Replace <server-ip> with the IP address of your WireGuard server.

  5. Start WireGuard: After configuring both the server and client, you can start the WireGuard service on the server:

    sudo systemctl enable --now wg-quick@wg0
    

    Replace wg0 with the name of your WireGuard interface if it's different.

  6. Start WireGuard on the Client: Copy the client.conf file to your client machine and start the WireGuard service:

    sudo wg-quick up client.conf
    

    This command will start the WireGuard service using the configuration specified in client.conf.

That's it! You should now have WireGuard VPN set up between your server and client. Remember to configure your firewall settings to allow traffic on the WireGuard port (UDP 51820) if you haven't already done so.

For reliable VPS hosting with fast NVMe disks and KVM-based virtualization, check out EcoStack Cloud, where prices start from just 2.90 €. Visit EcoStack.cloud to learn more and get started!

Top comments (0)