• 4
Votes
name
name Punditsdkoslkdosdkoskdo

What is the reverse DNS command line utility?

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.

 

There is yet another way. Reverse the IP address and use nslookup

nslookup -type=PTR 4.3.2.1.in-addr.arpa

to resolve the address 1.2.3.4

  • 0
Reply Report

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:

#!/usr/bin/perl

use Socket;

my @t = gethostbyname($ARGV[0]);
print "$name     = $t[0]
"; shift(@t);
print "$aliases  = $t[0]
"; shift(@t);
print "$addrtype = $t[0]
"; shift(@t);
print "$length   = $t[0]
"; shift(@t);

foreach (@t) {
  print "          = ", inet_ntoa($_), "
";
}

gethostbyaddr:

#!/usr/bin/perl

use Socket;

my @t = gethostbyaddr(inet_aton($ARGV[0]), AF_INET);
print "$name     = $t[0]
"; shift(@t);
print "$aliases  = $t[0]
"; shift(@t);
print "$addrtype = $t[0]
"; shift(@t);
print "$length   = $t[0]
"; shift(@t);

foreach (@t) {
  print "          = ", inet_ntoa($_), "
";
}

example:

g3 0 /home/jj33/swap > gethostbyname www.google.com
$name     = www.l.google.com
$aliases  = www.google.com
$addrtype = 2
$length   = 4
          = 72.14.205.147
          = 72.14.205.103
          = 72.14.205.104
          = 72.14.205.99
g3 0 /home/jj33/swap > gethostbyaddr 72.14.205.147 
$name     = qb-in-f147.google.com
$aliases  = 
$addrtype = 2
$length   = 4
          = 72.14.205.147
  • 0
Reply Report

dig and host should be what you're looking for ;)

http://www.unix.com/unix-dummies-questions-answers/9866-nslookup-linux.html

On *nix system you can do this command : dig -x [address]

Alternatively you can add +short at the end of the dig command to output only the dns result.

On Windows, use nslookup

EDIT : nslookup work too on *nix systems. More infos on nslookup command whether it seems to have been replace since a while now : http://linuxreviews.org/man/nslookup/

  • 0
Reply Report