Installing and Configuring Postfix

Postfix — mail transfer agent (MTA) with open source.

Assume that the IP address of the server is configured with a domain name, from which the mail will be sent in the future.

Switch directly to the root user:

sudo -i

Proceed to install Postfix.
To install in Ubuntu, perform:

apt-get update
apt-get install postfix

For installation in CentOS:

yum install postfix

During the installation, some questions will be asked:
1) Choose the “Internet site”
2) Specify the fully qualified domain name server (FQDN), for example example.com

After that Postfix will start working.
Configuration files are usually found in /etc/postfix.

We can look at the status/restart/stop/start Postfix commands:

service postfix status
service postfix restart
service postfix stop
service postfix start

If necessary, you can reconfigure by typing the following command:

dpkg-reconfigure postfix

Let’s see if the ports are used:

netstat -na | grep LISTEN | grep 25
netstat -na | grep LISTEN | grep 587

You can perform an automatic check of configuration, permissions on files, etc .:

postfix check

Let’s try to send the letter to the specified address (after the command we will type the desired text and put a point for completion):

sendmail -v admin@example.com

You can search the logs for the information you need via grep, for example, find all the lines that contain admin@example.com:

grep admin@example.com /var/log/mail.log

You can also connect from another host to the postfix port via telnet and make sure that it is running.

For diagnostics, you can observe the connections using tcpdump:

tcpdump port 25
tcpdump port 587

The message queue can be viewed with the commands:

mailq | less
postqueue -p | less
qshape
qshape deferred

View current and default parameters:

postconf
postconf -d

An example of viewing a specific parameter:

postconf | grep message_size_limit

An example of a parameter change (similar to a change in the configuration file):

postconf -e 'message_size_limit = 20480000'

If there are more than one IP on the server, and the domain is only on one, we will specify from which IP the sending will be done:

sudo nano /etc/postfix/main.cf
smtp_bind_address = 11.1.1.2

You can also specify on which interfaces Postfix will work:

#inet_interfaces = all
inet_interfaces = 127.0.0.1

Restart Postfix to apply the changes:

sudo /etc/init.d/postfix restart

See also my articles:

Leave a comment

Leave a Reply