How can I direct a query to specific DNS server?

I would like to issue a query to a specific DNS server, whose IP address I know. It doesn't really matter if it's on Windows or *nix.

In Windows I can do something like:

C:\Documents and Settings\Anton Daneyko>nslookup superuser.com
Server:  DNSs2.Uni-Marburg.DE
Address:  137.248.21.22

Non-authoritative answer:
Name:    superuser.com
Address:  64.34.119.12

But this uses the local machine's DNS settings. Instead, I would like to query a specific DNS server to test if it is responding to my queries correctly or responding at all.

So it should be something like:

nslookup --dns-ip=8.8.8.8 superuser.com

For basic A and CNAME records, you can simply do

nslookup somewhere.com some.dns.server

Usage: 
   nslookup [-opt ...]             # interactive mode using default server
   nslookup [-opt ...] - server    # interactive mode using 'server'
   nslookup [-opt ...] host        # just look up 'host' using default server
   nslookup [-opt ...] host server # just look up 'host' using 'server'

or if you just type nslookup without any parameters, you can do a lot more options...

Commands:   (identifiers are shown in uppercase, [] means optional)
NAME            - print info about the host/domain NAME using default server
NAME1 NAME2     - as above, but use NAME2 as server
help or ?       - print info on common commands
set OPTION      - set an option
    all                 - print options, current server and host
    [no]debug           - print debugging information
    [no]d2              - print exhaustive debugging information
    [no]defname         - append domain name to each query
    [no]recurse         - ask for recursive answer to query
    [no]search          - use domain search list
    [no]vc              - always use a virtual circuit
    domain=NAME         - set default domain name to NAME
    srchlist=N1[/N2/.../N6] - set domain to N1 and search list to N1,N2, etc.
    root=NAME           - set root server to NAME
    retry=X             - set number of retries to X
    timeout=X           - set initial time-out interval to X seconds
    type=X              - set query type (ex. A,AAAA,A+AAAA,ANY,CNAME,MX,NS,PTR,SOA,SRV)
    querytype=X         - same as type
    class=X             - set query class (ex. IN (Internet), ANY)
    [no]msxfr           - use MS fast zone transfer
    ixfrver=X           - current version to use in IXFR transfer request
server NAME     - set default server to NAME, using current default server
lserver NAME    - set default server to NAME, using initial server
root            - set current default server to the root
ls [opt] DOMAIN [> FILE] - list addresses in DOMAIN (optional: output to FILE)
    -a          -  list canonical names and aliases
    -d          -  list all records
    -t TYPE     -  list records of the given RFC record type (ex. A,CNAME,MX,NS,PTR etc.)
view FILE           - sort an 'ls' output file and view it with pg
exit            - exit the program

Just digging into the options of nslookup, which you can display if you invoke nslookup and then typing help inside of the nslookup interactive mode gave me the right answer:

C:\Documents and Settings\Anton Daneyko>nslookup help
Server:  DNSs2.Uni-Marburg.DE
Address:  137.248.21.22

*** DNSs2.Uni-Marburg.DE can't find help: Non-existent domain

C:\Documents and Settings\Anton Daneyko>nslookup
Default Server:  DNSs2.Uni-Marburg.DE
Address:  137.248.21.22

> stackoverflow.com 8.8.8.8
Server:  [8.8.8.8]
Address:  8.8.8.8

Non-authoritative answer:
Name:    stackoverflow.com
Address:  64.34.119.12

Yes, C:\Documents and Settings\Anton Daneyko>nslookup superuser.com will look up your own DNS server to find out the IP address for superuser.com. If you add the ip address or the name of a different DNS server to the command line, it will lookup that given DNS server for the ip address of superuser.com. Ex:

C:\Documents and Settings\Anton Daneyko>nslookup superuser.com 8.8.4.4
Server:  google-public-dns-b.google.com
Address:  8.8.4.4

Non-authoritative answer:
Name:    superuser.com
Addresses:  190.93.245.58
      190.93.246.58
      141.101.114.59
      190.93.247.58
      190.93.244.58

By the way, 8.8.4.4 is the ip address of Google DNS servers.

But, both of the above give "Non-authoritative answers", as neither of them SOA, which is the authoritative for superuser.com domain. Both have a cached copy that has been propagated from the SOA. If you want to ask the authoritative server, first find out the name of ip address of the authoritative server, using the command:

C:\Documents and Settings\Anton Daneyko>nslookup -type=ns superuser.com
Server:  DNSs2.Uni-Marburg.DE
Address:  137.248.21.22

Non-authoritative answer:
superuser.com   nameserver = cf-dns02.superuser.com
superuser.com   nameserver = cf-dns01.superuser.com

cf-dns02.superuser.com  internet address = 173.245.59.4
cf-dns02.superuser.com  AAAA IPv6 address = 2400:cb00:2049:1::adf5:3b04
cf-dns01.superuser.com  AAAA IPv6 address = 2400:cb00:2049:1::adf5:3a35
cf-dns01.superuser.com  internet address = 173.245.58.53

This will return a non-authoritative answer from your local DNS server, from the Marburg Uni, naming all the authoritative servers for the superuser.com. Then you can use the command we used earlier to ask any of the 4 authoritative servers, as follows:

C:\Documents and Settings\Anton Daneyko>nslookup superuser.com 173.245.59.4
Server:  cf-173-245-59-4.cloudflare.com
Address:  173.245.59.4

Name:    superuser.com
Addresses:  141.101.114.59
      190.93.246.58
      190.93.245.58
      190.93.247.58
      190.93.244.58

As you see, this time the authoritative SOA server returned the ip addresses, hence you don't see the comment "Non-authoritative answer" comment, anymore. This is particularly useful, when you have created a new domain name or changed the hosting providers or transferred to a different domain registrar, and you can't access your website, as the new IP addresses haven't propagated even after 24 hours. Then you can start with the SOA and verify that your correct ip address is given by the DNS server, and then follow it further down the tree. Good to check if Google DNS servers have received the changes, and then lastly if your local DNS server can resolve your Domain name to correct IP address.


Get specific record-types from specified DNS server with one command

To look up record types other than the default A and AAAA (and CNAME) records returned by nslookup, using the DNS server you specify:

nslookup -q=<record type> <host> <DNS server>

For example, to return MX records for the domain stackexchange.com using DNS server 8.8.4.4 the command would be:

nslookup -q=MX stackexchange.com 8.8.4.4