I am trying to get list of all hostnames from my DNS server by command:

host -l example-domain.com mydns.com

However one machine has invalid DNS name, because there are two hyphens in row and I get error:

host: 'exa--mple.example-domain.com' is not a legal IDNA2008 name.....

In this case executing of this command is interrupted and I don't get complete list. Is there any way how to skip this error, and get complete list? Or maybe some other command? I have also tried dig command, but there is same problem:

dig @mydns.com example-domain.com axfr

Something like "try/catch" would be fine, but I think it doesn't exist in bash. I have also tried export IDN_DISABLE=1 according to manual of command host. Unfortunately, it doesn't help me, still same error. I am using current version of debian.

3 Answers 3


Yes, it is possible to send all occurring errors "to the trash" by using

command > /dev/null 2>&1


command &>/dev/null

For more detailed information visit e.g. cyberciti or do a quick google search, then you will probably find more detailed tutorials.

  • 1
    If I used both of these command I will not get any output.
    – pomahajbo
    Aug 30, 2021 at 7:40

Commands which are part of the bash syntax, have to be right in a script. But you are speaking about the result of the execution of a program called by this bash script. $? is the value returned by the last executed command. You can use it to make decisions in the following part of the bash script. Unfortunately, according to man pages of the host and dig commands, there is no useful code returned.

You have the general capability to redirect the output of the dig or host commands and to analyze it using commands like grep or awk. But you are depending on the exact syntax of the output of these programs. This syntax can change in future releases of these programs.

Please note a discrepancy in your question. Your host command is asking about example-domain.com and the cited output is related to exa--mple.com. Further, it is better to always ask about absolute domain names, i.e. ending with a period.


If you just want to ignore the error (disregarding the $? value), how about using...

somecommand || true

... to ignore the return code...?

e.g. pass each host as a string to xargs (one string at a time, using the xargs -n1 flag, and the xargs -I flag, where _ is the substitued value in this example.


>echo google.com blahblah123.com | xargs -n1 -I_ host -l _   || true
;; Connection to for google.com failed: connection refused.
;; Connection to for blahblah123.com failed: connection refused.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .