How to Solve Error Message fatal: unable to use my own hostname when starting Postfix Mail Server in a Virtual Server

Posted on

Introduction

This article will explain how to solve the error message above. Basically, this error appear upon starting the postfix mail server’s service. The error message is ‘fatal: unable to use my own hostname’. Actually, this article has a relation with a previous article. That article is an article with the title of ‘How to Install Postfix Mail Server in Linux CentOS 8 running in a Virtual Server’ and it exist in this link. Basically, after the installation process is finish, there is an error message appear. The full error message execution, it exist as follows :

[root@10 ~]# systemctl start postfix
Job for postfix.service failed because the control process exited with error code.
See "systemctl status postfix.service" and "journalctl -xe" for details.
[root@10 ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Mon 2021-05-24 12:22:15 EDT; 4s ago
  Process: 82147 ExecStart=/usr/sbin/postfix start (code=exited, status=1/FAILURE)
  Process: 82144 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 82141 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=75)
May 24 12:22:12 10.0.2.15 systemd[1]: Starting Postfix Mail Transport Agent...
May 24 12:22:13 10.0.2.15 aliasesdb[82141]: /usr/sbin/postconf: warning: valid_hostname: numeric hostname: 10.0.2.15
May 24 12:22:13 10.0.2.15 aliasesdb[82141]: /usr/sbin/postconf: fatal: unable to use my own hostname
May 24 12:22:14 10.0.2.15 aliasesdb[82141]: newaliases: warning: valid_hostname: numeric hostname: 10.0.2.15
May 24 12:22:14 10.0.2.15 aliasesdb[82141]: newaliases: fatal: unable to use my own hostname
May 24 12:22:14 10.0.2.15 postfix[82147]: warning: valid_hostname: numeric hostname: 10.0.2.15
May 24 12:22:14 10.0.2.15 postfix[82147]: fatal: unable to use my own hostname
May 24 12:22:15 10.0.2.15 systemd[1]: postfix.service: Control process exited, code=exited status=1
May 24 12:22:15 10.0.2.15 systemd[1]: postfix.service: Failed with result 'exit-code'.
May 24 12:22:15 10.0.2.15 systemd[1]: Failed to start Postfix Mail Transport Agent.
[root@10 ~]# 
[root@10 ~]# vim /etc/postfix/main.cf
[root@10 ~]# systemctl start postfix
[root@10 ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-05-24 12:25:37 EDT; 3s ago
  Process: 82198 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 82196 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 82192 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 82266 (master)
    Tasks: 3 (limit: 11412)
   Memory: 6.5M
   CGroup: /system.slice/postfix.service
           ├─82266 /usr/libexec/postfix/master -w
           ├─82267 pickup -l -t unix -u
           └─82268 qmgr -l -t unix -u
May 24 12:25:36 10.0.2.15 systemd[1]: Starting Postfix Mail Transport Agent...
May 24 12:25:37 10.0.2.15 postfix/master[82266]: daemon started -- version 3.3.1, configuration /etc/postfix
May 24 12:25:37 10.0.2.15 systemd[1]: Started Postfix Mail Transport Agent.
[root@10 ~]#

Solution

Actually, there are a simple solution for solving the above error message appear. The focus of the error exist in the following lines :

May 24 12:22:13 10.0.2.15 aliasesdb[82141]: /usr/sbin/postconf: warning: valid_hostname: numeric hostname: 10.0.2.15 
May 24 12:22:13 10.0.2.15 aliasesdb[82141]: /usr/sbin/postconf: fatal: unable to use my own hostname 
May 24 12:22:14 10.0.2.15 aliasesdb[82141]: newaliases: warning: valid_hostname: numeric hostname: 10.0.2.15 
May 24 12:22:14 10.0.2.15 aliasesdb[82141]: newaliases: fatal: unable to use my own hostname

The Postfix Mail Server’s service cannot start properly. That is because by an assumption, one of the main reason is because the hostname is containing a numeric format. It exist by the following command execution to check the hostname of the server :

[admin@10 ~]$ hostname
10.0.2.15
[admin@10 ~]$

Actually, there are several solutions for solving the problems. In this article, at least there will be two solutions. The first solution is to change the hostname of the server or the machine manually. The second solution is to change the Postfix Mail Server’s configuration file. Maybe, there can be another solutions available out there. But this article will only show and provide two of them.

Changing the hostname as the Solution

As in the previous description, the first solution to solve the problem is by changing the hostname of the server or the machine manually. The main purpose is to be able to set the hostname into a non-numeric hostname. The following is the sequence for executing the solutions. First of all, change the hostname into a non-numeric form.

[admin@10 ~]$ sudo hostname localhost.localdomain.net
[admin@10 ~]$

Furthermore, although it is not a strict rule to use it, try to use a FQD (Fully Qualified Domain) name. Make sure that the form is actually inline with the form as in the above example. It is ‘localhost.localdomain.net’ for an example. After that, start the Postfix Mail Server as follows :

[admin@10 ~]$ sudo systemctl start postfix
[admin@10 ~]$

Following after, check the status of the service of Postfix Mail Server by executing the following command :

[admin@10 ~]$ sudo systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-05-25 13:01:28 EDT; 4s ago
  Process: 6392 ExecStop=/usr/sbin/postfix stop (code=exited, status=1/FAILURE)
  Process: 6565 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 6563 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 6561 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 6633 (master)
    Tasks: 3 (limit: 11428)
   Memory: 4.7M
   CGroup: /system.slice/postfix.service
           ├─6633 /usr/libexec/postfix/master -w
           ├─6634 pickup -l -t unix -u
           └─6635 qmgr -l -t unix -u
May 25 13:01:26 localhost.localdomain.net systemd[1]: Starting Postfix Mail Transport Agent...
May 25 13:01:28 localhost.localdomain.net postfix/master[6
May 25 13:01:28 localhost.localdomain.net systemd[1]: Started Postfix Mail Transport Agent.
[admin@10 ~]$

As in the output above appears, it informs that the Postfix Mail Server is already active properly.

 

Changing the Postfix Mail Server Configuration as the Solution

The second solution is another different one. It is solving the problem without having to change the hostname at all. Instead, it is achieving the target to solve the problem by changing the Postfix Mail Server. First of all, change it back to the original hostname setting :

[admin@10 ~]$ sudo hostname 10.0.2.15
[sudo] password for admin:
[admin@10 ~]$ hostname
10.0.2.15
[admin@10 ~]$

Stop the Postfix Mail Server’s service by the following command execution :

[admin@10 ~]$ systemctl stop postfix
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
Authentication is required to stop 'postfix.service'.
Multiple identities can be used for authentication:
 1.  Administrator (admin)
 2.  podman
Choose identity to authenticate as (1-2): 1
Password:
==== AUTHENTICATION COMPLETE ====
[admin@10 ~]$

By the time the Postfix Mail Server starts to run and active again by following the same previous command to start the service, suddenly it will fail to start as follows :

[admin@10 ~]$ systemctl start postfix
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
Authentication is required to start 'postfix.service'.
Multiple identities can be used for authentication:
 1.  Administrator (admin)
 2.  podman
Choose identity to authenticate as (1-2): 1
Password:
==== AUTHENTICATION COMPLETE ====
Job for postfix.service failed because the control process exited with error code.
See "systemctl status postfix.service" and "journalctl -xe" for details.
[admin@10 ~]$

It obvious, since the hostname value is back to the previous numeric format. In order to prove it, just check the status of the Postfix Mail Server’s service as follows :

[admin@10 ~]$
systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2021-05-25 13:56:49 EDT; 18s ago
  Process: 6783 ExecStop=/usr/sbin/postfix stop (code=exited, status=1/FAILURE)
  Process: 6808 ExecStart=/usr/sbin/postfix start (code=exited, status=1/FAILURE)
  Process: 6806 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 6803 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=75)
 Main PID: 6633 (code=killed, signal=TERM)
May 25 13:56:47 10.0.2.15 aliasesdb[6803]: /usr/sbin/postconf: fatal: unable to use my own hostname
May 25 13:56:48 10.0.2.15 aliasesdb[6803]: newaliases: warning: valid_hostname: numeric hostname: 10.0.2.15
May 25 13:56:48 10.0.2.15 aliasesdb[6803]: newaliases: fatal: unable to use my own hostname
May 25 13:56:48 10.0.2.15 postfix/sendmail[6805]: warning: valid_hostname: numeric hostname: 10.0.2.15
May 25 13:56:48 10.0.2.15 postfix/sendmail[6805]: fatal: unable to use my own hostname
May 25 13:56:48 10.0.2.15 postfix[6808]: warning: valid_hostname: numeric hostname: 10.0.2.15
May 25 13:56:48 10.0.2.15 postfix[6808]: fatal: unable to use my own hostname
May 25 13:56:49 10.0.2.15 systemd[1]: postfix.service: Control process exited, code=exited status=1
May 25 13:56:49 10.0.2.15 systemd[1]: postfix.service: Failed with result 'exit-code'.
May 25 13:56:49 10.0.2.15 systemd[1]: Failed to start Postfix Mail Transport Agent.
[admin@10 ~]$

So, what about the solution then. The answer is simple. The solution is by editing the Postfix Mail Server by executing the following command :

 
[admin@10 ~]$ sudo vim /etc/postfix/main.cf
[admin@10 ~]$

The following is the addition of a new line where is important to be able to solve the problem to the Postfix Mail Server’s configuration file. It exist in ‘/etc/postfix/main.cf’. Just add the following line :

myhostname = localhost.localdomain.net

After that, save and close it. Try to start the Postfix Mail Server again once more as follows :

[admin@10 ~]$ [admin@10 ~]$ sudo systemctl start postfix
[admin@10 ~]$

Apparently executing the above single line command to start Postfix Mail Server does not trigger any problem. For the last time, try to check the hostname just to make sure by executing the following command :

[admin@10 ~]$ hostname
10.0.2.15
[admin@10 ~]$

Last but not least, check the Postfix Mail Server’s service status as follows :

[admin@10 ~]$ systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-05-25 13:59:04 EDT; 7s ago
  Process: 6783 ExecStop=/usr/sbin/postfix stop (code=exited, status=1/FAILURE)
  Process: 6876 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 6874 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 6872 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 6944 (master)
    Tasks: 3 (limit: 11428)
   Memory: 4.6M
   CGroup: /system.slice/postfix.service
           ├─6944 /usr/libexec/postfix/master -w
           ├─6945 pickup -l -t unix -u
           └─6946 qmgr -l -t unix -u
May 25 13:59:01 10.0.2.15 systemd[1]: Starting Postfix Mail Transport Agent...
May 25 13:59:04 10.0.2.15 postfix/postfix-script[6942]: starting the Postfix mail system
May 25 13:59:04 10.0.2.15 postfix/master[6944]: daemon started -- version 3.3.1, configuration /etc/postfix
May 25 13:59:04 10.0.2.15 systemd[1]: Started Postfix Mail Transport Agent.
[admin@10 ~]$

So, the action for solving the problem by modifying the Postfix Mail Server is actually working as it shows in the above output command.

Leave a Reply