What's the command to find the name of a computer given its IP address?
I always forget what this command is, but I know it exists in Windows and I assume it exists on the *nix command-line.
What's the command to find the name of a computer given its IP address?
I always forget what this command is, but I know it exists in Windows and I assume it exists on the *nix command-line.
The commands
dig
andhost
should be what you're looking for ;)On *nix systems, you can use this command:
Alternatively, you can add
+short
at the end of thedig
command to output only the DNS result.There's also
nslookup
on both *nix and Windows systems for reverse DNS requests.On *nix you can use:
Try "host"
Forward lookup with
host
:Reverse lookup with
host
:Similar to dig
Forward lookup with
dig
:Reverse lookup with
dig
:Try "rdt"
It takes a little more setup. But if you do this, then you can run this "rdt" PHP script from the command line and it's quite wonderful. It does a few back and forth trips between forward and reverse lookups.
Download from here: https://github.com/grawity/code/blob/master/net/rdt
Example. This is what it looks like when it's working:
On most of the Linux systems that I am aware of you can use:
will work on the command line.
Come to think of it, isn't nslookup available on Windows XP?
This question already has a million answers, but I'm gonna add another one. Here's a little function I wrote for easily doing reverse DNS with dig. Add this to your
~/.bashrc
file, reload your shell, and then you can do reverse DNS lookups withrevdns 1.2.3.4
:Reverse DNS lookups are done by checking the pointer (PTR) records. If you wanna do reverse DNS for "1.2.3.4", you have to lookup pointer records for "4.3.2.1.in-addr.arpa". My function takes in an IP address, reverses the order of the octets (i.e. changes it from 1.2.3.4 to 4.3.2.1), and then uses
dig
to execute the PTR lookup I just described.You can, of course, just use
nslookup 1.2.3.4
if you have it, but I prefer this dig-based solution because it uses the OS' DNS servers instead of nslookup-provided ones (if you want, by the way, you can add additional dig flags when you callrevdns
, and they will get passed to dig)I'm well aware that dig/host/nslookup are the standard tools for these, but I keep these around for testing the OS's resolution (essentially, to test nsswitch.conf is working correctly):
gethostbyname:
gethostbyaddr:
example:
On Windows I got in to the habit of using:
as this will also reflect data from your
hosts
file and WINS and so on.If you're using nslookup it's this (assuming 192.168.0.1 as the IP in question)
EDIT: Remember a reverse lookup only works if there is a PTR record created for the IP, and it's not guaranteed to return the hostname you're looking for. Completely depends on how DNS is configured and maintained in your situation.
Powershell:
I prefer the command-line dig for Windows (available here: http://members.shaw.ca/nicholas.fong/dig/) to nslookup any day.
If you have to test/administer DNS from a Windows workstation, grab this tool. Then:
...also, remember to add c:\dig to your path!