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?

Windows Ninja
  • 2,586
  • 19
  • 46
  • 70
  • 1
    Does your provider allow telnetting to that port? – Lucas Kauffman Mar 20 '12 at 20:13
  • 1
    I'm just trying to test sending mail via smtp from another server. – Windows Ninja Mar 20 '12 at 20:14
  • Make sure Postfix is started and listening on port 25. `service postfix status` and `netstat -anp | grep LISTEN` – Aaron Copley Mar 20 '12 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 '12 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 '12 at 20:18
  • @mdpc SSH to test postfix? – Lucas Kauffman Mar 20 '12 at 20:19
  • @AaronCopley I don't see port 25 listening although postfix is started, so that is likely the issue. Where would I look in the postfix configs to find out what port postfix is set to listen on? – Windows Ninja Mar 20 '12 at 20:20
  • It's listening on another port, then. You're running a customized VPS or something like Plesk. Look in `/etc/postfix/master.cf`. See also this similar question: http://serverfault.com/a/367416/50647 – Aaron Copley Mar 20 '12 at 20:29

5 Answers5

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.

cjc
  • 24,916
  • 3
  • 51
  • 70
  • 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? – Windows Ninja Mar 21 '12 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: http://www.postfix.org/postconf.5.html#inet_interfaces – cjc Mar 21 '12 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. – Windows Ninja Mar 21 '12 at 11:24
  • 1
    Sure, just use the private IP for the inet_interfaces line, then. – cjc Mar 21 '12 at 11:28
  • Yep, that worked (I just added the local server name and restarted postfix). Thanks for your help cjc and everybody else! – Windows Ninja Mar 21 '12 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.

Steve
  • 103
  • 5
Alex Lee
  • 111
  • 1
  • 2
  • 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 '15 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.

petrus
  • 5,297
  • 26
  • 42
Doug Conran
  • 149
  • 3
  • If I remember correctly, CentOS comes with IPTables enabled by default. Perhaps that is blocking your port? – djangofan Nov 13 '12 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.

user9517
  • 115,471
  • 20
  • 215
  • 297
1

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

Anshuman
  • 239
  • 1
  • 2
  • 8