0

I had setup a Wireguard server on my Win 10 PC to access my home network by following this youtube tutorial.

Server config

[Interface]
PrivateKey = server-private
ListenPort = 51820
Address = 192.168.200.1/24

[Peer]
PublicKey = client-public
AllowedIPs = 192.168.200.2/32

I tried connecting to the server via Android Wireguard client

Client config

[Interface]
PrivateKey = client-private
Address = 192.168.200.2/24
DNS = 8.8.8.8, 1.1.1.1

[Peer]
PublicKey = server-public
AllowedIPs = 0.0.0.0/0
Endpoint = server.public.ip:51820

I had enabled port-forwarding on the router on port 51820 to my Win 10 PC internal static ip port 51820

I had also connected my home wifi adapter to the wireguard interface adapter (Wireguard_Server) by right clicking on wifi adapter --> Properties --> Sharing --> Check both the check boxes to allow my Wireguard_Server home networking connection.

The client was able to connect to my Server and successfully access home network from public internet and also able to browse Internet via my home network.

The problem started when my home PC got restarted. I was able to establish wireguard connection from client to Server but I can't access any other resource on my home network nor connect to Internet.

How to fix this issue?

Technically, the devices connected in WireGuard interfaces are peers. But Server-Client is easy to understand for me and I went with that

1 Answer 1

2

After browsing through many articles, came across this article by Henry.

Turns out windows kinda disables the ICS setup done on reboot.

Followed the article and added registry key and modified the ICS service but it did not work and I still had to manually disable and enable ICS on Server for Internet over Wireguard to work.

Created the following powershell script mentioned in the article

Function Set-NetConnectionSharing
{
    Param
    (
        [Parameter(Mandatory=$true)]
        [string]
        $LocalConnection,

        [Parameter(Mandatory=$true)]
        [bool]
        $Enabled        
    )

    Begin
    {
        $netShare = $null

        try
        {
            # Create a NetSharingManager object
            $netShare = New-Object -ComObject HNetCfg.HNetShare
        }
        catch
        {
            # Register the HNetCfg library (once)
            regsvr32 /s hnetcfg.dll

            # Create a NetSharingManager object
            $netShare = New-Object -ComObject HNetCfg.HNetShare
        }
    }

    Process
    {
        #Clear Existing Share          
        $oldConnections = $netShare.EnumEveryConnection |? { $netShare.INetSharingConfigurationForINetConnection.Invoke($_).SharingEnabled -eq $true}           
        foreach($oldShared in $oldConnections)
        {
            $oldConfig = $netShare.INetSharingConfigurationForINetConnection.Invoke($oldShared)
            $oldConfig.DisableSharing()                        
        }        
    
        # Find connections
        $InternetConnection = Get-NetRoute | ? DestinationPrefix -eq '0.0.0.0/0' | Get-NetIPInterface | Where ConnectionState -eq 'Connected'        
        $publicConnection = $netShare.EnumEveryConnection |? { $netShare.NetConnectionProps.Invoke($_).Name -eq $InternetConnection.InterfaceAlias }
        $privateConnection = $netShare.EnumEveryConnection |? { $netShare.NetConnectionProps.Invoke($_).Name -eq $LocalConnection }

        # Get sharing configuration
        $publicConfig = $netShare.INetSharingConfigurationForINetConnection.Invoke($publicConnection)
        $privateConfig = $netShare.INetSharingConfigurationForINetConnection.Invoke($privateConnection)

        if ($Enabled)
        {           
            $publicConfig.EnableSharing(0)
            $privateConfig.EnableSharing(1)
        }
        else
        {
            $publicConfig.DisableSharing()
            $privateConfig.DisableSharing()
        }
    }
}

and set it up as a scheduled task

task batch file

@echo off
"%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe" Set-NetConnectionSharing "Wireguard_Server" $true
  • running on startup as automatic
  • whether user is logged in or not

I also had to enable running local powershell scripts in Group Policy. Execution Policy : RemoteSigned

After the task is setup, the wireguard connection works without any problems even after wireguard server reboot.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .