Delen via


Zelfstudie: Een AlwaysOn VPN-verbinding maken op Windows-clientapparaten

In deze zelfstudie leert u hoe u een AlwaysOn VPN-verbinding maakt op Windows-clientapparaten. De reeks wordt voortgezet voor het implementeren van AlwaysOn VPN in een voorbeeldomgeving. Eerder in de reeks hebt u een voorbeeldinfrastructuur geïmplementeerd en certificeringsinstantiesjablonen geconfigureerd.

In deze handleiding leert u:

  • Maak en test een handmatige GEBRUIKERS-VPN-verbinding die wordt gebruikt als sjabloon voor de AlwaysOn VPN-verbinding.
  • Converteer de handmatige VPN-verbinding naar een AlwaysOn VPN-verbinding met behulp van PowerShell.

AlwaysOn VPN-verbindingen kunnen worden geconfigureerd als een apparaattunnel of een gebruikerstunnel:

  • Device tunnel: connects to specified VPN servers before users signs in to the device. Een apparaattunnel wordt gebruikt voor scenario's voor connectiviteit vóór het inloggen en apparaatbeheer.

  • User tunnel: connects only after a user logs on to the device. Met een gebruikerstunnel kunnen gebruikers toegang krijgen tot organisatiebronnen via VPN-servers.

Zie VPN-apparaattunnels configureren in de Windows-client voor meer informatie over de verschillen tussen apparaattunnels en gebruikerstunnels.

Always On VPN connections, whether a device tunnel or a user tunnel, are configured using the ProfileXML node in the VPNv2 configuration service provider (CSP). De stappen in deze zelfstudie laten zien hoe u een gebruikerstunnel configureert op één Windows-clientapparaat. U kunt deze stappen gebruiken voor kleine omgevingen of voor testdoeleinden.

Voor grotere omgevingen moet u Microsoft Intune of Microsoft Configuration Manager gebruiken om het AlwaysOn VPN-profiel te implementeren op Windows-clientapparaten. Zie Een AlwaysOn VPN-profiel implementeren voor Windows-clients met Microsoft Intune en een AlwaysOn VPN-profiel implementeren voor Windows-clients met Microsoft Configuration Manager voor meer informatie.

Prerequisites

Voor het voltooien van de stappen in deze zelfstudie hebt u het volgende nodig:

Een handmatige VPN-verbinding voor gebruikers maken en testen

Eerst moet u een VPN-clientverbinding maken om te controleren of de VPN-testclient een geslaagde VPN-verbinding tot stand kan brengen. Met deze verbinding kunt u ook de EAP-instellingen (Extensible Authentication Protocol) maken voor de AlwaysOn VPN-verbinding. For more information about EAP settings, see EAP configuration.

  1. Meld u aan bij het aan het domein gekoppelde Windows-clientapparaat als de VPN-gebruiker die u eerder hebt aangemaakt in Active Directory testgebruiker aanmaken.

  2. On the Start menu, type VPN to select VPN Settings. Press ENTER.

  3. Selecteer een VPN-verbinding toevoegen in het detailvenster.

  4. For VPN Provider, select Windows (built-in).

  5. For Connection Name, enter Contoso VPN.

  6. Voer voor servernaam of -adres de externe FQDN (Fully Qualified Domain Name) van uw VPN-server in (bijvoorbeeld vpn.contoso.com).

  7. For VPN type, select IKEv2.

  8. Selecteer Certificaatvoor het type aanmeldingsgegevens.

  9. Select Save.

  10. Under Related Settings, select Change adapter options.

  11. Right-click Contoso VPN, and select Properties.

  12. On the Security tab, for Data encryption, select Maximum strength encryption.

  13. Selecteer Extensible Authentication Protocol (EAP) gebruiken. Kies vervolgens bij Extensible Authentication Protocol (EAP) de optie Microsoft: Protected EAP (PEAP) (versleuteling ingeschakeld).

  14. Select Properties to open Protected EAP Properties, and complete the following steps:

    1. Voer voor Verbinding maken met deze servers de hostnaam van uw NPS-server in.

    2. Voor vertrouwde basiscertificeringsinstanties selecteert u de CA die het certificaat van de NPS-server heeft uitgegeven (bijvoorbeeld contoso-CA).

    3. Voor meldingen voordat u verbinding maakt, selecteert u Gebruiker niet vragen om nieuwe servers of vertrouwde CA's te autoriseren.

    4. Voor Authenticatiemethode selecteren, selecteer smartcard of ander certificaat.

    5. Select Configure.

      1. Selecteer Een certificaat op deze computer gebruiken.

      2. Voer voor Verbinding maken met deze servers de hostnaam van de NPS-server in.

      3. Selecteer voor vertrouwde basiscertificeringsinstanties de CA die het certificaat van de NPS-server heeft uitgegeven.

      4. Selecteer Gebruiker niet vragen om nieuwe servers of vertrouwde certificeringsinstanties te autoriseren.

      5. Select OK to close Smart Card or other Certificate Properties.

      6. Select OK to close Protected EAP Properties.

    6. Select OK to close Contoso VPN Properties.

  15. Close the Network Connections window.

  16. In Settings, select Contoso VPN, and then select Connect. De VPN-verbinding moet tot stand worden gebracht. You can verify the connection by checking the Network Connections window. The Contoso VPN connection should show as Connected. Test of u verbinding kunt maken met een resource aan de andere kant van de VPN-tunnel, bijvoorbeeld een bestandsshare of webserver.

  17. Nadat u hebt gecontroleerd of de VPN-verbinding is geslaagd, verbreekt u de verbinding met de VPN-verbinding.

