8

I'm trying to telnet into port 25 on a CentOS server that runs PostFix to test sending email messages from the server.

When I try to telnet in from another CentOS box on the same network I get the message below:

 Unable to connect to remote host: Connection refused 

SELinux is disabled and I've opened port 25 in iptables...what else should I be looking at?

8
  • 1
    Does your provider allow telnetting to that port? Mar 20, 2012 at 20:13
  • 1
    I'm just trying to test sending mail via smtp from another server. Mar 20, 2012 at 20:14
  • Make sure Postfix is started and listening on port 25. service postfix status and netstat -anp | grep LISTEN Mar 20, 2012 at 20:16
  • 3
    Your ISP may block outgoing port 25, because that's something spambots will use. Can you telnet gmail-smtp-in.l.google.com 25? That's a GMail MTA, and you can be sure something is listening to port 25 on that server. If you get blocked, then your ISP is blocking you.
    – cjc
    Mar 20, 2012 at 20:17
  • 2
    @mdpc, LucidLuniz is testing network functionality. He's not trying to connect and log in. telnet is a good tool for checking if something is listening to a TCP port and possibly issue commands to that service.
    – cjc
    Mar 20, 2012 at 20:18

5 Answers 5

15

Run the following the check if postfix is listening on port 25/tcp:

netstat -plnt |grep :25

You should see a line like:

tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2460/master

If you don't see such a line, check /etc/postfix/master.cf.

In that file, you should see a line like:

smtp      inet  n       -       n       -       -       smtpd

The first column is the port, which postfix derives from /etc/services.

You should look up general documentation on setting up Postfix, so your server doesn't become a spam relay. The CentOS wiki has fairly good documentation in that regard.

Update:

Also, look at http://www.postfix.org/postconf.5.html#inet_interfaces which will describe how to configure Postfix to listen on different network interfaces. The relevant line will be found in /etc/postfix/main.cf.

5
  • When running that command I see this: tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 30948/master so it seems as though port 25 should allow connections, correct? Mar 21, 2012 at 10:54
  • 1
    No, it's only listening on localhost (the 127.0.0.1) address. For it to be available on the Internet, you'll have to configure it to listen on, at least, the public network interface or on all interfaces. Look at /etc/postfix/main.cf and find the inet_interfaces line. It's probably set to 127.0.0.1 or "loopback-only". Change that to "all". Take a look at the Postfix docs here: postfix.org/postconf.5.html#inet_interfaces
    – cjc
    Mar 21, 2012 at 11:15
  • I don't need this to be publicly accessible. It only needs to be accessible from a server within our network (that I'm trying to telnet into it from). Sorry, I should have explained that upfront. Mar 21, 2012 at 11:24
  • 1
    Sure, just use the private IP for the inet_interfaces line, then.
    – cjc
    Mar 21, 2012 at 11:28
  • Yep, that worked (I just added the local server name and restarted postfix). Thanks for your help cjc and everybody else! Mar 21, 2012 at 11:31
11

I edited the file /etc/postfix/main.cf. The parameter to look up was

inet_interfaces = localhost

I changed it to

inet_interfaces = $myhostname, localhost

Restart postfix. The problem was fixed.

1
  • 2
    This helped me (although I used inet_interfaces = all), but the file to edit is actually /etc/postfix/main.cf, not master.cf (the latter does not have the inet_interfaces parameter). I've edited your answer to reflect this.
    – JJC
    Apr 20, 2015 at 19:50
4

I had this problem and found that I needed to do:

# service postfix stop

followed (a bit later) by

# service postfix start

Postfix reload did not seem to close and then re-open the required ports.

1
  • If I remember correctly, CentOS comes with IPTables enabled by default. Perhaps that is blocking your port?
    – djangofan
    Nov 13, 2012 at 17:16
2

I generally only see the Connection Refused message if there is nothing listening. Are you sure you have an SMTP server running on the external IP address? Check with

netstat -tunlp | grep 25
tcp      0    0 127.0.0.1:25              0.0.0.0:*         LISTEN    1743/master

Here you can see I'm only running on the loopback interface.

1

Check your /etc/hosts.allow and /etc/hosts.deny files. Maybe the telnet or the ports are blocked in those?!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .