micahmo / WgServerforWindows

Wg Server for Windows (WS4W) is a desktop application that allows running and managing a WireGuard server endpoint on Windows
MIT License
822 stars 79 forks source link

Iptables prerouting on windows #117

Open MatisseVS opened 1 year ago

MatisseVS commented 1 year ago

Hey,

I'm currently running wireguard server on a linux VM to use as a VPN for my game servers hosted at home. However I prefer switching to windows server. I've tried your program and it works flawless. The only issue I have is that I don't know how to preroute traffic in windows as there is no iptables support.

These are the iptables I'm currently using, wondering if you have any tips on how I would accomplish this on windows.

iptables -t nat -A PREROUTING -d /32 -p udp -m udp --dport 27015 -j DNAT --to-destination 10.8.0.2:27015 iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

micahmo commented 1 year ago

Hi @zevoscripts, thanks for the inquiry!

I hate to be the bearer of bad news, but I think you will be disappointed if you're hoping Windows will be able to provide the advanced routing options of iptables. I'm also very lacking in knowledge here. Can you give me an idea of your desired topology? Are you trying to route packets that are incoming through your WireGuard server to a particular other machine before going where they're actually destined?

MatisseVS commented 1 year ago

Hey,

Thanks for your response

I'm routing gameservers through the wireguard tunnel so packets that come into the wireguard server on a particular port should be routed through the tunnel to my client server.

micahmo commented 1 year ago

I'm not sure you'll find what you want. Windows NAT routing is pretty simple. It creates a local network adapter with its own IP range. However, once packets come in, they just get routed as if they were being made by your Windows server on your LAN or WAN. I'm not aware of any way to route them to another server (if they weren't already destined for that server from the client).

You're welcome to take a look at the NAT routing commands, and if any combination of them gives you what you want, I'd be happy to add it to the application.

https://learn.microsoft.com/en-us/powershell/module/netnat/?view=windowsserver2022-ps

But again, the Windows implementation here is pretty simple. 😞