How to specify DNS server addresses for VPN connection permanetly with any command-line (without GUI operation)?

Max 26 Reputation points
2021-09-08T10:57:19.47+00:00

Dear professionals,

I just consiger automatic registration about VPN connection with static DNS name server address information by command line (e.g. PowerShell).

Add-VpnConnection -Name $vpnName -ServerAddress $serverAddress -RememberCredential ...

After successful registration with above command, I try to

Set-DnsClientServerAddress  -InterfaceAlias $vpnName -ServerAddress SSS.TTT.UUU.VVV

However, an error has occured as "No MSFT_DNSClientServerAddress objects found".

Next, switch the VPN to online, and execute above command. Then DNS server addresses looks affected.

ipconfig /all

   PPP Adapter ????:
   DNS Servers....:SSS.TTT.UUU.VVV

But it's temporary. So after disconnected and re-connected the VPN connection, that I/F has DNS server address information supplied by DHCP protocol.

    ipconfig /all

       PPP Adapter ????:
       DNS Servers....:DDD.EEE.FFF.GGG <- (supplied by DHCP server)

Let me know how to register the static DNS addresses to VPN connection permanently.

I will appreciate your support.

Max

Windows DHCP
Windows DHCP
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.DHCP: Dynamic Host Configuration Protocol (DHCP). A communications protocol that lets network administrators manage centrally and automate the assignment of Internet Protocol (IP) addresses in an organization's network.
1,023 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,381 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dave Patrick 426.1K Reputation points MVP
    2021-09-08T12:32:04.003+00:00

    Usually the VPN will inherit the DNS from the RRAS server's connection properties.

    --please don't forget to upvote and Accept as answer if the reply is helpful--


  2. Limitless Technology 39,366 Reputation points
    2021-09-08T14:13:11.46+00:00

    Hello Max,

    You can use the registry key: HKLM\System\CurrentControlSet\Services\Tcpip\Linkage\Bind

    This list the NIC GUIDs and their bindings and orders of preference for the adapter. This way you can establish the preference of your DNS setting over DHCP assignments.

    Follow this steps:

    Examine the Bind registry key
    Connect to your VPN connection
    Check the Bind key again and copy the GUID that was added to the top of the list
    Paste the GUID entry at the bottom of the list 20 times
    Export the key and clean up the exported file to only include the bind key

    Hope this helps in your query,

    Best regards,