Share via


Query DNS to get all Aliases?

Question

Monday, November 18, 2013 10:32 PM | 1 vote

Greetings. I'm a SQL Server DBA, and advanced DNS is way beyond my realm, so please be gentle.

Several of our Production SQL boxes make use of Aliases, and we want to be able to run a query that ties Hosts to those Aliases. I've done some googling on this topic, and it really appears that there’s no good universal way to making this happen. Some go say far as to say it can't be done accurately, while others list fairly clunky methods.

Does anyone have a good method for this?

 Thanks!

 

TIA, ChrisRDBA

All replies (11)

Wednesday, November 20, 2013 9:44 PM ✅Answered

You can simply use nslookup.

C:>\nslookup   (Enter)

> type in name of alias.domain.com    (Enter)

Ace Fekay
MVP, MCT, MCITP/EA, MCTS Windows 2008/R2 & Exchange 2007, Exchange 2010 EA, MCSE & MCSA 2003/2000, MCSA Messaging 2003
Microsoft Certified Trainer
Microsoft MVP - Directory Services
Technical Blogs & Videos: http://www.delawarecountycomputerconsulting.com/

This post is provided AS-IS with no warranties or guarantees and confers no rights.


Wednesday, November 20, 2013 10:00 PM ✅Answered | 1 vote

Hello,

I don't know about SQL queries for DNS.. but if you want the CNAMEs for a given number of servers, you can use PowerShell:

File.txt contains: "Server1","Server2" ...

$Server=Get-Content -path .\File.txt

$Server | ForEach-Object {
Get-WmiObject -Namespace 'root\MicrosoftDNS' `
-Class MicrosoftDNS_CNAMEType `
-Filter "ContainerName = 'YourDomain'" `
-ComputerName $_  | 
Select-Object @{N='Alias'; E={$_.Ownername}}, Primaryname

Because it uses WMI, it will also work on Windows Server 2008 / R2

If you have Windows Server 2012 R2 you can check out this cmdlet.

Best regards,

Razvan Rusu


Tuesday, November 19, 2013 2:27 PM

Hi,

Based on my understanding, I don’t think it is possible to do this.

Can you elaborate what “run a query that ties Hosts to those Aliases” means?

Maybe you can provide some background information.

Thank you.


Wednesday, November 20, 2013 7:52 PM

I agree to provide actual names and examples of what you want to accomplish and the end results.

DNS is not that complex, however, there are numerous ways to make things work, and in some instances, there are no solutions. So it depends on what you are trying to accomplish.

Ace Fekay
MVP, MCT, MCITP/EA, MCTS Windows 2008/R2 & Exchange 2007, Exchange 2010 EA, MCSE & MCSA 2003/2000, MCSA Messaging 2003
Microsoft Certified Trainer
Microsoft MVP - Directory Services
Technical Blogs & Videos: http://www.delawarecountycomputerconsulting.com/

This post is provided AS-IS with no warranties or guarantees and confers no rights.


Wednesday, November 20, 2013 8:42 PM

So we have several SQL Servers. Some clusters, some not. Some of these boxes have DNS aliases associated with them, so pointing to more than one host name gets you to the same place.

However, this also causes confusion for obvious reasons when the number of servers you manage grows. I want to be able to run a query based on host name that will return all associated aliases. 

TIA, ChrisRDBA


Monday, November 25, 2013 7:54 PM

Hello,

I don't know about SQL queries for DNS.. but if you want the CNAMEs for a given number of servers, you can use PowerShell:

File.txt contains: "Server1","Server2" ...

$Server=Get-Content -path .\File.txt

$Server | ForEach-Object {
Get-WmiObject -Namespace 'root\MicrosoftDNS' `
-Class MicrosoftDNS_CNAMEType `
-Filter "ContainerName = 'YourDomain'" `
-ComputerName $_  | 
Select-Object @{N='Alias'; E={$_.Ownername}}, Primaryname

Because it uses WMI, it will also work on Windows Server 2008 / R2

If you have Windows Server 2012 R2 you can check out this cmdlet.

Best regards,

Razvan Rusu

My understanding is that wont work for our 2003 servers, will it?

TIA, ChrisRDBA


Monday, November 25, 2013 8:12 PM

I'm almost certain it works. It uses WMI, after all. Please run it, and in case it generates errors, come back here and we'll solve them.

Best regards,

Razvan Rusu


Tuesday, November 26, 2013 10:33 PM

$Server=Get-Content -path C:\Users\myName\Desktop\alias.txt
$Server | ForEach-Object {
Get-WmiObject -Namespace 'root\MicrosoftDNS' `
-Class MicrosoftDNS_CNAMEType `
-Filter "ContainerName = 'myDomain'" `
-ComputerName $_  | 
Select-Object @{N='Alias'; E={$_.Ownername}}, Primaryname

So I ran the block of code with a server name in double quotes in the alias.txt file. However, nothing happened. No error, no output, nothing. I've never used PS so please bear with my ignorance.

TIA, ChrisRDBA


Tuesday, November 26, 2013 10:37 PM

While in the folder where you saved the file as alias.ps1 file,open PowerShell command prompt, and run it as:

./alias.ps1

Ace Fekay
MVP, MCT, MCITP/EA, MCTS Windows 2008/R2 & Exchange 2007, Exchange 2010 EA, MCSE & MCSA 2003/2000, MCSA Messaging 2003
Microsoft Certified Trainer
Microsoft MVP - Directory Services
Technical Blogs & Videos: http://www.delawarecountycomputerconsulting.com/

This post is provided AS-IS with no warranties or guarantees and confers no rights.


Tuesday, November 26, 2013 11:22 PM | 1 vote

Also, run it as an administrator


Tuesday, December 3, 2013 8:34 PM

Now getting "Invalid namespace "root\MicrosoftDNS".

TIA, ChrisRDBA