Skip to main content

UNIX dig command, basic info

I recently became familiarized with  dig or domain information groper, or in short it is the outstanding tool for DNS lookups. It has great functionally ant it is preinstalled on most of the distributions today.If we don't tell it to query a specific name server, dig will try each of the servers listed in /etc/resolv.conf.

The command goes something like this:

dig [ @server ] [ -b address ] [ -c class ] [ -f filename ] [ -k filename ] [ -p port# ] [ -t type ] [ -x addr ] [ -y name:key ] [ name ] [ type ] [ class ] [ queryopt... ]
dig [ -h ]
dig [ global-queryopt... ] [ query... ]

Examples

Or why I use dig mostly for. Let say I want to see all the redirects from the top level ns to my server.

 dig mitemitreski.com +trace

and we get something like this:


; <<>> DiG 9.7.1-P2 <<>> mitemitreski.com +trace
;; global options: +cmd
.   46703 IN NS b.root-servers.net.
.   46703 IN NS k.root-servers.net.
.   46703 IN NS c.root-servers.net.
.   46703 IN NS e.root-servers.net.
.   46703 IN NS i.root-servers.net.
.   46703 IN NS g.root-servers.net.
.   46703 IN NS f.root-servers.net.
.   46703 IN NS d.root-servers.net.
.   46703 IN NS l.root-servers.net.
.   46703 IN NS a.root-servers.net.
.   46703 IN NS j.root-servers.net.
.   46703 IN NS h.root-servers.net.
.   46703 IN NS m.root-servers.net.
;; Received 228 bytes from 
192.168.1.1#53(192.168.1.1) in 44 ms

com.   172800 IN NS f.gtld-servers.net.
com.   172800 IN NS d.gtld-servers.net.
com.   172800 IN NS a.gtld-servers.net.
com.   172800 IN NS l.gtld-servers.net.
com.   172800 IN NS i.gtld-servers.net.
com.   172800 IN NS b.gtld-servers.net.
com.   172800 IN NS m.gtld-servers.net.
com.   172800 IN NS k.gtld-servers.net.
com.   172800 IN NS j.gtld-servers.net.
com.   172800 IN NS h.gtld-servers.net.
com.   172800 IN NS c.gtld-servers.net.
com.   172800 IN NS e.gtld-servers.net.
com.   172800 IN NS g.gtld-servers.net.
;; Received 494 bytes from
 
128.8.10.90#53(d.root-servers.net) in 136 ms

mitemitreski.com. 172800 IN NS ns71.domaincontrol.com.
mitemitreski.com. 172800 IN NS ns72.domaincontrol.com.
;; Received 118 bytes from
 192.55.83.30#53(m.gtld-servers.net) in 174 ms

mitemitreski.com. 3600 IN A 96.9.172.197
mitemitreski.com. 3600 IN NS ns71.domaincontrol.com.
mitemitreski.com. 3600 IN NS ns72.domaincontrol.com.
;; Received 102 bytes from
 208.109.255.46#53(ns72.domaincontrol.com) in 126 ms


And basically we got the redirects from the top-level domains to our host.
Let say we want to know the MX records for a server, we write
 dig mx gmail.com 

WE GET : 

; <<>> DiG 9.7.1-P2 <<>> mx gmail.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23455
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0,
 ADDITIONAL: 0

;; QUESTION SECTION:
;gmail.com.   IN MX

;; ANSWER SECTION:
gmail.com.  3586 IN MX 30 alt3.gmail-smtp-in.l.google.com.
gmail.com.  3586 IN MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com.  3586 IN MX 40 alt4.gmail-smtp-in.l.google.com.
gmail.com.  3586 IN MX 20 alt2.gmail-smtp-in.l.google.com.
gmail.com.  3586 IN MX 5 gmail-smtp-in.l.google.com.


...

For the full description take a look at the dig man page or on-line at:
http://www.manpagez.com/man/1/dig/
http://ss64.com/bash/dig.html

Other references

http://stackoverflow.com/questions/tagged/dig

Popular posts from this blog

HTML 5 data-* attributes, how to use them and why

It is always tempting to add custom attributes in HTML so that you can use the data stored there to do X. But if you do that there is no way of knowing if your HTML attribute will not be overridden in the future and used for something else and additionally you will not be writing valid HTML markup that can pass HTML 5 validator and with that you can create some very bad side effects. That is why there is a spec in HTML 5 called custom data attributes that enable number of useful features.

You may go around and read the specs, but the basic idea is very simple, you can add any attribute that starts with "data-" and that attribute will be treated as non-visible data for that attribute. By non-visible I mean that it is not something that gets rendered to the client so it does not affect the layout or style of the page, but it is there in the HTML so in no way this is private.
So let's get right into it, the following snippet is a valid HTML5 markup

<div id="aweso…

Basic Authentication with RestTemplate

Spring Rest Templates are very good way of writing REST clients. By default they work with basic HTTP so if we need to use Basic Authorization we would need to init the rest template with custom HttpClient. This way the Rest Template will automatically use Basic Auth and append to the HTTP headers "Authorization: Basic BASE64ENCODED_USER_PASS".

HttpClient client = new HttpClient(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("USERNAME","PASS"); client.getState().setCredentials( new AuthScope("www.example.com", 9090, AuthScope.ANY_REALM), credentials); CommonsClientHttpRequestFactory commons = new CommonsClientHttpRequestFactory(client); RestTemplate template = new RestTemplate(commons); SomeObject result = template.getForObject( "http://www.example.com:9090/",SomeObject.class );

In EE application this would probably be managed by DI framework like Spring Core and only initialized once sin…

Temporary files and directories in Java 7 and before

Sometimes we want to create a temporary file, whether to save some data that gets written by some other application or just to temporary store stuff. Well, usually applications have their own temporary folder where they do this and it gets somehow configured. But why not use the underlying OS specific file like "/tmp/" in Linux so there must be some system property that has this info and there is. The key is "java.io.tmpdir" resulting in "/tmp" in my case or by code:
String tempDir = System.getProperty("java.io.tmpdir"); We can use tempDir  folder as a temporary place to store files, but there are a lot nicer ways to work with files like this even in JDK6 not just in JDK7:
import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; public class TempFile { public static void main(String[] args) { try { // create a temp file File tempFile = File.createTempFile("old-file",…