Important

Zorg ervoor dat de VPN-sjabloonverbinding met uw VPN-server is geslaagd. Dit zorgt ervoor dat de EAP-instellingen juist zijn voordat u ze in de volgende sectie gebruikt. U moet minstens één keer verbinding maken voordat u doorgaat; anders bevat het profiel niet alle informatie die nodig is om verbinding te maken met het VPN.

De handmatige VPN-verbinding converteren naar een AlwaysOn VPN-verbinding

Vervolgens converteert u de handmatige VPN-verbinding naar een AlwaysOn VPN-verbinding met behulp van een PowerShell-script.

  1. Als dezelfde gebruiker op het Windows-clientapparaat, opent u Windows PowerShell ISE als beheerder.

  2. Kopieer en plak het volgende PowerShell-script in het Windows PowerShell ISE editorvenster en zorg ervoor dat u de acht variabele waarden naar eigen waarden wijzigt.

    Vouw deze sectie uit om het PowerShell-script weer te geven.
    # Set the variables for the VPN profile.
    $domain = 'corp' # Name of the domain.
    $templateName = 'Contoso VPN' # Name of the test VPN connection you created in the tutorial. 
    $profileName = 'Contoso AlwaysOn VPN' # Name of the profile we are going to create.
    $servers = 'aov-vpn.contoso.com' # Public or routable IP address or DNS name for the VPN gateway.
    $dnsSuffix = 'corp.contoso.com' # Specifies one or more commas separated DNS suffixes. 
    $domainName = '.corp.contoso.com' # Used to indicate the namespace to which the policy applies. Contains `.` prefix.
    $dnsServers = '10.10.0.6' # List of comma-separated DNS Server IP addresses to use for the namespace.
    $trustedNetwork = 'corp.contoso.com' # Comma-separated string to identify the trusted network.
    
    # Get the EAP settings for the current profile called $templateName
    $connection = Get-VpnConnection -Name $templateName
    
    if(!$connection)
    {
        $message = "Unable to get $templateName connection profile: $_"
        Write-Host "$message"
        exit
    }
    
    $EAPSettings= $connection.EapConfigXmlStream.InnerXml
    
    $profileNameEscaped = $profileName -replace ' ', '%20'
    
    # Define ProfileXML
    $profileXML = @("
    <VPNProfile>
      <DnsSuffix>$dnsSuffix</DnsSuffix>
      <NativeProfile>
    <Servers>$servers</Servers>
    <NativeProtocolType>IKEv2</NativeProtocolType>
    <Authentication>
      <UserMethod>Eap</UserMethod>
      <Eap>
        <Configuration>
        $EAPSettings
        </Configuration>
      </Eap>
    </Authentication>
    <RoutingPolicyType>SplitTunnel</RoutingPolicyType>
      </NativeProfile>
    <AlwaysOn>true</AlwaysOn>
    <RememberCredentials>true</RememberCredentials>
    <TrustedNetworkDetection>$trustedNetwork</TrustedNetworkDetection>
      <DomainNameInformation>
    <DomainName>$domainName</DomainName>
    <DnsServers>$dnsServers</DnsServers>
    </DomainNameInformation>
    </VPNProfile>
    ")
    
    # Output the XML for possible use in Intune
    $profileXML | Out-File -FilePath ($env:USERPROFILE + '\desktop\VPN_Profile.xml')
    
    # Escape special characters in the profile (<,>,")
    $profileXML = $profileXML -replace '<', '&lt;'
    $profileXML = $profileXML -replace '>', '&gt;'
    $profileXML = $profileXML -replace '"', '&quot;'
    
    # Define WMI-to-CSP Bridge properties
    $nodeCSPURI = "./Vendor/MSFT/VPNv2"
    $namespaceName = "root\cimv2\mdm\dmmap"
    $className = "MDM_VPNv2_01"
    
    try
    {
    
        # Determine user SID for VPN profile.
        $WmiLoggedOnUsers = (Get-WmiObject Win32_LoggedOnUser).Antecedent
        If($WmiLoggedOnUsers.Count -gt 1) { 
            $WmiLoggedOnUsers = $WmiLoggedOnUsers -match "Domain=""$domain"""
        }
    
        $WmiUserValid = ($WmiLoggedOnUsers | Select-Object -Unique -First 1) -match 'Domain="([^"]+)",Name="([^"]+)"'
    
        If(-not $WmiUserValid){
            Throw "Returned object is not a valid WMI string"
        }
    
        $UserName = "$($Matches[1])\$($Matches[2])"
    
        $ObjUser = New-Object System.Security.Principal.NTAccount($UserName)
        $Sid = $ObjUser.Translate([System.Security.Principal.SecurityIdentifier])
        $SidValue = $Sid.Value
        $message = "User SID is $SidValue."
    
        Write-Host "$message"
    
    }
    catch [Exception] 
    {
    
        $message = "Unable to get user SID. $_"
        Write-Host "$message" 
        exit
    }
    
    try 
    {
    
        # Define WMI session.
        $session = New-CimSession
        $options = New-Object Microsoft.Management.Infrastructure.Options.CimOperationOptions
        $options.SetCustomOption("PolicyPlatformContext_PrincipalContext_Type", "PolicyPlatform_UserContext", $false)
        $options.SetCustomOption("PolicyPlatformContext_PrincipalContext_Id", "$SidValue", $false)
    
    }
    catch {
    
        $message = "Unable to create new session for $profileName profile: $_"
        Write-Host $message
        exit
    }
    
    try
    {
    
        # Detect and delete previous VPN profile.
        $deleteInstances = $session.EnumerateInstances($namespaceName, $className, $options)
    
        foreach ($deleteInstance in $deleteInstances)
        {
            $InstanceId = $deleteInstance.InstanceID
            if ("$InstanceId" -eq "$profileNameEscaped")
            {
                $session.DeleteInstance($namespaceName, $deleteInstance, $options)
                $message = "Removed $profileName profile $InstanceId" 
                Write-Host "$message"
            }
            else 
            {
                $message = "Ignoring existing VPN profile $InstanceId"
                Write-Host "$message"
            }
        }
    }
    catch [Exception]
    {
        $message = "Unable to remove existing outdated instance(s) of $profileName profile: $_"
        Write-Host $message
        exit
    
    }
    
    try
    {
    
        # Create the VPN profile.
        $newInstance = New-Object Microsoft.Management.Infrastructure.CimInstance $className, $namespaceName
        $property = [Microsoft.Management.Infrastructure.CimProperty]::Create("ParentID", "$nodeCSPURI", "String", "Key")
        $newInstance.CimInstanceProperties.Add($property)
        $property = [Microsoft.Management.Infrastructure.CimProperty]::Create("InstanceID", "$profileNameEscaped", "String", "Key")
        $newInstance.CimInstanceProperties.Add($property)
        $property = [Microsoft.Management.Infrastructure.CimProperty]::Create("ProfileXML", "$profileXML", "String", "Property")
        $newInstance.CimInstanceProperties.Add($property)
        $session.CreateInstance($namespaceName, $newInstance, $options)
    
        $message = "Created $profileName profile."
        Write-Host "$message"
    
    }
    catch [Exception]
    {
    
        $message = "Unable to create $profileName profile: $_"
        Write-Host "$message"
        exit
    }
    
    $message = "Always On VPN connection created successfully."
    Write-Host "$message"
    
  3. Voer het script uit.

  4. Controleer of het script is geslaagd door de volgende opdracht uit te voeren in het Windows PowerShell ISE editorvenster:

    Get-CimInstance -Namespace root\cimv2\mdm\dmmap -ClassName MDM_VPNv2_01
    

    De uitvoer moet vergelijkbaar zijn met het volgende voorbeeld (de ProfileXML waarde is afgekapt voor leesbaarheid):

    AlwaysOn                : True
    ByPassForLocal          : 
    DeviceTunnel            : 
    DnsSuffix               : corp.contoso.com
    EdpModeId               : 
    InstanceID              : Contoso%20AlwaysOn%20VPN
    LockDown                : 
    ParentID                : ./Vendor/MSFT/VPNv2
    ProfileXML              : <VPNProfile>...</VPNProfile>
    RegisterDNS             : 
    RememberCredentials     : True
    TrustedNetworkDetection : corp.contoso.com
    PSComputerName          : 
    
  5. De Always On VPN-verbinding moet succesvol worden aangemaakt en tot stand gebracht. You can verify the connection by checking the Network Connections window. De Contoso AlwaysOn VPN-verbinding moet worden weergegeven als Verbonden. Test of u verbinding kunt maken met een resource aan de andere kant van de VPN-tunnel, bijvoorbeeld een bestandsshare of webserver.

U maakt nu verbinding met de VPN-server met behulp van de AlwaysOn VPN-verbinding. Hier volgen enkele extra bronnen om u te helpen met uw AlwaysOn VPN-implementatie: