I'm attempting to DDOS protect one of my servers (called "the client" from here on out to eliminate confusion). To do that, I'm renting a cheap server from OVH (called "the server") and am attempting to route all traffic from the server to the client, so that it passes through the DDOS protection.
I decided on Wireguard as the best solution, and successfully linked the two servers. I am now trying to forward ports from the client to the server, and have tried this setup (where 10.20.40.2
is the client, and 10.20.40.1
is the server):
sudo iptables -t nat -A PREROUTING -p tcp --dport $port -j DNAT --to-destination 10.20.40.2
sudo iptables -A FORWARD -o wg0 -p tcp --syn --dport $port -m conntrack --ctstate NEW -j ACCEPT
sudo iptables -A FORWARD -o wg0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A FORWARD -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A PREROUTING -p tcp --dport $port -j DNAT --to-destination 10.20.40.2
sudo iptables -t nat -A POSTROUTING -o wg0 -p tcp --dport $port -d 10.20.40.2 -j SNAT --to-source 10.20.40.1
This works fine, except that from the client's point of view, every IP is 10.20.40.1
aka the server's. Is there a way I can forward the public IP addresses to the client? I have seen this question on StackExchange before, but with the limitation that "the client" in their situation was inaccessible. I have full access to both servers, so installing software on either is not a problem.
The client's Wireguard configuration:
[Interface]
PrivateKey = (redacted)
ListenPort = 51820
Address = 10.20.40.2/16
[Peer]
PublicKey = (redacted)
Endpoint = (redacted):51820
AllowedIPs = 10.20.40.0/16
The server's Wireguard configuration:
[Interface]
PrivateKey = (redacted)
ListenPort = 51820
Address = 10.20.40.1/24
[Peer]
PublicKey = (redacted)
AllowedIPs = 10.20.40.0/24