13

When I try either of these commands they do not stop after 5 seconds:

$ dig +time=5 @hii.com hello.me 

-or-

$ dig @hii.com hello.me +time=5

What is the correct way to use this option?

slm
  • 7,355
  • 16
  • 54
  • 72
sg552
  • 389
  • 3
  • 4
  • 11

1 Answers1

26

The timeout value is per try so setting a +time=5 would result in a 15 seconds delay as the default for +tries is 3. If you set +tries=1 then your command will timeout in 5 seconds e.g.

time dig +time=5  @hii.com hello.me

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5_7.1 <<>> +time=5 @hii.com hello.me
; (1 server found)
;; global options:  printcmd
;; connection timed out; no servers could be reached

real    0m15.017s
user    0m0.003s
sys     0m0.011s

or with a tries=1

 time dig +time=5 +tries=1 @hii.com hello.me

; <<>> DiG 9.3.6-P1-RedHat-9.3.6-16.P1.el5_7.1 <<>> +time=5 +tries=1 @hii.com hello.me
; (1 server found)
;; global options:  printcmd
;; connection timed out; no servers could be reached

real    0m5.015s
user    0m0.006s
sys     0m0.007s
user9517
  • 114,104
  • 20
  • 206
  • 289
  • 1
    Thank you very much. I was planning to stop the query by php actually and it was originally from here: http://stackoverflow.com/questions/9281060/limit-php-execution-time but dig option is more simple and efficient. Thanks again. – sg552 Feb 15 '12 at 18:46
  • So `+tries` is acting as `+time`'s iterator inside the dig command? – ConstantFun Jul 29 '20 at 07:18