Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Primary Dns Suffix programmatically?

Tags:

c#

dns

How to retrive Primary Dns Suffix programmatically in c#?

C:\Users\jdoe>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : ABC-PC
   --->Primary Dns Suffix  . . . . . . . : mdanshin.co.za<---
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : mdanshin.co.za
like image 795
Mikhail Danshin Avatar asked Nov 03 '15 16:11

Mikhail Danshin


People also ask

How do I get a DNS suffix?

In Windows 10:In the Internet Protocol (TCP/IP) Properties dialog box, click the Advanced button. Click the DNS tab in the Advanced TCP/IP Settings dialog box. Click the "Append these DNS suffixes (in order)" radio button. Now click the Add button to add DNS suffixes to the connection.

How do I find my DNS suffix in CMD?

To see if the DNS suffix search list was pushed by group policy, we can run command gpresult/h c:\gpreport. html with admin privileges to check group policy result.

How do I change DNS suffix in CMD?

There's no netsh command to configure the DNS suffixes, but you can use Group Policy to set the DNS suffix list. Go to Computer Configuration, Policies, Administrative Templates, Network, DNS Client and you can set the DNS Suffix Search List setting. You set the primary through the Primary DNS Suffix setting.

What is specific DNS suffix?

DNS Suffixes are text that are appended to a host name in order to query DNS for an IP address. DNS works by use of “Domains”, equitable to namespaces and usually are a textual value that may or may not be “dotted” with other domains.


1 Answers

So, Alex K's answer is not correct (sorry). That will give you the connection specific DNS information which can be different for each adapter. Consider the configuration below. One adapter will give a different answer.

The correct answer is:

 var primaryDnsSuffix = IPGlobalProperties.GetIPGlobalProperties().DomainName;

That will return the value in the line that says "Primary Dns Suffix"

IPInterfaceProperties.DnsSuffix Property

Multi-homed ipconfig /all output:

Windows IP Configuration

   Host Name . . . . . . . . . . . . : BOB
   Primary Dns Suffix  . . . . . . . : fred.george.com
   Node Type . . . . . . . . . . . . : Peer-Peer
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : fred.george.com
                                       george.com

PPP adapter Harry:

   Connection-specific DNS Suffix  . : fred.george.com
   Description . . . . . . . . . . . : Harry
   Physical Address. . . . . . . . . :
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.2(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.255
   Default Gateway . . . . . . . . . : 0.0.0.0
   DNS Servers . . . . . . . . . . . : 192.168.1.1
   Primary WINS Server . . . . . . . : 192.168.1.100
   Secondary WINS Server . . . . . . : 192.168.1.101
   NetBIOS over Tcpip. . . . . . . . : Enabled

   Ethernet adapter Ethernet 2:

   Connection-specific DNS Suffix  . : ron.george.com
   Description . . . . . . . . . . . : Realtek USB GbE Family Controller #2
   Physical Address. . . . . . . . . : 6B-21-CD-65-AC-25
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.3(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Lease Obtained. . . . . . . . . . : Friday, August 30, 2019 10:29:34 AM
   Lease Expires . . . . . . . . . . : Thursday, September 05, 2019 2:36:12 PM
   Default Gateway . . . . . . . . . :
   DHCP Server . . . . . . . . . . . : 192.168.1.1
   DNS Servers . . . . . . . . . . . : 192.168.1.102
                                       192.168.1.103
   NetBIOS over Tcpip. . . . . . . . : Disabled
   Connection-specific DNS Suffix Search List :
                                       george.com
like image 51
Reginald Blue Avatar answered Sep 28 '22 00:09

Reginald Blue