Find AD hostname from Linux command line

G

google

We have a large pool of Windows XP machines that receive their IP
addresses via a Linux-based DHCP server. These IP addresses are pooled
and are not statically assigned, so at any given moment a particular
machine can have any one of several IP addresses.

To minimize confusion, we have these Windows XP machine automatically
register themselves with the college's Active Directory, so, even
though the IP address for a given machine may change, its Windows
machine name does not change.

For example, I will set up a workstation with machine name "lancelot".
After it boots, if I log onto a Windows machine and do a ping against
"lancelot.ad.mydomain.com" I will get a response.

Now the problem: I have a Linux server that needs to know this
machine's Windows name (i.e., "lancelot") given the machine's (current)
IP address. If I do a simple nslookup on this IP address I get
something like "dhcp-27.mydomain.com" rather than the desired
"lancelot.ad.mydomain.com".

I understand I could use some kind of NETBIOS name resolution using
samba, but is there any other way? Is there a way to query the Active
Directory server directly using simple Linux tools to get the machine
name?
 
K

Kurt

A couple of possibilities. Most likely the Linux DHCP server is assigning
the hostname that is being registered in DNS. You should be able to turn
that off on the DHCP server and the Windows box by default will use its
NetBIOS name (computername) as it's hostname.

If you do an nslookup from the Windows box you should get the same results
as you do on the Linux box. If not, then the source of the DNS names must be
different DNS servers. To check the hostname on an XP box, just type
"hostname' at the command prompt (at least that works on Server 2003).

Also, I'm not sure whether you were being specific in your post as far as
the reverse lookup resolution goes, but ad.mydomain.com and mydomain.com are
two different zones.

....kurt
 
G

google

I don't want to turn off the Linux DHCP server from assigning the IP to
the Windows machine. And I have to allow the Active Directory to
continue to do whatever it is does when it assigns a "hostname" of the
form *.ad.mydomain.com. What I want to do is from the Linux server find
out what name the AD server assigned the Windows client given the
Windows client's IP address.

Yes, there are two different zones at work here: how do I query the AD
server to find out what it thinks the Windows machine name is? A simple
"nslookup 192.168.10.11" always returns the *.mydomain.com hostname,
whereas I want to get the *.ad.mydomain.com result.
 
H

Herb Martin

I don't want to turn off the Linux DHCP server from assigning the IP to
the Windows machine.

Not the IP, but the HOSTNAME from DHCP.

But I would also check that the Computer involved has a FULL
DNS name (with suffix) listed in its SYSTEM CONTROL Panel
(not on the NIC which is generally irrelevant.)
 
K

Kurt

I don't want to turn off the Linux DHCP server from assigning the IP to
the Windows machine.

Didn't suggest that, although I don't know why you don't just let the
windows server do this. Integration between DHCP and DNS is soooo easy that
way. What I suggested is that the hostname is possibly being assigned to the
DHCP clients by the DHCP server. As I said, Windows boxes use their
computernames as hostnames by default. Since your computers are registered
as something different, it would appear (from the limited information we
have to work with here) that a good possibility is that the DHCP server is
assigning the hostname. You can disable that one feature on the DHCP server
(not the whole DHCP server). I also gave you a method of checking whether or
not the hostname on an XP workstation is the same as it's NetBIOS name, by
typing "hostname" at a command prompt. That should tell you with certainty
that the hostname of the computer is different than it's computername. Just
how it got to be different will require more info to solve. Maybe it's not
different. We'll never know until you check it out and post what you find.
And I have to allow the Active Directory to
continue to do whatever it is does when it assigns a "hostname" of the
form *.ad.mydomain.com.

Active directory does not assign hostnames.
What I want to do is from the Linux server find
out what name the AD server assigned the Windows client given the
Windows client's IP address.

Once again, AD does not assign hostnames.
Yes, there are two different zones at work here: how do I query the AD
server to find out what it thinks the Windows machine name is? A simple
"nslookup 192.168.10.11" always returns the *.mydomain.com hostname,
whereas I want to get the *.ad.mydomain.com result.

That is what is listed in the reverse lookup zone. You'll have to find out
how your reverse lookup zones are being updated. Once again, do you get the
same result from an nslookup on one of the windows boxes? Maybe the Linux
box has static entries in it's hosts file? Maybe the reverse zone was set up
manually on the DNS server? Once again, step by step until you can pinpoint
where the descrepencies lie.

....kurt
 
G

google

