Introduction
In this article, we will discuss how to reroute WireGuard traffic from a Personal Computer (PC) to a Virtual Private Server (VPS) via a Public VPN server. We assume you have three entities: the PC, the VPS server with full access, and the VPN server.
Prerequisites
Before we dive into the steps, make sure you have the following:
- A PC with WireGuard installed
- A VPS server with WireGuard installed and full access
- A VPN server with WireGuard installed
- Public IP addresses for the PC, VPS server, and VPN server
Step 1: Configure the WireGuard Interface on the PC
First, let's configure the WireGuard interface on the PC.
[Interface]
PrivateKey =
Address = 10.0.0.1/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o eth0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o eth0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey =
AllowedIPs = 10.0.0.2/32
Endpoint = :51820
Step 2: Configure the WireGuard Interface on the VPS Server
Next, let's configure the WireGuard interface on the VPS server.
[Interface]
PrivateKey =
Address = 10.0.0.2/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o eth0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o eth0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey =
AllowedIPs = 10.0.0.1/32
Endpoint = :51820
Step 3: Configure the WireGuard Interface on the VPN Server
Now, let's configure the WireGuard interface on the VPN server.
[Interface]
PrivateKey =
Address = 10.0.0.3/24
ListenPort = 51820
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o eth0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o eth0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey =
AllowedIPs = 10.0.0.2/32
Endpoint = :51820
[Peer]
PublicKey =
AllowedIPs = 10.0.0.1/32
Endpoint = :51820
Step 4: Test the Connection
Now, test the connection by pinging from the PC to the VPS server and from the VPS server to the PC.
In this article, we discussed how to reroute WireGuard traffic from a PC to a VPS server via a VPN server. We configured the WireGuard interfaces on each device and tested the connection. For more information, check out the following resources: