Can IOS do an nslookup?

Answered Question
Jul 7th, 2008
User Badges:

I have a switch configured to resolve hostnames, it works fine, if I ping xxx.xxx.local or whatever it looks up the IP and displays output.


Can this be done in reverse? So If I find an IP address in the arp table and want to resolve its hostname, is there a command like Windows nslookup that will allow for this?

Correct Answer by Joe Clarke about 8 years 11 months ago

There is nothing built-in, but attached is a Tcl script I wrote to do A and PTR DNS lookups using the IOS tclsh (in IOS 12.3(2)T or later, 12.2(18)SXF5 or higher, 12.2(40)SE or higher, etc.). Tclsh doesn't support UDP sockets right now, so my script uses TCP. It works similarly to the UNIX host command. If you do not specify a DNS server, it tries to obtain one by looking at the device's config. The usage is:


host.tcl address [dns_server]


For example:


Router#tclsh flash:host.tcl 10.1.1.1

1.1.1.10.in-addr.arpa domain name pointer host.company.com


Router#tclsh flash:host.tcl host.company.com

host.company.com has address 10.1.1.1


The script is pretty simplistic, but it should accomplish what you want.



  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 5 (2 ratings)
Loading.
Correct Answer
Joe Clarke Mon, 07/07/2008 - 21:40
User Badges:
  • Cisco Employee,
  • Hall of Fame,

    Founding Member

There is nothing built-in, but attached is a Tcl script I wrote to do A and PTR DNS lookups using the IOS tclsh (in IOS 12.3(2)T or later, 12.2(18)SXF5 or higher, 12.2(40)SE or higher, etc.). Tclsh doesn't support UDP sockets right now, so my script uses TCP. It works similarly to the UNIX host command. If you do not specify a DNS server, it tries to obtain one by looking at the device's config. The usage is:


host.tcl address [dns_server]


For example:


Router#tclsh flash:host.tcl 10.1.1.1

1.1.1.10.in-addr.arpa domain name pointer host.company.com


Router#tclsh flash:host.tcl host.company.com

host.company.com has address 10.1.1.1


The script is pretty simplistic, but it should accomplish what you want.



Attachment: 
Nish Vamadevan Tue, 11/16/2010 - 13:21
User Badges:

Thanks Joseph,


Added the alias to makes things easier and lazier...


#alias exec host tclsh flash:host.tcl

synack000 Wed, 11/28/2012 - 13:29
User Badges:

Joe,


The above link you posted is not working. Is the updated script still available?


Thanks.

jasonmadruga84 Thu, 10/08/2015 - 19:28
User Badges:

On my 2940 switch I can issue the traceroute command on an ip address and it will do a reverse DNS lookup. Be sure to remember the CTRL+Shift+6 handy as traceroute can go for a while sometimes.
 

Actions

This Discussion