3

I've created a function that works perfectly within the same domain.
It can take a name like "Win7-Alpha" and return "Win7-Alpha.Alpha.ca" when being used on the "Alpha.ca" Domain.

public static string TryGetServerFQDN(string ServerName)
{
    string ServerFQDN = ServerName;
    if (!string.IsNullOrEmpty(ServerName))
    {
        IPHostEntry serverIPEntry = null;
        try
        {
            serverIPEntry = Dns.GetHostEntry(ServerName);
        }
        catch
        {
        }

        if (serverIPEntry != null && !string.IsNullOrEmpty(serverIPEntry.HostName))
        {
            ServerFQDN = serverIPEntry.HostName;
        }
    }
    return ServerFQDN;
}

However, if I try the very same thing on the "Beta.ca" Domain, it only returns "Win7-Alpha". It is able to resolve the IPv4 Address if it is passed instead, but again, it only returns "Win7-Alpha".... I don't want just "Win7-Alpha", I want the FQDN!

On Beta.ca DNS I can see the FQDN that I want so why won't it give it to me?

DNS on Beta.ca

Lauren Van Sloun
  • 1,070
  • 5
  • 17
  • 20
C Sharp Conner
  • 338
  • 1
  • 10

1 Answers1

1

It appears that Microsoft has done some very questionable coding practices. From what I can tell, Windows won't give you the FQDN name from another domain, but you can set up a DNS Suffix List that will force querying a name with Domain suffixes. This appears to force Windows to search for an entry that matches the FQDN (even though it can do this with just the hostname). The difference is when it return the IP Address and the name it used, the name it used was the FQDN it created from the List you specified.

I have verified that once I had the machine with the list, I was able to use my function and it would resolve the HostName from another domain to the correct FQDN.

On the machine itself

  1. Click Start
  2. Search for "Network and Sharing Center"
  3. Click "Change adapter settings"
  4. For each Adapter, Right Click it and select Properties
  5. Click either Internet Protocol Version 6 (TCP/IPv6) or Internet Protocol Version 4 (TCP/IPv4)
  6. Click "Properties" button
  7. Click "Advanced..." button
  8. Click DNS Tab
  9. Select Option "Append these DNS suffixes (in order)"
  10. Click "Add..." and add the domain you are on first
  11. Repeat click "Add..." and add each domain you might need the FQDN from.
  12. Again, ensure the top of the list is the domain this machine is on
  13. Click OK on the Advanced TCP/IP Settings Window
  14. Click OK on the Internet Protocol Properties Window
  15. Click "Close" or "OK" on the Adapter Properties Window
  16. Try pinging a computer by name on a different domain, you should see the FQDN returned.
  17. You can also IPv4 ping via "ping -4 COMPUTERNAME"
  18. If it doesn't appear working:
    • Open cmd.exe as Admin
    • ipconfig /flushdns
    • ipconfig /registerdns

Or Using Group Policy

  1. Run Group Policy Management with sufficient Domain/Forest Administrator Credentials
  2. Select what Policy you want to alter. In this example, Default Domain Policy
  3. Right Click and choose Edit
  4. Navigate down to [Computer Configuration > Policies > Administrative Templates > Network > DNS Client]
  5. Open "DNS Suffix Search List"
  6. Select "Enable"
  7. In the DNS Suffixes textbox, type your Comma separated DNS Suffixes. Ex. We are on Beta.ca domain, so we type Beta.ca,Alpha.ca
  8. Click OK or Apply then close the Windows
  9. If you need to policy to apply to a machine ASAP, on the machine you can open cmd.exe and type gpupdate /force

I personally think it is so incredibly stupid that DNS can match an IP address or the HostName FROM ANOTHER DOMAIN.... it finds the record but it won't give you back the FQDN of the record WHICH IT APPEARS TO KNOW WHEN YOU LOOK AT THE RECORD, IT APPEARS TO BE RIGHT THERE! ... but you can't have it unless you hardcode a list of DNS Suffixes and then you get the FQDN back which then makes the code work properly. Very poor performance indeed!

//Once you add Alpha.ca to the DNS Suffix List on the machine running this code....
//This will now correctly return Win7-Alpha.Alpha.ca
Dns.GetHostEntry("Win7-Alpha").HostName;

DNS Suffix present to create FQDN

C Sharp Conner
  • 338
  • 1
  • 10