nslookup on Mikrotik

Is there a Mikrotik command equivalent to the Windows nslookup command?

to find out the IP address of some domain, just ping it. or you can use the “:resolve” command, if you need it in scripts:
[admin@MikroTik] > put [:resolve mt.lv]
159.148.147.196

Thanks. The command also works fine without the colon, i.e. put [resolve mt.lv]

This is true, but does not tell which dns server is resolving, which can be helpful…

you can specify target dns server to query easily:

put [resolve google.com server 8.8.8.8]

I have a static IP mapping for a host to resolve to an internal IP. However, in my script I want to resolve the public IP by using an external DNS server. Seems simple enough with the ":resolve [server=1.2.3.4]" script command, but it's not working for me. It seems the :resolve command is always using local router DNS and ignoring the server=1.2.3.4 argument. Here's the example:

[admin@rb1.magrathea] > put [:resolve host.fqdn server=8.8.4.4]
172.16.42.25

But it's wrong, for example:

[root@nas1] ~# nslookup host.fqdn 8.8.8.8
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   host.fqdn
Address: 216.58.218.206

I have no redirect rules on the router, as evidenced by the above host using nslookup on the LAN through that same router.

Ideas?

Edit: version is:

feb/23/2016 18:17:54 by RouterOS 6.35rc12

Friendly bump to see if anyone has tips for forcing the :resolve command to use an external server?

Old thread.

Just confirm that this works fine for me on 6.39

[user@GV-FV155] > put [resolve remote.my-server.com]
10.10.10.32
[user@GV-FV155] > put [resolve remote.my-serve.com server 8.8.8.8]
92.xxx.xxx.134
[user@GV-FV155] >

Hello, all

NO! How can I discover DNServer? Which server return address? (Yeah, I have a very long list DNS and I am use every server.)

(FREEBSD 9.3 nonroot command line)
$ nslookup g.cn
Server: 8.8.8.8 // WHO tell about adress?
Address: 8.8.8.8#53 // allright, about g.cn google DNS well known. Und das ist fantastisch, I can see NS port number! Mikrotik can it?
Non-authoritative answer:
Name: g.cn
Address: 173.194.73.94

Or is it difficult to implement and understand?
Danke schoen.

when you use nslookup it will give you the DNS name of site (and also resolver IP and name)
what is the nslookup like command in mikrotik
Windows example:

nslookup 8.8.8.8
Server:  *******
Address:  10.5.50.177

Name:    google-public-dns-a.google.com
Address:  8.8.8.8

Linux example

nslookup microsoft.com

…and you would receive a response like this:

Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:    microsoft.com
Address: 134.170.185.46
Name:    microsoft.com
Address: 134.170.188.221

nice one, i thought MT didn’t support that one

Yes, you have to assume that the DNS server that replied is the DNS server that you (or the router) specified.
The [:resolve “microsoft.com”] is a script command, it is not really a troubleshooting tool. I have a number of scripts that relay on [:resolve “microsoft.com”] returning just a single IP-address, any change to it would break scripts for a lot of people.

It would be nice with a real “NSLOOKUP”-style troubleshooting tool though.

In RouterOS version 6.36 and newer, you can also use address lists to get a list of IP-addresses that the DNS name resolve as.

[admin@MikroTestRouter] > /ip firewall address-list add address="microsoft.com" list="list1"
[admin@MikroTestRouter] > /ip firewall address-list print where list="list1"
Flags: X - disabled, D - dynamic 
 #   LIST                  ADDRESS                                    CREATION-TIME        TIMEOUT
 0   list1                 microsoft.com                              oct/02/2019 11:38:55
 1 D ;;; microsoft.com
     list1                 40.112.72.205                              oct/02/2019 11:38:55
 2 D ;;; microsoft.com
     list1                 40.113.200.201                             oct/02/2019 11:38:55
 3 D ;;; microsoft.com
     list1                 104.215.148.63                             oct/02/2019 11:38:55
 4 D ;;; microsoft.com
     list1                 13.77.161.179                              oct/02/2019 11:38:55
 5 D ;;; microsoft.com
     list1                 40.76.4.15                                 oct/02/2019 11:38:55
[admin@MikroTestRouter] > /ip firewall address-list remove [find list="list1" !dynamic]

is there a way to get this output as a variable?

this code runs only in terminal.. how do I translate this so it can run on script?

:do {
:put [:resolve www.example.com];
} on-error={ :put “resolver failed”};
:put “lala”

output:

resolver failed
lala

:global dns [:resolve "www.google.com"]     
:put $dns
216.58.212.4
:set $result [:resolve mt.lv]; :put $result

thanks mate…

If you want to use the result in a other script then you should use :global, as ChaOs suggested.

When you use set of a variable, it should be declared fist (but works without), so either this;

:local result
:set $result [:resolve mt.lv]
:put $result

Or set it directly when declare the variable like this:

:local result [:resolve mt.lv]
:put $result

One line

local result [:resolve mt.lv]; :put $result

The problem with this tact is that it only allows to resolve the first A record. NSLOOKUP allows record type lookups like MX, SOA, etc.

How to accomplish this on Mikrotik?? Need an NSLOOKUP type tool.

What I wrote in #12 is the only other way I think we have right now.
Other than that, use an actual Windows mashie.

Why do you even need all that information on the router itself?