Debian – Telnet: Unable to connect to remote host

debianfirewalliptablessmtptelnet

Related Threads:

The problem

I have a server running Debian 3.2.65-1 and i am having some problems to connect other server to send emails through SMTP in a web app based on Drupal.

The first thing i've done is ckecking the server with telnet and the result is the following message.

Command Line syntax:

telnet smtp.mydomain.com 587

Result:

Trying XXX.XXX.XX.XXX...
telnet: Unable to connect to remote host: Connection timed out

After googling and reading some posts about different solutions:

  1. I can connect from other different machines to the SMTP server. So i discard the SMTP server as origin of the problem.
  2. The statement on 1 makes me think that it is a firewall problem. Then, I've checked iptables.

Command Line syntax:

iptables -L

Result:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

I understand that the server is open and it has the default configuration with no rules.

  1. I've found that the server has UFW, but it is not running.
  2. Following the advice of kasperd in comments: 3rd comment

netstat -ntlp

result:

(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:36990           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6082          0.0.0.0:*               LISTEN      -
tcp6       0      0 :::111                  :::*                    LISTEN      -
tcp6       0      0 :::8080                 :::*                    LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
tcp6       0      0 :::46645                :::*                    LISTEN      -
tcp6       0      0 :::22                   :::*                    LISTEN      -
tcp6       0      0 :::443                  :::*                    LISTEN      -
tcp6       0      0 ::1:6082                :::*                    LISTEN      -

Any ideas how can i fix it ?

Best Answer

Your server is not listening on port 587. I accept that you think you've been able to connect to it from some other machines, but I can only surmise that they've been going through some kind of transparent proxy which has hijacked connections to mail-server-type services, and whisked you off to some local mail server.

In other words, the machine that can't connect to server:587 is telling you the truth. Any machines that claim they can are lying to you.