none
DNS question RRS feed

  • Question

  • How can I find the CNAME for a server using nslookup or any other command.

    How to extract all CNAMES from all DNS zones on a DNS server.

    Monday, February 8, 2016 4:35 PM

Answers

  • Hi,

    You will need to have direct access to the server or administrative access for remote management to enumerate all zones and resource records, then filter this for CNAMEs.  For example:

    PS C:\> Get-DnsServerResourceRecord -ComputerName DC1.contoso.com -ZoneName contoso.com -RRType CNAME

    HostName                  RecordType Timestamp            TimeToLive      RecordData
    --------                  ---------- ---------            ----------      ----------
    foo                       CNAME      0                    01:00:00        ipam1.contoso.com.

    Please understand that this command requires administrator permissions on the server. 

    To run this command for all zones on the server, just pipe in Get-DnsServerZone

    PS C:\> Get-DnsServerZone | Get-DnsServerResourceRecord -ComputerName DC1.contoso.com -RRType CNAME

    HostName                  RecordType Timestamp            TimeToLive      RecordData
    --------                  ---------- ---------            ----------      ----------
    f881579c-1d62-4260-b08... CNAME      2/10/2016 10:00:0... 00:10:00        dc1.contoso.com.
    foo                       CNAME      0                    01:00:00        ipam1.contoso.com.

    Thanks,

    -Greg


    Thursday, February 11, 2016 6:57 AM
    Owner