I have control over neither the AD servers nor the DHCP servers that
hand out the IP addresses. But here is a description of the _symptoms_
and what I need to find out.

1. The Windows XP workstation gets an IP (say, 192.168.10.11) from some
non-Windows DHCP server. The IP is registered in the normal (i.e.,
non-Windows) way as something like "dhcp-036.mydomain.com". (Note: The
IP it gets is not really private.)

2. The Windows workstation has the computer name (e.g., "lancelot")
assigned manually when it is built. So, in our situation the hostname
will _always_ be different than the computer name. That the two names
are different is not the issue.

3. This Windows workstation has a single NIC which has the option
"Register this connection's addresses in DNS" turned ON. According to
the help for this option this means that the workstation will try to do
a dynamic registration of the IP address with the full computer name.
As there is only one Active Directory on our college campus, I presume
that this dynamic registration happens with one of the college's AD
servers. As the Windows XP's computer name is "lancelot" I am guessing
that the reverse mapping "lancelot.ad.mydomain.com" to 192.168.10.11 is
recorded somewhere in the guts of the Active Directory.

4. Thus, if log onto a Windows machine that is part of the Active
Directory and type "ping dhcp-036.mydomain.com" or "ping
lancelot.ad.mydomain.com" in both cases I get responses from the same
address, as expected.

5. If I am on a Linux server and do "ping lancelot.ad.mydomain.com",
not surprisingly I get a complaint that it cannot resolve the hostname.


QUESTION: I want a script that will run on a Linux server and that when
given an IP address will return the computer name of the Windows client
that registered that IP dynamically with the Active Directory, if there
is one. (The IP address of the local AD domain controller would be
built-in to the script.) In my running example, I would type something
like "computername 192.168.10.11" and get back "lancelot". What tool
that runs on Linux will enable me to direct a query of this nature
against an Active Directory domain controller?
 
K

Kurt

