NAT Routing Error
crack00r opened this issue · 11 comments
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Exception: New-NetNat : Ung�ltige Klasse
In Zeile:1 Zeichen:1
- New-NetNat -Name wg_server_nat -InternalIPInterfaceAddressPrefix 10.2 ...
-
+ CategoryInfo : MetadataError: (MSFT_NetNat:root/StandardCimv2/MSFT_NetNat) [New-NetNat], CimException + FullyQualifiedErrorId : HRESULT 0x80041010,New-NetNat at WireGuardServerForWindows.Models.NewNetNatPrerequisite.Resolve(String serverDataPath) in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\NewNetNatPrerequisite.cs:line 115 at WireGuardServerForWindows.Models.NewNetNatPrerequisite.Resolve() in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\NewNetNatPrerequisite.cs:line 68 --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at GalaSoft.MvvmLight.Helpers.WeakAction.Execute() at GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter) at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated) at System.Windows.Controls.Primitives.ButtonBase.OnClick() at System.Windows.Controls.Button.OnClick() at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) at System.Windows.Input.InputManager.ProcessStagingArea() at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
System.Exception: New-NetNat : Ung�ltige Klasse
In Zeile:1 Zeichen:1
- New-NetNat -Name wg_server_nat -InternalIPInterfaceAddressPrefix 10.2 ...
-
+ CategoryInfo : MetadataError: (MSFT_NetNat:root/StandardCimv2/MSFT_NetNat) [New-NetNat], CimException + FullyQualifiedErrorId : HRESULT 0x80041010,New-NetNat at WireGuardServerForWindows.Models.NewNetNatPrerequisite.Resolve(String serverDataPath) in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\NewNetNatPrerequisite.cs:line 115 at WireGuardServerForWindows.Models.NewNetNatPrerequisite.Resolve() in C:\Users\micah\source\repos\WireGuardServerForWindows\WireGuardServerForWindows\Models\NewNetNatPrerequisite.cs:line 68
Hey @crack00r, can you send the exact version of Windows you're running? From the Start menu or Run box, type winver
and screenshot the window. It should look something like this.
Thanks!
@crack00r I would still like to hear what version of Windows you're running, but I think I know what's going on here. The NAT routing features requires either...
- Hyper-V to be enabled (which requires Pro)
- Or Windows to be updated to 21H2
Of course Internet Connection Sharing can always be used if NAT cannot.
I've documented this limitation here.
I will keep the issue open to track an enhancement, which should do the following.
- On a Windows installation capable of (but not currently) running Hyper-V, automatically enable it.
- On a Windows installation incapable of running Hyper-V, do not show the NAT option.
Thanks for confirming! This aligns with my guess.
- You have version 21H1, so the NAT routing feature won't work without Hyper-V
- And you have Home, which means you can't enable Hyper-V anyway
I'm glad to hear that ICS works. And if you did want to use NAT instead (it has some benefits described in #18), you could update to 21H2.
As mentioned, I will keep this issue open, because the NAT button should not have been available in your scenario.
Upon further investigation (with Windows 10 Pro 21H2), it appears that Hyper-V must be enabled in order to use NAT Routing. @kenvix, you said in #18 that it didn't. Can you explain how you got New-NetNat
to work without first enabling Hyper-V?
For now, I've updated the documentation to reflect this.
https://github.com/micahmo/WireGuardServerForWindows#inability-to-enable-nat
Upon further investigation (with Windows 10 Pro 21H2), it appears that Hyper-V must be enabled in order to use NAT Routing. @kenvix, you said in #18 that it didn't. Can you explain how you got
New-NetNat
to work without first enabling Hyper-V?
I am not kenvix, but I installed WireGuard Server for Windows on Windows 10 pro 21H2 Build 19044.1620 yesterday without problems. And no, Hyper-V is not enabled. At least I believe it isn't: In Windows Features "Hyper-V" is unticked.
I didn't do anything special, it just worked.
After some testing on the Win Pro machine, I have installed WireGuard Server for Windows on Windows Server 2019 which has an old Windows 10 under the hood: Version 1809, Build 17763.2686. Everything works surprisingly well.
EDIT: Windows Server 2019 has the server role "Hyper-V" disabled.
Hmm, interesting. Now I wonder if my problem could've been related to the fact that I was using VMs to test this without nested virtualization enabled. I will have to do some more investigation.
Hmm, interesting. Now I wonder if my problem could've been related to the fact that I was using VMs to test this without nested virtualization enabled. I will have to do some more investigation.
Now I'm going to confuse you even more... I just tried WireGuardServerForWindows on Windows 10 Pro N Version 21H2 Build 19044.1620 and enabling NAT failed!
I installed Hyper V and enabling NAT worked. Out of curiosity I uninstalled Hyper V and enabling NAT failed again. Very weird.
I'm getting the impression that I won't be able to add a simple version check to gate this feature. 😊
It seems like I will need some sort of graceful handling of this error that does the following...
- Try to enable NAT Rounting.
- If it fails, try to enable Hyper-V.
- If that fails, direct users to Internet Connection Sharing instead.
Hey all, I just pushed v1.7.2 which should help to address this issue. As we collectively discovered, there's not a great way to know upfront whether NAT Routing will work or not, so the application just tries to enable it (with the option to try to enable Hyper-V as well); otherwise, it directs you to use ICS.