✓ Solved

Cant change port 25 in postfix

Hi, I'm quite new to Linode and Postfix. I'm trying to set up a mail server on my linode with postfix, dovecot and mysql. I have LAMP server with multiple sites on Debian 11.
I followed the guide https://www.linode.com/docs/guides/email-with-postfix-dovecot-and-mysql/ and https://www.linode.com/docs/guides/troubleshooting-problems-with-postfix-dovecot-and-mysql/ but still I can't send and receive emails. When I send an email to a gmail account, it tries to send via port 25 while I disabled this.
(connect to alt2.gmail-smtp-in.l.google.com[142.251.9.27]:25: Connection timed out)
I can telnet into port 25. I read about relayhost but I don't prefer this because I don't want to pay anything extra and be limited in my number of emails.

Part of my main.cf
# TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls= yes smtpd_tls_auth_only = yes smtp_tls_security_level = may smtpd_tls_received_header = yes smtpd_tls_security_level=may smtp_tls_CApath=/etc/ssl/certs smtpd_sasl_security_options = noanonymous, noplaintext smtpd_sasl_tls_security_options = noanonymous # Authentication smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache Restrictions smtpd_helo_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unlisted_recipient, reject_unauth_destination smtpd_sender_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_sender, reject_unknown_sender_domain smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

part of master.cf file:
========================================================================== # service type private unpriv chroot wakeup maxproc command + args # (yes) (yes) (no) (never) (100) # ========================================================================== #smtp inet n - - - - smtpd 2525 inet n - y - - smtpd #smtp inet n - y - 1 postscreen smtpd pass - - - - - smtpd #dnsblog unix - - y - 0 dnsblog #tlsproxy unix - - y - 0 tlsproxy submission inet n - - - - smtpd #6000 inet n - n - - smptd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes -o smtpd_sasl_type=dovecot -o smtpd_sasl_path=private/auth -o smtpd_tls_auth_only=yes -o smtpd_reject_unlisted_recipient=no -o smtpd_client_restrictions=permit_sasl_authenticated,reject # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions # -o smtpd_recipient_restrictions= # -o smtpd_relay_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING smtps inet n - - - - smtpd -v -o syslog_name=postfix/smtps -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes -o smtpd_sasl_type=dovecot -o smtpd_sasl_path=private/auth -o smtpd_client_restrictions=permit_sasl_authenticated,reject -o milter_macro_daemon_name=ORIGINATING # -o smtpd_reject_unlisted_recipient=no # -o smtpd_client_restrictions=$mua_client_restrictions # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions # -o smtpd_recipient_restrictions= # -o smtpd_relay_restrictions=permit_sasl_authenticated,reject # -o milter_macro_daemon_name=ORIGINATING

Can someone help me changing postfix smtp port to something other than port 25 so I can connect with gmail forexample without having a relayhost? I already search a lot in this community and on Google. I tried a lot but nothing worked.

2 Replies

✓ Best Answer

  • Launch a terminal, become the root user and edit the master.cf file located in /etc/postfix directory:

sudo vi /etc/postfix/master.cf

  • Look for the line:
smtp            inet      n      -       n       -       -        smtpd
  • Replace "smtp" with the port number that postfix should listen on, save the file and restart postfix.

Given the exposition of your problem, I'm not so sure you really want to do this. Port 25 is used for mail relay (a mail server transferring messages to another mail server). I'm pretty sure you want to use port 587 (submission) or port 465 (smtps) to submit email to gmail.

It would really surprise me if gmail was using port 25 at all except in the most special of special cases. They're probably using port 465 (smtps) -- which requires you to authenticate to them beforehand — that's why your connection is timing out.

It’s pretty easy to configure postfix to listen on all of ports 25, 465 & 587…

Anyway, I've answered your question but I take no responsibility for any damage you cause or costs you incur.

-- sw

P.S. Did you take care of this too?

https://www.linode.com/community/questions/19082/i-just-created-my-first-linode-and-i-cant-send-emails-why

Hi, the last link you sent was the answer for my problem! I set the Gmail SMTP as relayhost and opened a support ticket for Linode concerning the SMTP restrictions.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct