How to fix "dovecot: master: Error: socket() failed: Address family not supported by protocol" errors

botond published 2023/02/25, Sat - 08:03 time

Content

 

Introductory

Az ISPConfig after updating all services did not restart. In this case, Dovecot POP3/IMAP mail server, as well as the Postfix also threw warnings. Although we fixed these errors earlier, our settings were overwritten again during the ISPConfig update. In this troubleshooter, on the one hand, we fix "Address family not supported by protocol" type errors that cause the service to be inoperable, and we also make their permanent settings so that they remain even after further ISPConfig updates.

This description is carried out on my VPS server rented for this purpose, so the parts described here are presented in a live environment.

 

 

The symptom

The ISPConfig update script indicated an "Address family not supported by protocol" error during the configuration of Postfix services, which caused Postfix to start with warnings, but Dovecot no longer:

"Address family not supported by protocol" error occurring while updating ISPConfig

[...]
Reconfigure Services? (yes,no,selected) [yes]:

Configuring Postfix
postalias: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmap: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
postmap: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
[...]

Dovecot error while updating ISPConfig

[...]
Restarting services ...
Job for dovecot.service failed because the control process exited with error code.
See "systemctl status dovecot.service" and "journalctl -xe" for details.
Update finished.

In such cases, our mail system does not work, so we cannot access our email accounts either, because our Dovecot POP3/IMAP server is not running.

If the Monit on the service monitoring interface (if installed on our server), we see the problem here as well: Dovecot does not work, and as a result postfix cannot work properly either, since the mail forwarding service also depends on the operation of the mail server. In such cases, Monit stops monitoring the malfunctioning service, so the problem is immediately noticeable from here:

Monit - Postfix and Dovecot are not monitored

And if the systemctl command to look at the dovecot service, then we can also see the specific error message:

sudo systemctl status dovecot

