7

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?

Zek
  • 568
  • 3
  • 10
  • 24

2 Answers2

6

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.

Zek
  • 568
  • 3
  • 10
  • 24
0

I do not think that this error is bound to centos or netcat. I had the same error, only wrapped by paramiko, which is the Python module for ssh commands so that you do not need to use the bash.

With this paramiko module, I get the very similar

getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno -2] Name or service not known

when trying to ssh connect to a server.

When I tried the same connection using the "real" ssh in bash mode (no Python/paramiko), this time with ssh-keyscan, the error was:

getaddrinfo SOMETHING@MY_SERVER.com: Name or service not known

It turned out that it was wrong to add the SOMETHING prefix to the server address. I thought that in SOMETHING@MY_SERVER.com, the SOMETHING belongs to the server name although it was just the "username@" prefix. I confused this because I was given another username that was different, and the SOMETHING was very technical like "www-SOME_GENERAL_WORD" which did not look like a username to me.

Removing the username prefix so that only MY_SERVER.com was left solved the error. That means: if you get such an error, check your server address - clean it from any prefix or suffix.

questionto42
  • 353
  • 5
  • 23