All replies

  • I have documented what you need to achieve here: http://social.technet.microsoft.com/wiki/contents/articles/29184.nslookup-for-beginners.aspx#Zone_Transfer

    This posting is provided AS IS with no warranties or guarantees , and confers no rights.

    Ahmed MALEK

    My Website Link

    My Linkedin Profile

    My MVP Profile

    Tuesday, February 9, 2016 12:07 AM
  • The set type=CNAME does not work. It displays the CNAME for a domain name, however I want to check the CNAME of one particular server.

    Also I want to dump all the CNAMES from all the zones in DNS.


    • Edited by samb789 Tuesday, February 9, 2016 12:34 PM
    Tuesday, February 9, 2016 12:30 PM
  • Hi,

    You will need to have direct access to the server or administrative access for remote management to enumerate all zones and resource records, then filter this for CNAMEs.  For example:

    PS C:\> Get-DnsServerResourceRecord -ComputerName DC1.contoso.com -ZoneName contoso.com -RRType CNAME

    HostName                  RecordType Timestamp            TimeToLive      RecordData
    --------                  ---------- ---------            ----------      ----------
    foo                       CNAME      0                    01:00:00        ipam1.contoso.com.

    Please understand that this command requires administrator permissions on the server. 

    To run this command for all zones on the server, just pipe in Get-DnsServerZone

    PS C:\> Get-DnsServerZone | Get-DnsServerResourceRecord -ComputerName DC1.contoso.com -RRType CNAME

    HostName                  RecordType Timestamp            TimeToLive      RecordData
    --------                  ---------- ---------            ----------      ----------
    f881579c-1d62-4260-b08... CNAME      2/10/2016 10:00:0... 00:10:00        dc1.contoso.com.
    foo                       CNAME      0                    01:00:00        ipam1.contoso.com.

    Thanks,

    -Greg


    Thursday, February 11, 2016 6:57 AM
    Owner
  • Thanks for the reply. In the command below:

    Get-DnsServerResourceRecord -ComputerName DC1.contoso.com -ZoneName contoso.com -RRType CNAME

    We are mentioning the name of the Domain controllers. However if I have a member server and I want to know what are the CNAMES for that member servers across all zones in DNS, how can I achieve that?

    Or even if I want to list all the all CNAMES for the member server, in a particular zone, how can I achieve this?

    Thursday, February 11, 2016 1:25 PM
  • Hi,

    It doesn't matter if the server is a domain controller or member server.  In the example I used a DC but you can use any server running DNS.

    The first example gives all CNAMEs for a particular zone:

    Get-DnsServerResourceRecord -ComputerName <servername> -ZoneName <zonename> -RRType CNAME

    Thanks,

    -Greg

    Thursday, February 11, 2016 2:30 PM
    Owner
  • That is what my member server is not running DNS. And my question is: Suppose I have a member server called xyz.contoso.com and it has three CNAMES.

    I want a command to pull all the CNAMES for the server xyz in a particular zone and all zones on DNS.

    I do not want to pull all the CNAMES present in a particular zone.

    Tuesday, February 16, 2016 12:28 PM
  • Hi,

    I have already answered this question.  To get all CNAMEs in all zones:

    Get-DnsServerZone | Get-DnsServerResourceRecord -ComputerName <DNS server> -RRType CNAME

    Tuesday, February 16, 2016 2:49 PM
    Owner
  • I am not sure if I am not able to explain it correctly. In this command where am I mentioning the server name for which I want to get the CNAMEs for?

    These  two commands will either pull all the CNAMES in a particular zone on a particular DNS server or it will pull all the CNAMES for all the zones on the DNS server.

    I just want to pull the CNAMES for a particular member server ( which is not a DNS server). In this command I am putting the name of the DNS server but where am I putting the name of the server for which I want to pull the CNAME for?

    Tuesday, February 16, 2016 3:13 PM
  • The name of the server is after -ComputerName, for example:

    -ComputerName <DNS Server>

    Sorry - I noticed that you need to add -ComputerName to the first command also if you are running the command from a remote server.

    Try this:

    Get-DnsServerZone -ComputerName <DNS Server> | Get-DnsServerResourceRecord -ComputerName <DNS server> -RRType CNAME

    --------------

    This is how the command works:

    Get-DnsServerZone <--- gets a list of all DNS zones on the current server

    Get-DnsServerZone -ComputerName myserver.mydomain.com <---- gets a list of all DNS zones on myserver.mycomain.com

    Get-DnsServerResourceRecord -ZoneName myzone.net -RRType CNAME  <---- gets a list of all CNAMEs in the zone "myzone.net" on the current server

    Get-DnsServerResourceRecord -ComputerName mysever.mydomain.com -ZoneName myzone.net -RRType CNAME  <---- gets a list of all CNAMEs in the zone "myzone.net" on the server myserver.mydomain.com

    You can combine the commands to get all zones, and then get all the CNAMEs in those zones

    Get-DnsServerZone | Get-DnsServerResourceRecord -ZoneName myzone.net -RRType CNAME  <---- gets all CNAMEs in all zones on the current server

    Get-DnsServerZone -ComputerName myserver.mydomain.com | Get-DnsServerResourceRecord -ComputerName myserver.mydomain.com -RRType CNAME  <--- gets all CNAMEs in all zones on the server myserver.mydomain.com

    I hope this helps,

    -Greg

    Tuesday, February 16, 2016 3:30 PM
    Owner
  • It looks a little complicated because the command is long, but it is really simple.  There are two commands:

    Get-DnsServerZone

    Get-DnsServerResourceRecord

    To get data from a remote server, not the server you are logged onto already, you must add the -ComputerName option and specify where you want to pull the list of zones or resource records.

    For the second command, you can limit the resource records by type using the -RRType option and if you wish you can limit the zones to specific zones using the -ZoneName option.

    Lastly, you can "pipe" the commands together if desired so that you get the list of zones, then get all the resource records from those zones.  A pipe is a "|" symbol.

    Get-DnsServerZone | Get-DnsServerResourceRecord

    -Greg

    Tuesday, February 16, 2016 3:35 PM
    Owner
  • I am getting this error:

    PS C:\Users\> Get-DnsServerZone -ComputerName <name of DNS server> | Get-DnsServerResourceRecord -ComputerName <name of member server> -RRType CNAME

    Get-DnsServerZone : Failed to enumerate zones from the server <name of DNS server>.
    At line:1 char:1
    + Get-DnsServerZone -ComputerName <name of DNS server> | Get-DnsServerRe ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : PermissionDenied: (<name of DNS server>:root/Microsoft/...S_DnsServerZone) [Ge
       t-DnsServerZone], CimException
        + FullyQualifiedErrorId : WIN32 5,Get-DnsServerZone

    I have domain admin rights.

    Tuesday, February 16, 2016 4:24 PM
  • Did you edit the error and change the name of the DNS server to "<name of DNS server>" ?
    I guess you did otherwise you would get a different error.

    It's a permission problem, perhaps with PS remoting. Are you sure you have administrator rights on the remote server?

    Try this:

    PS C:\> Enter-PSSession -ComputerName dc1.contoso.com
    [dc1.contoso.com]: PS C:\Users\user1\Documents>

    Replace dc1.contoso.com with the name of your DNS server.

    What happens?

    If you get permission denied, try logging onto that server and typing this:

    Enable-PSRemoting

    -Greg


    Tuesday, February 16, 2016 5:12 PM
    Owner
  • Ahh.. wait I see the problem.

    Your prompt shows that you aren't running as Administrator.

    Open an elevated powershell window and try it again.

    -Greg

    Tuesday, February 16, 2016 5:24 PM
    Owner
  • Thanks for your response. The command you gave works. However in the below command:

    Get-DnsServerZone -ComputerName <DNS Server> | Get-DnsServerResourceRecord -ComputerName <DNS server> -RRType CNAME

    At both places, I am mentioning the name of the DNS server. However I have a CNAME as below:

    hrprod Alias (CNAME) us-xyz.contoso.com

    I want a command to pull the CNAME of the server: us-xyz.contoso.com, so it should only return one value called: hrprod and if there is no CNAME it should not pull anything.

    The server us-xyz.contoso.com is a web server which has a CNAME in DNS.

    I am nowhere mentioning the name of the member server is the above command.

    Tuesday, February 16, 2016 5:50 PM
  • Sorry I am not sure exactly what you need.

    Are you asking how to list only certain CNAMEs?

    You can add the -Name parameter and this will check for whatever name you specify and only list those that match, but you'll get a "failed to get record" error for a lot of zones.

    You can also just use findstr to filter the results:

    PS C:\> get-dnsserverzone -computername dc1.contoso.com | get-dnsserverresourcerecord -computername dc1.contoso.com -RRType cname | findstr -i foo
    foo                       CNAME      0                    01:00:00        ipam1.contoso.com.
    PS C:\>

    Tuesday, February 16, 2016 7:42 PM
    Owner
  • Yes I wanted to pull certain CNAMES. Thanks the findstr command works.

    You earlier command also work if I want to pull all CNAMES in a zone or all the CNAMES on all zones on a DNS server.

    Thanks a lot for your help.

    Wednesday, February 17, 2016 9:39 AM