Routing Traffic Through Three WireGuard Nodes: Main-Server, Web-Gateway, Client
WireGuard is a modern, fast, and secure VPN that utilizes state-of-the-art cryptography. With its simple and easy-to-use interface, it has become a popular choice for many users. In this article, we will discuss how to route traffic through three WireGuard nodes: Main-Server, Web-Gateway, and Client.
Main-Server
The Main-Server is the primary node that acts as the central hub for all the other nodes. It is responsible for routing traffic between the Web-Gateway and the Client. To set up the Main-Server, you will need to follow these steps:
- Install WireGuard on the Main-Server
- Generate a private and public key pair
- Configure the WireGuard interface
- Add the Web-Gateway as a peer
- Start the WireGuard interface
# Install WireGuard
sudo apt install wireguard
# Generate a private and public key pair
umask 077; wg genkey | tee privatekey | wg pubkey > publickey
# Configure the WireGuard interface
cat > /etc/wireguard/wg0.conf < EOF
[Interface]
Address = 10.0.0.1/24
PrivateKey =
ListenPort = 51820
[Peer]
PublicKey =
AllowedIPs = 10.0.1.0/24
Endpoint = :51820
PersistentKeepalive = 25
EOF
# Add the Web-Gateway as a peer
wg set wg0 peer allowed-ips 10.0.1.0/24 endpoint :51820
# Start the WireGuard interface
systemctl start wg-quick@wg0
Web-Gateway
The Web-Gateway is the second node that acts as a bridge between the Main-Server and the Client. It is responsible for routing traffic between the Main-Server and the Client. To set up the Web-Gateway, you will need to follow these steps:
- Install WireGuard on the Web-Gateway
- Generate a private and public key pair
- Configure the WireGuard interface
- Add the Main-Server as a peer
- Add the Client as a peer
- Start the WireGuard interface
# Install WireGuard
sudo apt install wireguard
# Generate a private and public key pair
umask 077; wg genkey | tee privatekey | wg pubkey > publickey
# Configure the WireGuard interface
cat > /etc/wireguard/wg0.conf < EOF
[Interface]
Address = 10.0.1.1/24
PrivateKey =
ListenPort = 51820
[Peer]
PublicKey =
AllowedIPs = 10.0.0.0/24
Endpoint = :51820
PersistentKeepalive = 25
[Peer]
PublicKey =
AllowedIPs = 10.0.2.0/24
Endpoint = :51820
PersistentKeepalive = 25
EOF
# Add the Main-Server as a peer
wg set wg0 peer allowed-ips 10.0.0.0/24 endpoint :51820
# Add the Client as a peer
wg set wg0 peer allowed-ips 10.0.2.0/24 endpoint :51820
# Start the WireGuard interface
systemctl start wg-quick@wg0
Client
The Client is the third node that connects to the Web-Gateway to access the Main-Server. To set up the Client, you will need to follow these steps:
- Install WireGuard on the Client
- Generate a private and public key pair
- Configure the WireGuard interface
- Add the Web-Gateway as a peer
- Start the WireGuard interface
# Install WireGuard
sudo apt install wireguard
# Generate a private and public key pair
umask 077; wg genkey | tee privatekey | wg pubkey > publickey
# Configure the WireGuard interface
cat > /etc/wireguard/wg0.conf < EOF
[Interface]
Address = 10.0.2.1/24
PrivateKey =
[Peer]
PublicKey =
AllowedIPs = 0.0.0.0/0
Endpoint = :51820
PersistentKeepalive = 25
EOF
# Add the Web-Gateway as a peer
wg set wg0 peer allowed-ips 0.0.0.0/0 endpoint :51820
# Start the WireGuard interface
systemctl start wg-quick@wg0
In this article, we have discussed how to route traffic through three WireGuard nodes: Main-Server, Web-Gateway, and Client. The Main-Server acts as the central hub for all the other nodes, while the Web-Gateway acts as a bridge between the Main-Server and the Client. The Client connects to the Web-Gateway to access the Main-Server. By following the steps outlined in this article, you can easily set up a secure and fast VPN using WireGuard.