Why node nc (netcat) give error "inverse host lookup failed: Unknown host"?

nc works fine when i execute it on a VM.

Connection to 22 port [tcp/ssh] succeeded!

But when I execute the same command inside my docker container, it gives the below UNKNOWN error/exception. inverse host lookup failed: Unknown host 
(UNKNOWN) [] 22 (ssh) open

Below is the nc command that I am using:

nc -vz 22 -w 4


  • "Inverse host lookup failed" simply means that nc wanted to print which host name corresponds to, but couldn't.

    UNKNOWN is simply what it then prints as the host name.

    This is distinct from "I looked it up, but it doesn't seem to correspond to anything" which is what happens outside the container.

    To be perfectly explicit, connecting to the host succeeded, but looking up its name from the IP address failed. This is just an informational warning message, not a hard error; the lookup is entirely optional, anyway, and can be disabled with -n.

    If you really want to avoid this warning and not switch to -n, you need to set up working DNS inside the container.