40

Trying to create a socks (-D) ssh tunnel - Linux box to Linux box (both centos):

sshd running on remote side ok.

From local machine we do / see this:

ssh -D 1080 user@8.8.8.8.
user@8.8.8.8's password: 
bind: Cannot assign requested address

(where 8.8.8.8 is really my server's IP and 'user' is my real username)

I am logged into the remote side in this terminal-window. I can verify that the local port was unused prior to this command, and then used by an ssh process, after the command, via:

netstat -lnp | grep 1080

So, unlike most googled-responses with this error, the problem would not seem to be the loopback interface assignment. If I try to use this tunnel with a mail client, the local-side permits the attempt (no 'proxy-failed' error), but no data / reply is returned.

On the remote side, I do have "PermitTunnel yes" in my sshd_config (though 'yes' should be the default, anyway).

Ideas or Clues?

Here is the relevant debug-output

OpenSSH_5.3p1, OpenSSL 1.0.0-fips 29 Mar 2010
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *

....

debug1: Authentication succeeded (password).
debug1: Local connections to LOCALHOST:1080 forwarded to remote address socks:0
debug1: Local forwarding listening on 127.0.0.1 port 1080.
debug1: channel 0: new [port listener]
debug1: Local forwarding listening on ::1 port 1080.
bind: Cannot assign requested address
debug1: channel 1: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.utf8

Other clue: If I run a Virtual Box on the client running Windows, open a tunnel with putty in that box, that tunnel, to the same remote server, works.

Stranger Still" If I use Putty (for linux) running directly on the Linux Client, it does NOT work, even if the settings are an exact duplicate of the putty settings which DO WORK in Putty running on Windows in a Virtual Box on the same Client Machine?? There is something fishy ... still trying experiments to figure out what it is.

JosephK
  • 603
  • 1
  • 6
  • 8

1 Answers1

69

The close the loop here. The answer, in this case, was to force the ssh client to use ipv4. E.g.

ssh -4 -D 8081 user@8.8.8.8
  • So I would think, except that I can select 'force ip4' in putty (running on Linux) without success. Also IPV6 is disabled on this machine, so theoretically should not have been at play. The completely inconsistent results I still get trying different permutations of this thing leave me scratching my head. In any case, your answer helped me get it working, and perhaps has uncovered something odd about how this version of CentOS or Linux Kernel or some-such is operating - Thanks. – JosephK Nov 06 '12 at 05:57
  • A long shot but perhaps turning off SSH DNS resolution on the server, "UseDNS no" in sshd_config, might resolve it. Perhaps some weird DNS resolution is going on the server causing bind issues. – Friedrich 'Fred' Clausen Nov 06 '12 at 10:44
  • 1
    Thanks a lot, the -4 was also the solution for Ubuntu 11.04. – Sander Dec 24 '12 at 21:03
  • I started having this issue after upgrading to Ubuntu 13.04, and this was the fix. – Nick Mar 14 '13 at 12:47
  • 5
    Instead of having to specify -4 every time, assuming all ssh connections are to be made with IPv4 only, add "AddressFamily inet" to your ssh_config file -- per user in ${HOME}/.ssh/ssh_config, or system wide for all users in /etc/ssh/ssh_config – J G Miller Mar 13 '17 at 13:04
  • 4
    What was the clue that made you think to try `-4`? – Paul Price Apr 28 '18 at 00:11
  • 1
    Refer to https://www.electricmonk.nl/log/2014/09/24/ssh-port-forwarding-bind-cannot-assign-requested-address/ . The clue is it listens on ipv6: "debug1: Local forwarding listening on ::1 port 8080." – Haili Sun Oct 29 '21 at 05:26