How can I have Postfix use /etc/hosts before doing a DNS lookup?

Posted on 2008-10-01
Last Modified: 2013-11-10
I have in /etc/hosts:  burritos

If I ping I get I can also telnet burritos 25 and I can deliver mail through mail from, rcpt to, data commands.

I have Postfix configured to deliver mail for locally, but it forwards mail for to server burritos.

The problem is Postfix does a DNS lookup regardless. It does not look into /etc/hosts. I don't have an A record for because I want it to only receive mail internally. I don't run a DNS server internally (which could obviously fix the problem, but is more complication than I'd like.)

/etc/host.conf says:
order hosts,bind
multi on
nospoof on
spoofalert on

I don't want to disable DNS lookups entirely. I just want for Postfix to check /etc/hosts first. Is that possible?

Question by:omniumnetworking
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
LVL 40

Expert Comment

ID: 22620011
check /etc/nsswitch.conf and look for a line similar to

hosts:      files dns

which should check /etc/hosts first then dns

Expert Comment

ID: 22620012
edit your /etc/nsswitch.conf file

change this line
hosts:      dns nis files

put files first

Expert Comment

ID: 22620017
omarfarid:  good timing :-)
Plug and play, no additional software required!

The ATEN UE3310 USB3.1 Gen1 Extender Cable allows users to extend the distance between the computer and USB devices up to 10 m (33 ft). The UE3310 is a high-quality, cost-effective solution for professional environments such as hospitals, factories and business facilities.

LVL 40

Expert Comment

ID: 22620029
same minute :)

Expert Comment

ID: 22620120
:) same answer
LVL 19

Expert Comment

ID: 22621050
Why not just have the transport table use the IP address instead of a name:
eg:    smtp:[]

Then you don't need to mess with the name resolution on your machine.

Author Comment

ID: 22625391
My /etc/nsswitch.conf already contains:
hosts:          files nis dns

I had checked that too.

I don't have anything on my transport table, so you'd have to be more specific.

LVL 19

Accepted Solution

bevhost earned 500 total points
ID: 22629885

Basically there is a file /etc/postfix/transport which contains a list of domain anmes and where the mail for thos domains should be routed to.  This routing table overrides and DNS settings.    smtp:[]

The [] brakets around the name tells the smtpd process not to try to look up the MX record for the target.
means send mail for to the MX record for    smtp:[]
means send mail for to the A record for    smtp:[]
means send mail for to server at

if you change the transport file you must
# postmap transport
# postfix reload

If you receive mail from external sources and you want to relay to transport destinations then you also need this in your file

relay_domains = $transport_maps

for the transport file to do anything you need this in your

transport_maps = hash:/etc/postfix/transport

LVL 19

Expert Comment

ID: 22629892
on re-reading that I notice a few typos, but you get the idea (I hope)
LVL 19

Expert Comment

ID: 22629905
For anyone reading this question who has sendmail instead of postfix,
The transport file is called /etc/mail/mailertable

Featured Post

Database Solutions Engineer FAQs

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller single-server environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Local Continuous Replication is a cost effective and quick way of backing up Exchange server data. The following article describes the steps required to configure Local Continuous Replication. Also, the article tells you how to restore from a backup…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question