The Linux dig command is useful for DNS lookup and to query specific DNS name servers.
Basic syntax is:
dig hostname
This will give you a generic answer similar to this:
; <<>> DiG 9.10.6 <<>> oopsla.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31918 ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4000 ;; QUESTION SECTION: ;oopsla.com. IN A ;; ANSWER SECTION: oopsla.com. 8 IN A 54.147.36.143 oopsla.com. 8 IN A 54.173.18.128 ;; Query time: 45 msec ;; SERVER: 172.16.10.108#53(172.16.10.108) ;; WHEN: Wed Mar 22 10:54:37 EDT 2023 ;; MSG SIZE rcvd: 71
To ask a specific DNS name server use the below Linux dig command:
dig @dns-name-server <hostnameToQuery>
Select DNS query type with the dig command. The syntax is below:
dig hostname type
For example, you want to query mail records(MX records)
dig myhostname MX
Query for A records:
dig cocotu.com A
If you like to find the hostname of an IP address:
dig <sampleIP>
dig 32.124.233.153
Hope you like this brief tutorial. If you like to support me check out my code with coffee T-Shirt I designed myself. Also, contact me if you have any questions.Thanks.