Bagikan melalui


Tutorial: Menyebarkan VPN AlwaysOn - Mengonfigurasi profil VPN AlwaysOn untuk klien Windows 10+

Berlaku untuk: Windows Server 2022, Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows 10, Windows 11

Di bagian terakhir tutorial ini, Anda akan mempelajari cara menggunakan skrip konfigurasi ProfileXML PowerShell untuk mengonfigurasi pengaturan VPN AlwaysOn dan membuat terowongan pengguna untuk koneksi klien.

Untuk informasi selengkapnya tentang opsi konfigurasi Always on VPN untuk penyedia layanan konfigurasi (CSP), lihat penyedia layanan konfigurasi VPNv2.

Prasyarat

Tutorial Lengkap : Menyebarkan VPN AlwaysOn - Mengonfigurasi templat Otoritas Sertifikat.

Membuat profil klien VPN AlwaysOn

Di bagian ini, kita akan membuat koneksi klien VPN untuk memverifikasi bahwa klien pengujian VPN dapat membuat koneksi VPN yang berhasil. Ini juga akan memungkinkan kami membuat pengaturan EAP untuk diekspor di bagian berikutnya.

Untuk informasi selengkapnya tentang pengaturan EAP, lihat Konfigurasi EAP.

  1. Masuk ke komputer klien VPN yang bergabung dengan domain sebagai pengguna VPN yang Anda buat di Buat pengguna uji Direktori Aktif.

  2. Pada menu Mulai, ketik VPN untuk memilih VPN Pengaturan. Tekan ENTER.

  3. Di panel detail, pilih Tambahkan koneksi VPN.

  4. Untuk Penyedia VPN, pilih Windows (bawaan).

  5. Untuk Nama Koneksi ion, masukkan Contoso VPN.

  6. Untuk Nama atau alamat server, masukkan FQDN eksternal server VPN Anda (misalnya, vpn.contoso.com).

  7. Untuk jenis VPN, pilih IKEv2.

  8. Untuk Jenis info masuk, pilih Sertifikat.

  9. Pilih Simpan.

  10. Di bawah Pengaturan terkait, pilih Ubah opsi adaptor.

  11. Klik kanan Contoso VPN, dan pilih Properti.

  12. Pada tab Keamanan , untuk Enkripsi data, pilih Enkripsi kekuatan maksimum.

  13. Pilih Gunakan Extensible Authentication Protocol (EAP). Kemudian, untuk Gunakan Extensible Authentication Protocol (EAP), pilih Microsoft: Protected EAP (PEAP) (enkripsi diaktifkan).

  14. Pilih Properti untuk membuka Properti EAP terproteksi, dan selesaikan langkah-langkah berikut:

    1. Untuk Koneksi ke server ini, masukkan nama server NPS.

    2. Untuk Otoritas Sertifikasi Akar Tepercaya, pilih CA yang mengeluarkan sertifikat server NPS (misalnya, contoso-CA).

    3. Untuk Pemberitahuan sebelum menyambungkan, pilih Jangan minta pengguna untuk mengotorisasi server baru atau CA tepercaya.

    4. Untuk Pilih Metode Autentikasi, pilih Kartu Pintar atau sertifikat lainnya.

    5. Pilih Konfigurasikan.

      1. Pilih Gunakan sertifikat pada komputer ini.

      2. Untuk Koneksi ke server ini, masukkan nama server NPS.

      3. Untuk Otoritas Sertifikasi Akar Tepercaya, pilih CA yang menerbitkan sertifikat server NPS.

      4. Pilih Jangan minta pengguna untuk mengotorisasi server baru atau otoritas sertifikasi tepercaya.

      5. Pilih OK untuk menutup Kartu Pintar atau Properti Sertifikat lainnya.

      6. Pilih OK untuk menutup Properti EAP terproteksi.

    6. Pilih OK untuk menutup Properti VPN Contoso.

  15. Tutup jendela Koneksi jaringan.

  16. Di Pengaturan, pilih Contoso VPN, lalu pilih Koneksi.

Penting

Pastikan koneksi VPN templat ke server VPN Anda berhasil. Melakukannya memastikan bahwa pengaturan EAP sudah benar sebelum Anda menggunakannya di langkah berikutnya. Anda harus tersambung setidaknya sekali sebelum melanjutkan; jika tidak, profil tidak akan berisi semua informasi yang diperlukan untuk terhubung ke VPN.

Mengonfigurasi klien VPN Windows Anda

Di bagian ini, Anda akan mengonfigurasi klien VPN Windows secara manual menggunakan skrip PowerShell.

  1. Masuk sebagai Pengguna VPN Anda ke komputer klien VPN.

  2. Buka lingkungan skrip terintegrasi (ISE) Windows PowerShell sebagai Administrator.

  3. Salin dan tempel skrip berikut ini:

    
    # Define key VPN profile parameters
    # Replace with your own values
    
    $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 = "Script Complete"
    Write-Host "$Message"
    
    
  4. Atur nilai untuk variabel berikut di bagian atas skrip: $Domain, , $TemplateName, $ProfileName$Servers, $DnsSuffix, $DomainName, dan $DNSServers. Untuk informasi selengkapnya tentang cara mengatur variabel ini, lihat: VPNv2 CSP.

  5. Tekan ENTER untuk menjalankan skrip.

  6. Verifikasi bahwa skrip berhasil dengan menjalankan perintah berikut di Windows PowerShell ISE:

        Get-CimInstance -Namespace root\cimv2\mdm\dmmap -ClassName MDM_VPNv2_01
    
  7. Anda akan melihat output berikut (nilai ProfileXML telah dipotong untuk keterbacaan):

    
    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          : 
    `
    

Anda sekarang telah mengonfigurasi terowongan pengguna Anda untuk Always On VPN. Jika Anda ingin mempelajari cara mengonfigurasi terowongan perangkat, lihat Mengonfigurasi terowongan perangkat VPN di klien Windows.

Langkah berikutnya