0

I'm using dig utility to find public IP address.

The command I used is:

dig +short myip.opendns.com @resolver1.opendns.com

but I had problem since on some other computers it took so long, so I added a timeout after 5 seconds:

dig +short +time=5 +tries=1 myip.opendns.com @resolver1.opendns.com

and it fails on some as expected, but on some other computers it never finishes. All it does is hangs...

Any idea why and how can this be fixed to timeout after 5 seconds as expected ?

EDIT:

Already tried timeout but it still hangs. I think it stucks while resolving DNS. For example, I can't ping www.google.com, but can 172.217.20.4.

3

As for using aplicational timeouts in some utilities, when there are connectivity issues, it is not always guaranteed the application will stop on it's own with some outside "coercion".

I would use an external utility to kill it after some time just in case, for the problematic situations where it hangs.

As in:

timeout 5 dig +short +time=5 +tries=1 myip.opendns.com @resolver1.opendns.com

From man timeout

NAME top

   timeout - run a command with a time limit

SYNOPSIS top

   timeout [OPTION] DURATION COMMAND [ARG]...
   timeout [OPTION]

DESCRIPTION top

   Start COMMAND, and kill it if still running after DURATION.
| improve this answer | |
  • I suspect 5s can be slow in some situation, but I do not know the OPs network. – Rui F Ribeiro Jun 3 '19 at 10:05
  • I already tried timeout, but it still hangs. I don't know why... – Dinko Pehar Jun 3 '19 at 10:11
  • I think it stucks while resolving DNS. I can't ping www.google.com, but can 172.217.20.4 – Dinko Pehar Jun 3 '19 at 10:13
  • timelimit might work better. Will add it as an alternative when i get to my Debian machine. – Rui F Ribeiro Jun 3 '19 at 12:29
  • (At least FreeBSD and GNU) timeout has a -k option to SIGKILL after an additional time. – A.B Jun 4 '19 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.