Linux – query a specific name server with nslookup or dig

By default, nslookup in Linux will use the name servers configured in /etc/resolv.conf. To check against a specific dns server, add the dns server IP address or name at the end of the nslookup command.

Below is an example to query Cloudflare name server 1.1.1.1 –

1
2
3
4
5
6
7
8
9
10
daniel@linux:/$ nslookup -type=MX gmail.com 1.1.1.1
Server:     1.1.1.1
Address:    1.1.1.1#53
 
Non-authoritative answer:
gmail.com   mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com   mail exchanger = 5 gmail-smtp-in.l.google.com.
gmail.com   mail exchanger = 10 alt1.gmail-smtp-in.l.google.com.
gmail.com   mail exchanger = 20 alt2.gmail-smtp-in.l.google.com.
gmail.com   mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.

For dns related debugging though, dig (under “dnsutils” package) is more feature rich. For troubleshooting the “dig +trace” command is handy in spotting failure points. Here is a useful link on how to use dig to troubleshoot dns issues –
https://linuxfreelancer.com/troubleshooting-dns-dig-tracing

1
2
3
4
5
6
daniel@linux:/$ dig @1.1.1.1 gmail.com mx +short
20 alt2.gmail-smtp-in.l.google.com.
30 alt3.gmail-smtp-in.l.google.com.
40 alt4.gmail-smtp-in.l.google.com.
5 gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.

References –

https://linux.die.net/man/1/nslookup

https://linux.die.net/man/1/dig

https://www.techradar.com/news/best-dns-server