Suppose I have two servers: A and B. On both I have installed WireGuard.
On server A, wg0
is routed with IP 10.8.0.0/24
and on server B, wg0
is routed with IP 10.7.0.0/24
.
Let's say server A's WireGuard is listening on port 4000 and server B's WireGuard is listening on port 5000.
I only want to forward all incoming traffic to server A on port 5000. There are other applications listening on another ports and I do not to forward them.
What I want is:
- client connects to --> server A
- let's say client says to server A open google.com for me
- server A connects to --> server B
- let's say server A says to server B open google.com for me
- server B reaches google.com
- sends data of received from google.com to --> server A
- server A sends the received data to --> client
What should be done? The OS is Ubuntu on both servers.
Update 1
S-B's /etc/wireguard/wg0.conf
file:
[Interface]
Address = 10.7.0.1/24
PrivateKey = SOME_KEY
ListenPort = PORT_NUMBER
S-A's /etc/wireguard/wg0.conf
file:
[Interface]
Address = 10.8.0.1/24
PrivateKey = SOME_KEY
ListenPort = PORT_NUMBER
I connected to S-A's VPN, ping on my cmd 8.8.8.8, it worked. SSHed into S-A while connecting to VPN, ping 8.8.8.8, it worked.
I did the same for S-B and it worked.
I can SSH from S-A to S-B and vice-versa.
One client conf file on S-A:
[Interface]
Address = 10.8.0.2/24
DNS = 8.8.8.8
PrivateKey = PRIVATE
[Peer]
PublicKey = PUBLIC
PresharedKey = PRESHARED
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = IP:PORT
PersistentKeepalive = 25
One client conf file on S-B:
[Interface]
Address = 10.7.0.2/24
DNS = 8.8.8.8
PrivateKey = PRIVATE
[Peer]
PublicKey = PUBLIC
PresharedKey = PRESHARED
AllowedIPs = 0.0.0.0/0, ::/0
Endpoint = IP:PORT
PersistentKeepalive = 25