VPN Guide

    Setting Up WireGuard VPN

    WireGuard has become the go-to VPN solution for many users due to its simplicity, speed, and modern cryptography. Combined with SOAHost's reliable VPS hosting, you can create your own private VPN server in just a few steps. This guide will walk you through the entire process of setting up WireGuard on a SOAHost VPS.

    Ubuntu 22.04/24.04
    WireGuard VPN
    โฑ๏ธ 15-20 minutes

    Prerequisites

    Before starting, ensure you have:

    Server Requirements

    • โ€ข SOAHost VPS (Ubuntu 22.04/24.04)
    • โ€ข Root access to server
    • โ€ข SSH client

    Knowledge Requirements

    • โ€ข Basic Linux command line
    • โ€ข Understanding of networking basics
    • โ€ข SSH connection skills
    2

    Initial Server Setup

    Connect to your SOAHost VPS and update the system:

    Connect via SSH
    ssh root@your-server-ip
    Update System Packages
    apt update && apt upgrade -y

    ๐Ÿ’ก Tip: Replace "your-server-ip" with your actual SOAHost VPS IP address.

    3

    Install WireGuard

    Install WireGuard and necessary utilities:

    Install WireGuard
    apt install wireguard wireguard-tools -y

    โœ… WireGuard is now installed and ready for configuration.

    4

    Generate Server Keys

    Generate the server's private and public keys:

    Navigate and Generate Keys
    cd /etc/wireguard
    wg genkey | tee server_private.key | wg pubkey > server_public.key
    Set Key Permissions
    chmod 600 server_private.key chmod 644 server_public.key

    ๐Ÿ” Security: Keep your private key secure and never share it!

    5

    Configure WireGuard Server

    Create the server configuration file:

    Create Config File
    nano /etc/wireguard/wg0.conf

    Add the following configuration (replace SERVER_PRIVATE_KEY with your actual private key):

    WireGuard Server Configuration
    [Interface]
    PrivateKey = SERVER_PRIVATE_KEY
    Address = 10.0.0.1/24
    ListenPort = 51820
    PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
    
    # Client configurations will be added below
    [Peer]
    PublicKey = CLIENT_PUBLIC_KEY
    AllowedIPs = 10.0.0.2/32
    6

    Enable IP Forwarding

    Enable IP forwarding to allow traffic routing:

    Enable IP Forwarding
    echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
    sysctl -p
    7

    Configure Firewall

    Configure UFW firewall to allow WireGuard traffic:

    Configure UFW Firewall
    ufw allow 51820/udp ufw allow OpenSSH ufw enable

    โš ๏ธ Warning: Make sure SSH is allowed before enabling UFW to avoid losing access!

    8

    Start WireGuard Service

    Start and enable the WireGuard service:

    Enable and Start Service
    systemctl enable wg-quick@wg0 systemctl start wg-quick@wg0
    Check Service Status
    systemctl status wg-quick@wg0

    ๐Ÿš€ Your WireGuard server is now running!

    9

    Generate Client Configuration

    Generate keys for each client device:

    Generate Client Keys
    wg genkey | tee client_private.key | wg pubkey > client_public.key

    Create a client configuration file:

    Client Configuration File
    [Interface]
    PrivateKey = CLIENT_PRIVATE_KEY
    Address = 10.0.0.2/32
    DNS = 8.8.8.8
    
    [Peer]
    PublicKey = SERVER_PUBLIC_KEY
    Endpoint = YOUR_SERVER_IP:51820
    AllowedIPs = 0.0.0.0/0
    PersistentKeepalive = 25
    10

    Adding Clients to Server

    Add the client's public key to the server:

    Add Client Dynamically
    wg set wg0 peer CLIENT_PUBLIC_KEY allowed-ips 10.0.0.2/32

    Or restart the service after editing the config file:

    Restart Service
    systemctl restart wg-quick@wg0
    11

    Client Setup

    Install WireGuard on your client devices:

    ๐Ÿ“ฑ Mobile

    Download WireGuard app from App Store or Google Play

    ๐Ÿ–ฅ๏ธ Desktop

    Download from wireguard.com

    ๐Ÿง Linux

    Install via package manager

    Linux Client Installation
    apt install wireguard

    ๐Ÿ“‹ Import the client configuration file or manually enter the configuration details in your WireGuard client.

    12

    Testing the Connection

    Follow these steps to test your VPN connection:

    1

    Connect to VPN

    Activate the WireGuard connection on your client device

    2

    Check IP Address

    Check Your IP
    curl ifconfig.me
    3

    Test DNS Resolution

    Test DNS
    nslookup google.com

    โœ… If the IP matches your SOAHost VPS IP, your VPN is working correctly!

    Troubleshooting Common Issues

    Security Best Practices

    ๐Ÿ”’ Server Security

    • โ€ข Regular system updates
    • โ€ข Implement fail2ban
    • โ€ข Change default SSH port
    • โ€ข Monitor server logs

    ๐Ÿ—๏ธ Key Management

    • โ€ข Unique keys per client
    • โ€ข Secure key storage
    • โ€ข Regular key rotation
    • โ€ข Revoke unused keys

    ๐ŸŽ‰ Congratulations!

    You now have a fully functional WireGuard VPN server running on your SOAHost VPS. This setup provides secure, encrypted access to the internet through your private server.