We have a web server on a box without direct access from the internet (e.g. behind a CGNAT). We want to use a box with a public IP address (such as a cheap VPS) as a gateway that will redirect HTTP traffic to the web server. We will setup a Wireguard VPN to enable bidirectional traffic between both boxes, as well as a few routing/NAT rules to redirect HTTP traffic.
Install Wireguard and wg-quick on both boxes: https://www.wireguard.com/install/
Note: in later steps, a public/private key pair can be generated with:
wg genkey | tee private.key | wg pubkey > public.key
For security, these *.key
files should be deleted once the VPN is configured.
Enable IP forwarding:
sudo tee <<<"net.ipv4.ip_forward = 1" /etc/sysctl.d/99-enable-ip-forward.conf
sysctl --system
Copy wgweb_gateway.conf
to /etc/wireguard/wgweb.conf
and replace placeholders with actual values.
You may need to replace eth0
with the network interface that relays internet traffic.
Run ip a
to get a list of network interfaces.
Make sure that the gateway can receive UDP traffic on port 51820
.
Start VPN (create and configure network interface):
systemctl start wg-quick@wgweb
Copy wgweb_server.conf
to /etc/wireguard/wgweb.conf
and replace placeholders with actual values.
Start VPN (create and configure network interface):
systemctl start wg-quick@wgweb
Once everything works correctly,
run systemctl enable wg-quick@wgweb
on both boxes to enable the VPN when the system starts.