I a building an email server that will use Postfix for SMTP, and Dovecot for IMAP.

This server will have two interfaces:

  • wwan0 - this interface has a static public IP address, and will be used by Postfix for sending and receiving email, and Dovecot for remotely acessing IMAP - this interface has a limited usage cap as it is a 3G connection
  • wlan0 - this interface has a private IP address assigned by a wifi/ADSL router - this interface will be used by Dovecot for local IMAP, and for remaining non-Postfix outgoing traffic - this interface has a much larger usage cap

My understanding is that I will need to:

  • Tell Postfix to only use wwan0 by setting the inet_interfaces main.cf parameter to the public static IP - this should make Postfix only listen on wwan0, and send all outgoing traffic via wwan0
  • Set the default gateway to the ADSL router - this should cause all remaining traffic to go via the ADSL
  • Set Dovecot to listen on localhost so all interfaces respond to IMAP

A further extension to this would be to explore how to get the default gateway to failover to the wwan0 connection when the ADSL fails (sometimes the ADSL will drop but WiFi and router will stay up but not be able to forward any traffic).

I understand you can have multiple default gateways with different metrics, but I can't see how this would fix the ADSL going down but not the router (since gateway is still routable to but fails to forward the traffic).

I have seen suggestion that using a script that checks if the ADSL is still live (ping or HTTP) and changes the kernel routing table to direct traffic to the best interface.

Is my understanding correct?


If you will "Set the default gateway to the ADSL router", AFAIK this will cause all (not remaining!) traffic to go to the ADSL router. So the outgoing traffic from Postfix will also go through ADSL router. And this is probably not what you want...

The answer on this question - Get linux to change default route if one path goes down? - contains a link on how to implement policy based routing, which will be probably the most relevant solution in your case.

However, I'm not sure about your setup. As far as I understood, you have 2 Internet connections. And your mail server is connected to both of them. Then I'm not sure why do you need to always send outgoing traffic from Postfix to wwan0.

I would just setup it so:

  1. Postfix listens on wwan0
  2. Dovecot listens on both
  3. ALL outgoing traffic goes through ADSL router (default route)

In this case, I would just setup a secondary gateway (wwan0) with different metric without policy-based routing and apply a script to prefer (change metric of) a failover (secondary) gateway, when some resources are not anymore reachable through the primary gateway:


  • OK, I guess that would work, but don't spam filters get suspicious about outgoing mail being on a different IP than incoming? I new to setting up an email server. – ljbade Jul 24 '14 at 0:14
  • For the spam filters I probably can't help, sorry. – Andrey Sapegin Jul 24 '14 at 7:03
  • 2
    @Leith, spam filter doesn't care if incoming != outgoing IP, as long as your outgoing IP pass rDNS test – masegaloeh Jul 24 '14 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.