Check Dovecot service status - The service is not working at all

 dovecot.service - Dovecot IMAP/POP3 email server
     Loaded: loaded (/lib/systemd/system/dovecot.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2023-02-24 21:07:07 CET; 18min ago
       Docs: man:dovecot(1)
             http://wiki2.dovecot.org/
    Process: 4016353 ExecStart=/usr/sbin/dovecot -F (code=exited, status=89)
   Main PID: 4016353 (code=exited, status=89)
        CPU: 110ms

Feb 24 21:07:07 vps dovecot[4016353]: master: Error: service(imap-login): listen([::], 143) failed: Address family not supported by protocol
Feb 24 21:07:07 vps dovecot[4016353]: Error: socket() failed: Address family not supported by protocol
Feb 24 21:07:07 vps dovecot[4016353]: Error: service(imap-login): listen([::], 993) failed: Address family not supported by protocol
Feb 24 21:07:07 vps dovecot[4016353]: Fatal: Failed to start listeners
Feb 24 21:07:07 vps dovecot[4016353]: master: Error: socket() failed: Address family not supported by protocol
Feb 24 21:07:07 vps dovecot[4016353]: master: Error: service(imap-login): listen([::], 993) failed: Address family not supported by protocol
Feb 24 21:07:07 vps dovecot[4016353]: master: Fatal: Failed to start listeners
Feb 24 21:07:07 vps systemd[1]: dovecot.service: Main process exited, code=exited, status=89/n/a
Feb 24 21:07:07 vps systemd[1]: dovecot.service: Failed with result 'exit-code'.
Feb 24 21:07:07 vps systemd[1]: Failed to start Dovecot IMAP/POP3 email server.

 

 

The reason of the error

The error is due to the fact that the management of the IPv6 network is disabled in our system, as a result of which various programs and services work incorrectly or not at all, because based on their settings, they would expect incoming connections on both the IPv4 and IPv6 networks. Some just throw an "Address family not supported by protocol" type error or warning, which causes them to continue running, but other programs and services don't even start. For example, Postfix belongs to the first camp, which only displays this error, then disables the use of its own IPv6 and finally starts, while Dovecot belongs to the other camp, which does not even start in this case. These programs must then be configured to not use the IPv6 network at all.

 

The solution

To fix "Address family not supported by protocol" errors, we need to look around the configuration files.

Configuring Dovecot

Let's fix the Dovecot configuration first, since this service won't start at all, so that's more important. Let's take a look at its configuration file to see what's going on there:

nano /etc/dovecot/dovecot.conf

At the very beginning of this we can see three lines:

# Do not change this file, as changes will be overwritten by any ISPConfig update.
# Put your custom settings in /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master.
# To start using those changes, do a force upgrade and let it reconfigure your services. (ispconfig_update.sh --force)

Here, in the first line, it says not to make changes to this file, because this file will be overwritten the next time ISPConfig is updated.

Of course, this short text does not reveal who exactly will overwrite this file and why, so I just add that ISPConfig stores the configuration files containing the appropriate settings of the services it manages and supervises in its own system (mostly in its database ) is stored in a "skeleton" structure. Then when an ISPConfig update is run, it reloads these files from this stored structure. That's why I also write elsewhere that we should not touch the configuration files, because ISPConfig will overwrite them. Thus, if, for example, we change a setting on its interface, it rebuilds the configuration file with the appropriate settings, overwrites the previous one, and then restarts the given service.
However, there are some parts that ISPConfig does not allow for individual setting on its own web interface, but it provides a solution for this in another way, where it provides the opportunity to specify our own settings. Here we come across one of these, which he continues in line 2 of the small commented text:

In the second line, describe where, if we have individual settings, we can enforce them. Also, in the last line, it informs that these can be implemented by updating the ISPConfig again --force by specifying a switch.

It is specified in the update script of ISPConfig --force switch does not have any special properties, it just runs the update even if our control panel already has the latest version. because without the switch, the update script exits in this case, saying that the update is not necessary.

The operating principle is thus the following: We must put our individual settings in the above-mentioned file, then when updating, the "official" config file is overwritten with the version stored in the skeleton and combined with the file containing our individual settings. Based on these, it is enough to include only the settings you want to change in this file, which in this case is a line that starts the configuration section:

listen = *,[::]

This setting controls whether Dovecot can also be used on the IPv4 network (*), and also on the IPv6 network ([::]) is waiting for connections. However, since the IPv6 network is disabled in our system, Dovecot does not start, since, as I mentioned above, this program is one of those programs that does not start if something is not right in the server environment according to its settings.

This setting must therefore be changed to the following in order for Dovecot to use only the IPv6 network according to our network configuration (disabled IPv4):

listen = *
Attention!
Those who arrived here (e.g. from search engines) do not have an ISPConfig control panel, so this did not modify this file, but use a server environment with a different system, they just disabled their IPv6 network, and that is why this error occurred, please do so the modification in this file (in this case, of course, the three-line ISPConfig description shown above should not be there either). Also, if they use another control panel that overwrites this file in a similar way, they should follow the instructions in their own system on where to make this change.
Since in this description we are dealing with the ISPConfig server environment, I will proceed accordingly here.

 

In a server environment with ISPConfig, we therefore create the appropriate file to perform our individual settings - for the sake of a permanent setting:

nano /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master

And add the following line:

listen = *

But connoisseurs can do it with just one command:

echo "listen = *" > /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master

If we already have such a file, which already contains individual settings, then we should append it to the file so that the other settings are not lost:

echo "listen = *" >> /usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master

(For example, if someone else managed the system before us, and so we don't know about the existence of this file)

 

 

Configuring Postfix

As I mentioned above, Postfix does work with this setting, but on the one hand, if we have already started, then let's be precise and make the setting here as well, and if we don't make it, then the /var/log/mail.log our file will be littered with "disabling IPv6 name/address support: Address family not supported by protocol" error messages. 

To see only the most recent ones from me:

The mail.log log file is full of "disabling IPv6 name/address support: Address family not supported by protocol" error messages

As I mentioned, the sending of letters still works because they are precisely "just" warnings, but if we need to find out any errors, it is very confusing if our log files are full of unnecessary error messages that we can easily avoid.

The configuration of Postfix is ​​defined in the /etc/postfix/main.cf can be found in file:

nano /etc/postfix/main.cf

And here we find the following line:

inet_protocols = all

And this should be changed to:

inet_protocols = ipv4

However, there is a little twist here, because if we overwrite this, the next ISPConfig update will run without a Postfix error, but the update script will also overwrite it. So, during the next update, it will issue warnings again. Here, however, there is no comment at the beginning of the configuration that would describe under what name ISPConfig will search for Postfix's individual configurations during the update. This information can be found in the ISPConfig installation package.

Of course, those who are not using the ISPConfig environment, but have just found themselves here and are reading this description, need only make the changes in this file, because this file will not be overwritten.

This part is here now I do not need it to implement, I'll just show you how to see what file name we need so that ISPConfig can read our custom settings from it, in case we need custom settings for other services:

cd /tmp

The latest ISPConfig download link can be obtained from the ISPConfig page:

At the time of writing this description, version 3.2.9 is the latest, so (staying in the /tmp directory) I download and unpack this:

wget https://ispconfig.org/downloads/ISPConfig-3.2.9.tar.gz
tar -xzf ISPConfig-3.2.9.tar.gz
cd ispconfig3_install/

After entering the main directory of the installation package, there is another one inside install / library and within that one tpl / library. I enter this:

cd install/tpl

There are many configuration files in this directory, for all services, which, if we look into them, each one has a description of what it is for. Here we now need the postfix config file. For this, I will list one, filtered for postfix:

ls -al | grep postfix

And here it releases several postfix files:

Locate the postfix custom configuration file in the ISPConfig installation package

It is there, so from here we need the "postfix_custom.conf.master" file. Let's take a look:

Viewing the postfix_custom.conf.master file

Here we already have the little comment we were looking for, which describes what to do with this file:

# You can use this file for custom Postfix settings. The used settings will overrule the settings set by ISPConfig.
# Use with caution!
# Put this file in /usr/local/ispconfig/server/conf-custom/install/ and make your changes there.

From here on, it is clearer than day what we have to do, continue the operation from here, if we omitted the above "investigation":

Let's copy this file to "location":

If you haven't done this part of downloading and extracting the installation package just now, create an empty file in the destination path with the name "postfix_custom.conf.master" and continue with it. You can even copy the above three comment lines into the file to keep everything in place.
cp postfix_custom.conf.master /usr/local/ispconfig/server/conf-custom/install/

Then open the file for editing:

nano /usr/local/ispconfig/server/conf-custom/install/postfix_custom.conf.master

And add the following line:

inet_protocols = ipv4

Edit the postfix_custom.conf.master file on the destination

Then save it.

 

 

Update ISPConfig

All that's left is to update our ISPConfig panel a --force switch:

ispconfig_update.sh --force

When updating, we can see that it has read the two custom configuration files:

/usr/local/ispconfig/server/conf-custom/install/dovecot_custom.conf.master
/usr/local/ispconfig/server/conf-custom/install/postfix_custom.conf.master

After that, Postfix error messages still appear during the first update:

Postfix error messages still appear during the first update of ISPConfig

Which might be an installation error, but regardless, there are no more error messages in the mail.log log file, so the custom setting works.

Also, if we run the update again, the error doesn't appear anymore:

Postfix error messages no longer appear during further updates of ISPConfig

There might be an error in the installer, but the point is that it works even after the first update, it only looks good if the error is no longer displayed.

Of course, it may happen that it gives error-free output immediately, I only put this here so that if the update script behaves like this elsewhere, you don't need to be afraid, because our unique setting works.

 

Control

Finally, if we have a Monit service monitoring system, we will issue the command to it to monitor all services, since the monitoring of the two faulty services was stopped earlier:

monit monitor all

Then update to the Monit interface:

Monit - The initialization of the monitoring of previously faulty services

Then we can see that the monitoring of the two services is initialized
Later when one expires Monit cycle, or press F5 in the browser, then everything is fine:

Monit - Everything is fine

After that, we also check the sending and receiving of letters, and for the sake of security, we can visit the /var/log/mail.log file to see if we still see "Address family not supported by protocol" error messages.

 

 

Conclusion

With this, we have permanently eliminated Dovecot's "Address family not supported by protocol" errors, because after updating ISPConfig, individual files containing our own settings were already used. However, do not forget that if you need to change any additional settings in the Dovecot or Postfix configurations later on, you should also do them in these individual files!