1. The Windows XP workstation gets an IP (say, 192.168.10.11) from some
non-Windows DHCP server. The IP is registered in the normal (i.e.,
non-Windows) way as something like "dhcp-036.mydomain.com". (Note: The
IP it gets is not really private.

AHA! Registered where? And by what?
2. The Windows workstation has the computer name (e.g., "lancelot")
assigned manually when it is built. So, in our situation the hostname
will _always_ be different than the computer name. That the two names
are different is not the issue.

That's not necessarily true, in fact it's usually not true, but since you
still haven't checked I'll go with that.
3. This Windows workstation has a single NIC which has the option
"Register this connection's addresses in DNS" turned ON. According to
the help for this option this means that the workstation will try to do
a dynamic registration of the IP address with the full computer name.

The key word there is "try".
As there is only one Active Directory on our college campus, I presume
that this dynamic registration happens with one of the college's AD
servers. As the Windows XP's computer name is "lancelot" I am guessing
that the reverse mapping "lancelot.ad.mydomain.com" to 192.168.10.11 is
recorded somewhere in the guts of the Active Directory.

Only if it's set up that way. Although Active Directory relies on DNS for
much of it's functionality, DNS can be entirely separate. The reverse zone
is really not required for AD to function, although most admins use it to
locate computers, for example, when sniffing the wire where IP addresses,
not names, are in packet headers.
4. Thus, if log onto a Windows machine that is part of the Active
Directory and type "ping dhcp-036.mydomain.com" or "ping
lancelot.ad.mydomain.com" in both cases I get responses from the same
address, as expected.

5. If I am on a Linux server and do "ping lancelot.ad.mydomain.com",
not surprisingly I get a complaint that it cannot resolve the hostname.

If the windows box and the Linux box are using the same DNS server, they
should both be able to resolve the same names. In the end, the only thing
that matters when looking up a name is what's in the DNS database on the DNS
server being queried. So go to a Windows box, open a terminal, and type
"ipconfig /all". Note the address of the DNS server. Then go to a linux
server and type "nslookup lancelot.ad.mydomain.com x.x.x.x" where x.x.x.x
is the IP address of the DNS server you got form ipconfig /all on the
Windows box. See if it can now resolve the name. If so, it means that the
linux box is using a different DNS server than the windows box (or some
other form of name resolution altogether, i.e HOSTS).

QUESTION: I want a script that will run on a Linux server and that when
given an IP address will return the computer name of the Windows client
that registered that IP dynamically with the Active Directory, if there
is one.

Windows hosts don't register themselves in Active Directory, they register
themselves in DNS - IF the DNS server is configured to accept that
registration. Just because the client is configured to register itself
doesn't mean the server is configured to allow it. Most Active Directories
host their own DNS, but it's not required. If the campus uses Linux for
DHCP, it wouldn't surprise me if they were also using Linux for DNS. BIND 9
can be configured to accept dynamic DNS registrations from clients, although
security is more difficult to configure because it lives outside the Active
Directory security model.

(The IP address of the local AD domain controller would be
built-in to the script.) In my running example, I would type something
like "computername 192.168.10.11" and get back "lancelot". What tool
that runs on Linux will enable me to direct a query of this nature
against an Active Directory domain controller?

nslookup will do just fine, but once again you're querying the DNS server
for the AD domain (which is probably a domain controller, but not
necessarily). You just need to specify the address of the DNS server you
want to query in your nslookup command. You really don't need a script
unless you're calling it from another application. In fact I have a native
linux program written in C that calls nslookup to resolve names.

Just a bit of history which may help clear this naming thing up for you. A
windows "computername" is a leftover from a time before Windows networks
used TCP/IP. NetBIOS was the protocol, and NetBEUI was the transport. This
was an entirely broadcast-based system where computers coming on line would
announce themselves to the network and in turn receive a "browse list" from
the "master browser". That's what showed up in "network neighborhood". It
only worked on non-routed networks. In fact, NetBIOS over NetBEUI is not
routable. When networks grew to the point that they needed to be routed,
NetBIOS was patched into TCP/IP so that it could cross routed boundaries.
Because broadcasts are contained inside routed boundaries, the old
broadcast-based announcement wouldn't work, so WINS was invented. Much like
DNS (though not heirarchical), the WINS server could be queried for the
NetBIOS name (computername) of the windows node, and the IP address was
returned. It cut down on broadcasts and allowed unicasts between subnets to
a common server for name resolution. Windows computers register themselves
in WINS when they start up. The "browse list" was then learned from the WINS
server so computers on both sides of the router were visible in "Network
Neighborhood".

With the growth of the Internet and the need for a heirarchical structure
in - by now very large - corporate networks, it made sense to use the name
resolution method designed specifically to service the IP addressing scheme
(that MS was already using along with TCP as an addressing and transport
protocol suite). So DNS was incorporated. Since most networks used (still
use) a combination of DNS and NetBIOS (people still rely on "My Network
Places - still NetBIOS based), it made it less confusing for users if the
NetBIOS name and the DNS name were the same. NetBIOS uses the computer name
and DNS uses the hostname. 99% of the time they are the same. The "fully
qualified" DNS name is the hostname + the DNS heirarchy. So lancelot's
computername is it's NetBIOS name, just "lancelot". Normally it's hostname
would be the same, and it' FQDN would be lancelot.ad.mydomain.com. Members
of the ad.mydomain.com domain will automatically have the DNS suffix added
on to the hostname when making DNS queries, so "nslookup lancelot" from a
member computer works just as well as "nslookup lancelot.ad.mydomain.com".
And Windows is usually configured to try WINS if DNS resolution is not
available and vice versa. But it does confuse things. Where did the name
resoluton come from? And then to make matters even more confusing, NetBIOS
names CAN be different from hostnames. In fact this is common when naming
active directory domains (which use the same structure as DNS, and use DNS
for resolution, but are independent from DNS itself). If an organization's
domain is "SuperOpticalServices.local", the NetBIOS name is likely to be
SOS, just so we lazy admins don't have to type the whole thing out. Anyway,
that's why there are so many short names, long names, resolution methods,
cross-referencing, etc in a Windows network. Linux networks are much simpler
with just DNS.

....kurt
 
H

Herb Martin

I have control over neither the AD servers nor the DHCP servers that
hand out the IP addresses. But here is a description of the _symptoms_
and what I need to find out.

You seem to have several fundamental misconceptions
about DNS, AD, how and where registration occurs so
read this entire message.
1. The Windows XP workstation gets an IP (say, 192.168.10.11) from some
non-Windows DHCP server. The IP is registered in the normal (i.e.,
non-Windows) way as something like "dhcp-036.mydomain.com". (Note: The
IP it gets is not really private.)

Does the DHCP server register this name or is it manually
(and thus permanently) registered?

Is "Mydomain.com" the same domain (name) as the AD?

2. The Windows workstation has the computer name (e.g., "lancelot")
assigned manually when it is built. So, in our situation the hostname
will _always_ be different than the computer name. That the two names
are different is not the issue.

FIX THIS. The Windows name NEEDS to be (in the System Control
Panel) "lancelot.mydomain.com" (or the correct AD domain name.)

Windows machines cannot register themselves UNLESS they know
their domain/zone name.
3. This Windows workstation has a single NIC which has the option
"Register this connection's addresses in DNS" turned ON. According to
the help for this option this means that the workstation will try to do
a dynamic registration of the IP address with the full computer name.

Yes, but note that you need a SUFFIX to pick the Zone/Domain in
which it is to be registered.

And don't depend on setting the suffix on the NIC (that is mostly for
dual homed machines) but rather SET THE NAME in the SYSTEM
CONTROL panel.
As there is only one Active Directory on our college campus, I presume
that this dynamic registration happens with one of the college's AD
servers.

