Bobcares

Postfix Relayhost: Explained

by | Aug 29, 2022

 Let us take a closer look at the Postfix relayhost with the support of our Server Management Support services at Bobcares.

 Role of Relayserver in Postfix

postfix relayhost

A relay server is a server to which Postfix delegate email sending. So, Postfix will receive the emails and then forward them to the ‘smarthost.’ This structure is known as a Satellite System.

This form of design is particularly appealing if we have a huge online page that employs numerous services that require email transmission. To use the right SMTP service, several services or applications require the proper setup of config files. smtp

Having an internal Satellite System might be quite useful: the config files include all of the smarthost’s information, and only the smarthost knows which SMTP server to use to deliver emails. We can easily change the SMTP provider; simply alter the postfix configuration and everything will function flawlessly.

Postfix Relayhost configuration

The first step in postfix relayhost is to install postfix. Run the command:  sudo apt install postfix

OR

sudo apt-get install postfix

As the next step, a prompt will ask for the mail configuration. We can give the mail configurations that suites our requirements to proceed. Here the configuration is “Internet site”.

  • No configuration: Select to retain the current configuration.
  • Internet site: SMTP can send and receive email.
  • Internet with smarthost: Mail is received either directly through SMTP or with the use of a program such as fetchmail. A smarthost is used to send outgoing mail.
  • Satellite system: Routes All mail to another machine known as a’smarthost’ for delivery.
  • Local only: Local users’ mail is the only mail that is delivered. There isn’t any network.

Next request for the fully Qualified Domain Name (FQDN) for the server. This is the complete domain name (like abcd.com). Technically, a FQDN must terminate with a dot, however, Postfix does not need this.

The final step in effectively installing Postfix is to configure the relay host. The relay host is the hostname to which Postfix sends all incoming emails. This ensures an efficient postfix relayhost installation process.

Install pluggable authentication modules

Using the apt command, we must install the libsasl2-modules for authentication purposes for an easy postfix relayhost installation management: sudo apt-get install libsasl2-modules postfix

OR

sudo apt install libsasl2-modules postfix

Sample outputs: Reading package lists... Done Building dependency tree Reading state information... Done postfix is already the newest version (3.1.0-3). Suggested packages: libsasl2-modules-otp libsasl2-modules-ldap libsasl2-modules-sql libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal The following NEW packages will be installed: libsasl2-modules 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 47.5 kB of archives. After this operation, 227 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libsasl2-modules amd64 2.1.26.dfsg1-14build1 [47.5 kB] Fetched 47.5 kB in 0s (95.8 kB/s) Selecting previously unselected package libsasl2-modules:amd64. (Reading database ... 21643 files and directories currently installed.) Preparing to unpack .../libsasl2-modules_2.1.26.dfsg1-14build1_amd64.deb ... Unpacking libsasl2-modules:amd64 (2.1.26.dfsg1-14build1) ... Setting up libsasl2-modules:amd64 (2.1.26.dfsg1-14build1) ...

Configure myhostname

The next step in the postfix relayhost installation porcess is to edit /etc/postfix/main.cf, enter:

sudo vi /etc/postfix/main.cf

OR

sudo nano /etc/postfix/main.cf

Set myhostname to FQDN as configured earlier:

myhostname = bash.cyberciti.biz

Then we must save and close the file.

Setup the relay server for postfix relayhost

For this process, we have to open the /etc/postfix/main.cf, enter to continue with postfix relayhost process:

sudo vi /etc/postfix/main.cf

Edit/Update it by typing in the following codes:

# Enable auth
smtp_sasl_auth_enable = yes
# Set username and password
smtp_sasl_password_maps = static:YOUR-SMTP-USER-NAME-HERE:YOUR-SMTP-SERVER-PASSWORD-HERE smtp_sasl_security_options = noanonymous
# Turn on tls encryption
smtp_tls_security_level = encrypt
header_size_limit = 4096000
# Set external SMTP relay host here IP or hostname accepted along with a port number. relayhost = [YOUR-SMTP-SERVER-IP-HERE]:587
# accept email from our web-server only (adjust to match your VPC/VLAN etc) inet_interfaces = 127.0.0.1

After that, we have to Save and close the file. Since we changed to inet_interfaces, stop and start Postfix, type:

sudo systemctl stop postfix
sudo systemctl start postfix
OR sudo systemctl restart postfix

Using the netstat or ss commands, confirm that TCP port #25 is in the listed state on 127.0.0.1:

etstat -tulpn | grep :25

Sample outputs:

(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN

Send a test mail using Postfix the relay server

This is the final step in postfix relayhost process. The mail command has the following syntax:

echo "This is a test email body." | mail -s "Subject" -a "From: you@your-domain-dot-com" user@example-dot-com

To determine the email forwarding use the log file: sudo tail -f /var/log/mail.log

OR

sudo journalctl -u postfix

[Need assistance with similar queries? We are here to help]

Conclusion

To conclude we have learned how to setup and manage the postfix relayhost in a few simple steps starting from installing Postfix, pluggable authentication modules, and hostname configuration with our server management support services.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.