ssh root@your_vps_ip_address
sudo apt install wireguard
sudo yum install epel-release sudo yum install wireguard-tools
wg genkey | tee privatekey | wg pubkey > publickey
'privatekey': Your private key.
'publickey': Your public key.
sudo nano /etc/wireguard/wg0.conf
[Interface] PrivateKey = your_private_key Address = 10.0.0.1/24 # IP range for VPN clients ListenPort = 51820 # Default WireGuard port [Peer] PublicKey = client_public_key AllowedIPs = 10.0.0.2/32 # Client IP within the VPN range
PrivateKey: The server’s private key.
Address: The IP range that WireGuard will use for connected clients.
ListenPort: The port WireGuard will listen on for incoming connections.
PublicKey: The public key of the client that will connect to this server.
AllowedIPs: The IPs allowed to use the VPN, typically the client’s IP within the VPN network.
sudo ufw allow 51820/udp sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1
sudo sysctl -p
sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0
sudo wg
wg genkey | tee client_privatekey | wg pubkey > client_publickey
[Interface] PrivateKey = client_privatekey Address = 10.0.0.2/32 # Must match the AllowedIPs in the server config DNS = 1.1.1.1 # Optional: Configure a DNS server for the client [Peer] PublicKey = server_publickey Endpoint = your_vps_ip:51820 AllowedIPs = 0.0.0.0/0 # Route all traffic through the VPN
PrivateKey: The client’s private key.
Address: The IP address assigned to the client within the VPN.
DNS: Optional DNS server for the client.
PublicKey: The server’s public key.
Endpoint: The IP address and port of your VPS.
AllowedIPs: The IP ranges routed through the VPN. Use 0.0.0.0/0 to route all traffic.