This question already has an answer here:

For some reason my CentOS VPS refuses all connections except for HTTP, SSH and Telnet. Whenever I try to connect to a port such as 25 (SMTP) or even a random port such as 225 I get a connection refused error :S netstat -ap shows that the server is listening and iptables is turned off.

However I can interface with the same ports on the server through telnet...

# iptables -L
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    

# netstat -an | fgrep LISTEN
tcp        0      0        *                   LISTEN      
tcp        0      0       *                   LISTEN      
tcp        0      0 :::22                       :::*                        LISTEN      
tcp        0      0 :::80                       :::*                        LISTEN      
unix  2      [ ACC ]     STREAM     LISTENING     169786017 /tmp/.font-unix/fs7100
unix  2      [ ACC ]     STREAM     LISTENING     169786045 /var/run/saslauthd/mux

This is the error message i'm getting from my php script. My PHP script works fine with every other SMTP server I've come across Warning: fsockopen() [function.fsockopen]: unable to connect to :25 (Connection refused)

marked as duplicate by Iain, mdpc, Katherine Villyard, Cristian Ciupitu, MadHatter Oct 4 '15 at 9:14

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    So is it possible that your ISP only allows a handful ports?! – mailq Oct 9 '11 at 20:39
  • Nope, it lets me connect to other servers, just not my VPS. – Randy the Dev Oct 9 '11 at 20:40
  • Or did you mean my VPS ISP? – Randy the Dev Oct 9 '11 at 20:40
  • Are you certain iptables isn't running ? – Iain Oct 9 '11 at 20:42
  • yes, that is what @mailq mean. Did your ISP (as in your VPS provider) put a firewall in front of your VPS? Out of curiosity, what ports should be accessible? – Rilindo Oct 9 '11 at 20:44

It looks like there is something upstream of your VPS that is blocking access except for the ports noted. You should contact your VPS provider and ask them about it.

  • 1
    You were right, they blocked pretty much everything, I solved it by running my SMTP server on port 80 :P – Randy the Dev Oct 9 '11 at 22:44

Okay, to make things clear - if you are running CentOS, chances are that you are at release 5 with sendmail as the default. In that case, you will not be to connect externally, because sendmail will only listen to localhost by default. To make it listen on the main IP, you will need to disable the line in /etc/sendmail.mc from this:

DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl

to this:

dnl DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl

Then rebuild sendmail.cf with the following:

/etc/init.d/sendmail restart

(if it is postfix, it may be a different story. IIRC, postfix will only listen by default on localhost as well, so you will need to configure it as well to listen on the main IP).

HOWEVER, since you are just trying to test external connectivity, you may just need to install nc and then run it to listen to a specific. Here is my example:

[root@kvm0006 mail]# nc -l 50

Here I am listening on port 50 (hence, the -l). Now when I connect from outside the server on that port, I will get this:

yvaine:Downloads rilindo$ telnet 50
Connected to kvm0006.monzell.com.
Escape character is '^]'.

Which will return the following on the server side:

[root@kvm0006 mail]# nc -l 50

To install nc:

yum -y install nc
  • Unfortunately I have already done that to no avail :( – Randy the Dev Oct 9 '11 at 21:23
  • And for some reason connecting through telnet works, but connecting directly doesn't. – Randy the Dev Oct 9 '11 at 21:23
  • And that includes telnet from a remote server. – Randy the Dev Oct 9 '11 at 21:27
  • doesn't mean listening on port 25 for all available interfaces ? – Iain Oct 9 '11 at 21:31
  • Can we get the output of your telnet test? And when you do a telnet test, can you do a tcpdump on the server interface, so that we can see that there is actually two way traffic? – Rilindo Oct 9 '11 at 21:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.