Edit: For anyone else having this problem, this question was actually very badly asked/understood and a better description of the problem (and the correct solution) can be found here.

I'm trying to set up mail on my Raspberry Pi. I've set up and configured Postfix and everything generally works, except at boot it seems that the script /etc/init.d/postfix copies the file /etc/resolv.conf to its chroot before it's actually been updated. This reslults in email sending failing with DNS issues.

There's a better write-up of this in this blog post along with a workaround (injecting a "sleep 5" in the startup script).

I'm curious about how/why this happens (and why it's presumably affecting only the Pi, or few enough people that it hasn't been noticed/fixed) and where the bug actually lies (so I can raise it - is it a postfix issue, or something on the Pi not behaving as expected?).

The /etc/init.d/postfix file has this at the top (says it relies on network; not sure if that means it shouldn't start prior to resolveconf being done?)

# Provides:          postfix mail-transport-agent
# Required-Start:    $local_fs $remote_fs $syslog $named $network $time
# Required-Stop:     $local_fs $remote_fs $syslog $named $network
# Should-Start:      postgresql mysql clamav-daemon postgrey spamassassin saslauthd dovecot
# Should-Stop:       postgresql mysql clamav-daemon postgrey spamassassin saslauthd dovecot
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Postfix Mail Transport Agent
# Description:       postfix is a Mail Transport agent

What is the intended mechanism for ensuring this doesn't happen?

  • 1
    sleep 5 is not a good workaround for several reasons. i.e. does not work all the time. see the name of the dhcp init file/daemon and add it to Required start in the postfix init file. Commented Mar 27, 2016 at 10:06
  • Thanks! I'm a bit of a noob... I have a "/etc/init.d/dhcpcd" file, so do I just add the string "dhcpcd" to the line (the others all start with dollars and don't match names in the init.d folder). If you post this as an answer and it works; I'll accept :) Commented Mar 27, 2016 at 10:11
  • add it and test it out first if it works. There are other possible solutions too. Commented Mar 27, 2016 at 10:12
  • @RuiFRibeiro Adding "dhcpcd" to the end of the Required-Start line does not appear to have worked :( Commented Mar 27, 2016 at 10:25
  • I was already afraid of that. I am being dumb anyway. I have a good answer. Commented Mar 27, 2016 at 10:28

3 Answers 3


The problem is happening because of precedences. postfix startup seems to be finishing the job earlier than dhcpcd5.

One possible solution to fix the /etc/resolv.conf in the postfix jail after the DHCP client does the work. I suggest using dhclient and placing a script to fix the /etc/resolv.conf in the directory /etc/dhcp/dhclient-exit-hooks.d.

The scripts placed in this directory are executed after an IP is obtained by dhcp and those scripts are very useful to take measures needed after getting and/or changing an IP address.

I actually have a question talking about the theme here: Better method for acting on IP address change from the ISP?

The relevant package in Debian system is isc-dhcp-client, and if not installed, it can be installed doing:

sudo apt-get install isc-dhcp-client

Now /etc/network/interfaces has to be modified to use it:

auto eth0
iface eth0

and finally:

sudo dpkg --purge dhcpcd5

Actually, after uninstalling dhcpcd5 (and configuring /etc/network/interfaces together with @Danny), the precedences were enforced,and the postfix problem was solved.

Nevertheless, with machines directly connected to ISPes and permanently on, the script in dhclient-exit-hooks.d is also advised as the ISP can cause a change in your IP address.

  • My only concern with copying this single file is whether there are other files also missing (the postfix init.d script does a lot) and I don't want to duplicate the logic. I guess I could restart postfix (that works), but I don't know if that's a bit weird (letting it start up and immediately restarting!)? Commented Mar 27, 2016 at 10:36
  • Yes, it is a possibility. You can what actions you need to fix it. I also restart daemons there. (see the link to my question) Commented Mar 27, 2016 at 10:38
  • I created a file as root at /etc/dhcp/dhclient-exit-hooks.d/restart-postfix with the contents /etc/init.d/postfix restart however it doesn't seem to have fixed the issue. Upon reboot, the jailed resolve.conf is still bad. I'm not sure whether it's still running too soon, or not running at all. Commented Mar 27, 2016 at 13:00
  • please chmod the file to 755 and try again Commented Mar 27, 2016 at 13:11
  • 1
    Rui is right in that it's a precedences thing in the bootup scripts. I had the same problem and found that the easiest thing was to just add a restart of the postfix service into /etc/rc.local That way postfix re-copies the etc/resolv.conf after network is all up Commented Jan 27, 2017 at 16:08

On Ubuntu Zesty the following will work:

This fix will probably need to be done after any upgrade to postfix. Postscript fails after reboot because it does not wait for the network to come back up. This causes it to miss the entries in /etc/resolv.conf It is supposed to copy these to /var/spool/postfix/etc/resolv.conf

Change and/or add the following to the [Unit] blocks of these systemd files:

/lib/systemd/system/[email protected]

Add or change:


After making changes to a service reload systemctl:

systemctl daemon-reload


Note: The file that really matters is the [email protected]


Putting a script in /etc/dhcp/dhclient-exit-hooks.d/ on my raspberry with jessie 8.0 did not do anything. Even making it executable did not help. It seems those scripts are not run.
To me the issue is another bad example of the complexity introduced with systemd, network-manager and resolvconf.
Adding a line to /etc/rc.local did not work either.
I found that on my system /etc/rc.local is run 18s! before /etc/resolv.conf gets updated.
As the raspberry is on a local LAN I disabled the resolvconf mechanism by making /etc/resolv.conf immutable but even that did not help.
/var/spool/postfix/etc/resolv.conf now has the correct entries but postfix still does not run properly with entries hanging in the mqueue saying "(Host or domain name not found. Name service error for name=....com type=MX: Host not found, try again)"
I tried to batch restart postfix with a delay of 30s with the following line in /etc/rc.local ( sleep 30 ; service postfix restart ) &
Alas this did not work either.
But if I login to the system and manually restart postfix mail gets sent.
So I changed the entry to
( sleep 30 ; /etc/init/postfix stop ; sleep 5 ; /etc/init/postfix start ) &
which finally fixed the issue for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .