Community discussions

MikroTik App
 
bakiri123
just joined
Topic Author
Posts: 4
Joined: Tue Jul 24, 2012 2:37 pm

nslookup on Mikrotik

Thu Aug 23, 2012 12:26 pm

Is there a Mikrotik command equivalent to the Windows nslookup command?
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 24823
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: nslookup on Mikrotik

Thu Aug 23, 2012 12:30 pm

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:

ros code

[admin@MikroTik] > put [:resolve mt.lv]
159.148.147.196
No answer to your question? How to write posts
 
bakiri123
just joined
Topic Author
Posts: 4
Joined: Tue Jul 24, 2012 2:37 pm

Re: nslookup on Mikrotik

Thu Aug 23, 2012 1:38 pm

Thanks. The command also works fine without the colon, i.e. put [resolve mt.lv]
 
User avatar
marria
newbie
Posts: 31
Joined: Sat Jun 04, 2011 8:41 pm

Re: nslookup on Mikrotik

Thu Jul 23, 2015 5:09 am

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:

ros code

[admin@MikroTik] > put [:resolve mt.lv]
159.148.147.196
This is true, but does not tell which dns server is resolving, which can be helpful...
 
olkba
just joined
Posts: 3
Joined: Wed Oct 21, 2015 12:38 pm

Re: nslookup on Mikrotik

Wed Oct 21, 2015 12:41 pm

you can specify target dns server to query easily:
put [resolve google.com server 8.8.8.8]
 
yottabit
Member Candidate
Member Candidate
Posts: 184
Joined: Thu Feb 21, 2013 5:56 am

Re: nslookup on Mikrotik

Wed Feb 24, 2016 2:14 am

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 <host> [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
 
yottabit
Member Candidate
Member Candidate
Posts: 184
Joined: Thu Feb 21, 2013 5:56 am

Re: nslookup on Mikrotik

Sat Feb 27, 2016 5:58 pm

Friendly bump to see if anyone has tips for forcing the :resolve command to use an external server?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1915
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: nslookup on Mikrotik

Sun May 07, 2017 1:16 pm

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] >
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 
 
stardm
just joined
Posts: 1
Joined: Wed Nov 01, 2017 7:58 pm

Re: nslookup on Mikrotik

Wed Nov 01, 2017 9:01 pm

Hello, all
you can specify target dns server to query easily:
put [resolve google.com server 8.8.8.8]
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.
 
arashams
newbie
Posts: 33
Joined: Thu Jul 04, 2013 11:20 pm

Re: nslookup on Mikrotik

Mon Jan 01, 2018 10:04 am

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
Last edited by arashams on Mon Jan 01, 2018 12:43 pm, edited 1 time in total.
 
User avatar
nichky
Long time Member
Long time Member
Posts: 676
Joined: Tue Jun 23, 2015 2:35 pm

Re: nslookup on Mikrotik

Mon Jan 01, 2018 10:30 am

nice one, i thought MT didn't support that one
RouterOS does not have a random function. Many has tried to make script to make random text, but all seems to be flawed.
viewtopic.php?f=9&t=160183

!) Safe Mode is your friend;
 
User avatar
Deantwo
Member
Member
Posts: 317
Joined: Tue Sep 30, 2014 4:07 pm

Re: nslookup on Mikrotik

Wed Oct 02, 2019 12:48 pm

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]
I wish my FTP was FTL.
 
tannexdadole
just joined
Posts: 6
Joined: Tue Aug 22, 2017 4:14 pm

Re: nslookup on Mikrotik

Fri May 08, 2020 4:32 pm

you can specify target dns server to query easily:
put [resolve google.com server 8.8.8.8]
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
Last edited by tannexdadole on Fri May 08, 2020 4:43 pm, edited 1 time in total.
 
User avatar
Cha0s
Forum Guru
Forum Guru
Posts: 1034
Joined: Tue Oct 11, 2005 4:53 pm

Re: nslookup on Mikrotik

Fri May 08, 2020 4:40 pm

:global dns [:resolve "www.google.com"]     
:put $dns
216.58.212.4
 
msatter
Forum Guru
Forum Guru
Posts: 2043
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: nslookup on Mikrotik

Fri May 08, 2020 4:43 pm

:set $result [:resolve mt.lv]; :put $result
Loving my freedom and so, no Twitter, no Facebook/Instagram/WhatsApp, no Apple and no Google/Alphabet, no Amazon/Cloudfront/AWS.

Running:
RouterOS 6.49Beta / Winbox 3.27 64bits
 
tannexdadole
just joined
Posts: 6
Joined: Tue Aug 22, 2017 4:14 pm

Re: nslookup on Mikrotik

Fri May 08, 2020 6:24 pm

:set $result [:resolve mt.lv]; :put $result
thanks mate...
 
msatter
Forum Guru
Forum Guru
Posts: 2043
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: nslookup on Mikrotik

Fri May 08, 2020 7:16 pm

If you want to use the result in a other script then you should use :global, as ChaOs suggested.
Loving my freedom and so, no Twitter, no Facebook/Instagram/WhatsApp, no Apple and no Google/Alphabet, no Amazon/Cloudfront/AWS.

Running:
RouterOS 6.49Beta / Winbox 3.27 64bits
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1915
Joined: Sat Dec 24, 2016 11:17 am
Location: jo.overland at gmail.com

Re: nslookup on Mikrotik

Fri May 08, 2020 9:23 pm

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
 
Why do not use Splunk to monitor your MikroTik Router(s)? Look at this page in how to set it up.

MikroTik->Splunk
 

Who is online

Users browsing this forum: Joe1962, tdw and 62 guests