Netcat issue, getaddrinfo: Name or service not known

I am trying to use netcat to relay SSH traffic (bidirectionally) from port 2222 on one host to port 22 on a different host. For test purposes, I redirect to 127.0.0.1:22 here instead of the remote host.

Here is the command and the error I am getting:

nc -n –l 2222 0<backpipe | nc -n 127.0.0.1 22 1>backpipe
getaddrinfo: Name or service not known

I must be missing something really obvious here, but I fail to see it. I am using only IP addresses (and even "-n" to not resolve anything), but it appears to still be trying to do a DNS lookup.

This is CentOS 6.x [64].

What am I missing?


Solution 1:

I got this working. The issue was that I had to specify the host for the first nc command, like so:

nc -n 192.168.1.2 -l 2222 0<backpipe | nc -n 127.0.0.1 22 1>backpipe" 

Normally the host should not be needed with "-l" (it defaults to local host), according to the man page.