Introduction
In today's digital world, Virtual Private Servers (VPS) are widely used for hosting applications and services. Sometimes, we need to connect our VPS to our local network using a VPN to access specific applications or services. However, when enabling a VPN via WireGuard on a VPS, the default routing table might drop VPN traffic, and we need to configure WireGuard VPN routes for network applications with binded network interfaces.
Prerequisites
Before configuring WireGuard VPN routes, ensure you have the following:
- A VPS with a public IP address and a private IP address in your local network.
- WireGuard installed on your VPS.
- Access to your VPS via SSH.
Configuring WireGuard Interface
First, we need to configure the WireGuard interface on the VPS. Create a new configuration file for the interface:
sudo nano /etc/wireguard/wg0.conf
Add the following content to the file:
[Interface]
PrivateKey =
Address = /24
ListenPort = 51820
PostUp = iptables -A FORWARD --in-interface wg0 -j ACCEPT all
PostUp = iptables -A FORWARD --in-interface eth0 -j ACCEPT from /24 to any
PostDown = iptables -D FORWARD --in-interface wg0 -j ACCEPT all
PostDown = iptables -D FORWARD --in-interface eth0 -j ACCEPT from /24 to any
Replace
Configuring WireGuard Peer
Next, we need to configure the WireGuard peer on the VPS:
sudo nano /etc/wireguard/wg0.conf
Add the following content to the file:
[Peer]
PublicKey =
AllowedIPs = /32
Replace
Configuring Routes
Now, we need to configure the routes for the application:
sudo ip route add /32 via
Replace
Verifying Configuration
Finally, we need to verify the configuration:
sudo wg-quick up wg0
sudo ip addr show wg0
The output should show the WireGuard interface with the assigned IP address and the configured peer.
References
For more information, refer to the following resources: