There is a very annoying problem with postfix since upgrading from 16.04 to 16.10. I use postfix to send rkhunter and APC UPS power outage messages from my gmail account. Every time I reboot, the postfix /var/log/mail.log throws a “name service error…type=AAAA” whenever the system attempts to send a message. I found a solution on another forum, but it hasn’t solved the problem permanently. I change the line “inet_protocols = all” value to ipv4. The weird thing is that I have to toggle between “all” and “ipv4” to send mail. This temporarily solves the problem, but I always have to change the protocols. Sometimes, ipv4 works, other times, it’s the all value. I use network manager to manually assign an IP address, gateway, and DNS servers. I started out by using Google DNS as primary and openDNS as secondary. I changed the DNS server to my local router and the problem still persists, so I’m at a loss as to why both protocols work, but at different times. I’m on a Comcast 250 Mb business account.
I experienced the same issues when deploying Ubuntu 16.10 to a new MiniPC (opposed to Ubuntu 14.x that worked fine).
I have finally found an automated solution for this: enable the NetworkManager-wait-online.service and deploy a custom script that restarts the postfix service ±5 minutes after the machine has booted (assuming that the wireless connection is active by then).
A. Enable this.
systemctl enable NetworkManager-wait-online.service; systemctl status NetworkManager-wait-online.service;
B. Add a customer Systemd timer + service
@info The timer will start ONCE, {x} minutes after the machine was booted.
nano /etc/systemd/system/mjd-restart-postfix-after-wlan-connected.timer
[Unit]
Description=(timer)mjd-restart-postfix-after-wlan-connected
[Timer]
OnBootSec=5min
[Install]
WantedBy=timers.target
nano /etc/systemd/system/mjd-restart-postfix-after-wlan-connected.service
[Unit]
Description=mjd-restart-postfix-after-wlan-connected
[Service]
Type=oneshot
ExecStart=/bin/sh -ec "systemctl restart postfix; systemctl status postfix; uname -a | /usr/bin/mailx -s \"Server (`hostname`): postfix was restarted.\" [email protected]"
MYUNIT=mjd-restart-postfix-after-wlan-connected
MYTIMER=${MYUNIT}.timer
systemctl enable ${MYTIMER}; systemctl status ${MYTIMER};
systemctl list-units --all | grep "${${MYUNIT}}"
systemctl status | grep "${${MYUNIT}}"
C. Restart
````# wait 5 minutes
D. Check
MYUNIT=mjd-restart-postfix-after-wlan-connected
MYTIMER=${MYUNIT}.timer
systemctl status ${MYTIMER}
If the contents of these 2 config files (one of Resolve and one of Postfix) are not the same then the issue is PROBLEMATIC (Postfix started before LAN/WLAN gets connected).
cat /etc/resolv.conf
cat /var/spool/postfix/etc/resolv.conf
E. Info
@doc https://bugs.launchpad.net/ubuntu/+source/postfix/+bug/1519331
@doc https://wiki.archlinux.org/index.php/Systemd/Timers
@doc qshape deferred
@doc cat /var/log/syslog | egrep "NetworkManager|postfix"