I have Postfix running on an Ubuntu 16.04 server for Gitlab and I am able to send email out to most domains except my corporate domain. From what I can tell, Postfix never tries the mail server IP address under my domain. For this example, say my email is skrawn@company.com and the mail server is at The Postfix mail log reports:

Jan  5 10:05:10 linux-dev postfix/smtp[2058]: connect to company.com[]:25: Connection timed out
Jan  5 10:05:40 linux-dev postfix/smtp[2058]: connect to company.com[]:25: Connection timed out
Jan  5 10:06:10 linux-dev postfix/smtp[2058]: connect to company.com[]:25: Connection timed out

So it's not even trying the actual mail server at I search around and saw suggestions of editing the /etc/hosts file to manually map the domain to the correct IP. So in my hosts file, I added:    company.com

Then to make Postfix use the hosts file as well as the DNS servers, I add this to /etc/postfix/main.cf:

smtp_host_lookup=dns, native

Reloaded postfix, restarted the server, etc. Postfix is still not trying the mail server IP.

So, I changed the /etc/postfix/main.cf to


And it works!

Jan  5 10:22:27 linux-dev postfix/smtp[1317]: 9DBC61A405FB: to=<skrawn@company.com>, relay=company.com[]:25, delay=90665, delays=90664/0.04/0.51/0.26, dsn=2.0.0, status=sent (250 Message accepted for delivery)

Ok, so maybe I just need to change the smtp_host_lookup so it checks native first:

smtp_host_lookup=native, dns

No luck. It sill won't try Any ideas on what I am missing the configuration? I'd like to be able to send emails both to that mail server and to other domains. Thank you for any help!

  • 2
    Usually this is done with MX records, not random hosts entries. – thrig Jan 5 '17 at 17:40
  • 1
    Agreed with @thrig; what do you see if you run dig mx yourcompany.com or host yourcompany.com? – DopeGhoti Jan 5 '17 at 17:42
  • $ dig mx company.com ; <<>> DiG 9.10.3-P4-Ubuntu <<>> mx company.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 11315 ;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4000 ;; QUESTION SECTION: ;company.com. IN MX ;; AUTHORITY SECTION: company.com. 699 IN SOA company.com. admin. 24380 900 600 86400 3600 ;; Query time: 0 msec ;; SERVER: ;; WHEN: Thu Jan 05 10:43:01 MST 2017 ;; MSG SIZE rcvd: 96 – skrawn Jan 5 '17 at 17:46
  • $ host company.com company.com has address company.com has address company.com has address – skrawn Jan 5 '17 at 17:47

Most of postfix trouble in communicating that I run in, I did fix with these settings.

inet_interfaces = all
myhostname = mail.dom.com
smtpd_banner = $myhostname
mydomain = dom.com
myorigin = $mydomain
mydestination = localhost
mynetworks =

Also in /etc/hosts       localhost       mail.dom.com alias   mail.dom.com  alias    mail.dom.com  alias  # YOUR ISP assigned IP

Also be sure that you select inet_interfaces = all so postfix can listen on all of your domains that you set in the /etc/hosts

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.