Search code examples
unixnetcat

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


nc works fine when i execute it on a VM.

Connection to 10.0.0.10 22 port [tcp/ssh] succeeded!

But when I execute the same command inside my docker container, it gives the below UNKNOWN error/exception.

10.0.0.10: inverse host lookup failed: Unknown host 
(UNKNOWN) [10.0.0.10] 22 (ssh) open

Below is the nc command that I am using:

nc -vz 10.0.0.10 22 -w 4

Solution

  • "Inverse host lookup failed" simply means that nc wanted to print which host name 10.0.0.10 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.