11.5. Avoiding DNS Lookups
Problem
You want to avoid situations where you have to do DNS lookups of client addresses, as this is a very slow process.
Solution
Always set the HostNameLookups directive to
Off:
HostNameLookups Off
Make sure that, whenever possible, Allow from and/or Deny from directives use
the IP address, rather than the hostname of the hosts in
question.
Discussion
DNS lookups can take a very long time—anywhere from 0 to 60 seconds—and should be avoided at all costs. In the event that a client address cannot be looked up at all, it can take up to a minute for the lookup to time out, during which time the child process that is doing the lookup cannot do anything else.
There are a number of cases in which Apache will need to do DNS lookups, and so the goal here is to completely avoid those situations.
HostNameLookups
Before Apache 1.3, HostNameLookups, which determines whether
Apache logs client IP addresses or hostnames, defaulted to
on, meaning that each Apache log entry required a DNS lookup to convert the
client IP address to a hostname to put in the logfile. Fortunately,
that directive now defaults to off, and so this is
primarily an admonition to leave it alone.
If you need to have these addresses converted to hostnames, this should be done by another program, preferably running on a machine other than your production Web server. That is, you really should copy the file to some other machine for the purpose of processing, so that the effort required to do this processing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access