No, it must happen with your DNS servers for the ZONE of the
machine name set in the SYSTEM CONTROL Panel.

That the DC happens to be the DNS server is merely an accident
(from the client's perspective.)
As the Windows XP's computer name is "lancelot" I am guessing
that the reverse mapping "lancelot.ad.mydomain.com" to 192.168.10.11 is
recorded somewhere in the guts of the Active Directory.

Not unless you set the COMPUTER name and DOMAIN in the
SYSTEM CONTROL PANEL to "lancelot.ad.domain.com" will
the FORWARD name be set.

As to the reverse that is an entirely separate registration which
must be in the REVERSE zone (there is no direct relationship
between forward and reverse zones to the DNS servers -- this
relationship is all in the minds of us administrators.)

You must have the forward zone set to ALLOW dynamic registration
and if you want the reverse records dynamically registered you
must also have it set to accept them SEPARATELY.

Each zone, forward OR reverse, is configured separately.
4. Thus, if log onto a Windows machine that is part of the Active
Directory and type "ping dhcp-036.mydomain.com" or "ping
lancelot.ad.mydomain.com" in both cases I get responses from the same
address, as expected.

Then forward registration is happening as expected and someone
has already set up (manually probably) the alternate name.
5. If I am on a Linux server and do "ping lancelot.ad.mydomain.com",
not surprisingly I get a complaint that it cannot resolve the hostname.

Presuming you tried #4 from a differnet machine, this is NOT a
DNS registration problem but a RESOLUTION issue.

My bet (with the presumption being confirmed) is that the UNIX
box is using a "different set of DNS servers" OR (most likely) the
PARENT zone server (mydomain.com) has never bothered to
DELEGATE to the Windows DNS server for the ad.mydomain.com
zone.

QUESTION: I want a script that will run on a Linux server and that when

Why would you expect Windows to have a script that would run on
a Linux server? (You'll have to write such a thing.)
given an IP address will return the computer name of the Windows client
that registered that IP dynamically with the Active Directory, if there
is one.

No, not unless you can get the reverse record registered or you
write something custom.

First, computer names do NOT get registered with AD, but rather
with DNS. (That AD requires an 'associated' DNS server/zone
is important but note that it is the DNS which holds the name to
address mappings and these are optional for NON-DCs.)

Presuming you have no control of the reverse zone (which is
quite common), I can think of a way to do it but it won't be
pretty and must run with either admin privileges or from a
machine which can list the zone (usually disabled on all but
secondaries.)

You could use DNScmd on a DNS server to produce a list
and make it available to your Linux server which could run
a script to process it for the reverse record.
(The IP address of the local AD domain controller would be
built-in to the script.)

Not necessary or even relevant. (Irrelevant since the DC
doesn't have the DNS registration -- that's the DNS server) and
unnecessary since you can simply query the DNS server for
the list of NameServers.

Then you would need a way to "list the zone" (which is usually
disabled for security reasons), either by using the nslookup
list command or by reading a file from a known location --
e.g., the file share name MIGHT need to be incoded. (I would
suggest "NetLogon" share IF (and only if) your DCs are also
your DNS servers for AD. The Netlogon share exists on all
DCs and is set to everyone Read (even unathenticated users
if you haven't secured your machines thoroughly.)
In my running example, I would type something
like "computername 192.168.10.11" and get back "lancelot". What tool
that runs on Linux will enable me to direct a query of this nature
against an Active Directory domain controller?

There isn't a single tool that could do that. You could write it in
Perl in just a few lines IF the security allows it.

Easier would likely be to have the main script run on the DNS
server and product the list of names to IPs and make it available,
then a simple grep or perl script from Linux could find the
record you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top