You may have come across this problem in Windows 10/11 where L2TP VPN connections using a shared preshare key and a username and password fail to connect although everything is fine in IOS/MACOS or Linux clients.

The solution to the problem is the following.

Run the following from an elevated command prompt:

REG ADD HKLM\SYSTEM\CurrentControlSet\Services\PolicyAgent /v AssumeUDPEncapsulationContextOnSendRule /t REG_DWORD /d 0x2 /f

Also make sure the following setting is checked in the adapter created for your VPN Connection in networks.

enter image description here

Now after rebooting your computer you should be able to connect normally without issues.