1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "./style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="./style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <manualpage metafile="dns-caveats.xml.meta">
25 <title>Issues Regarding DNS and Apache HTTP Server</title>
28 <p>This page could be summarized with the statement: don't
29 configure Apache HTTP Server in such a way that it relies on DNS resolution
30 for parsing of the configuration files. If httpd requires DNS
31 resolution to parse the configuration files then your server
32 may be subject to reliability problems (ie. it might not boot),
33 or denial and theft of service attacks (including users able
34 to steal hits from other users).</p>
37 <section id="example">
38 <title>A Simple Example</title>
41 # This is a misconfiguration example, do not use on your server <br />
42 <VirtualHost www.abc.dom> <br />
43 ServerAdmin webgirl@abc.dom <br />
44 DocumentRoot /www/abc <br />
48 <p>In order for the server to function properly, it absolutely needs
49 to have two pieces of information about each virtual host: the
50 <directive module="core">ServerName</directive> and at least one
51 IP address that the server will bind and respond to. The above
52 example does not include the IP address, so httpd must use DNS
53 to find the address of <code>www.abc.dom</code>. If for some
54 reason DNS is not available at the time your server is parsing
55 its config file, then this virtual host <strong>will not be
56 configured</strong>. It won't be able to respond to any hits
57 to this virtual host (prior to httpd version 1.2 the server
58 would not even boot).</p>
60 <p>Suppose that <code>www.abc.dom</code> has address 192.0.2.1.
61 Then consider this configuration snippet:</p>
64 # This is a misconfiguration example, do not use on your server <br />
65 <VirtualHost 192.0.2.1> <br />
66 ServerAdmin webgirl@abc.dom <br />
67 DocumentRoot /www/abc <br />
71 <p>This time httpd needs to use reverse DNS to find the
72 <code>ServerName</code> for this virtualhost. If that reverse
73 lookup fails then it will partially disable the virtualhost.
74 If the virtual host is name-based then it will effectively be
75 totally disabled, but if it is IP-based then it will mostly
76 work. However, if httpd should ever have to generate a full
77 URL for the server which includes the server name, then it will
78 fail to generate a valid URL.</p>
80 <p>Here is a snippet that avoids both of these problems:</p>
83 <VirtualHost 192.0.2.1> <br />
84 ServerName www.abc.dom <br />
85 ServerAdmin webgirl@abc.dom <br />
86 DocumentRoot /www/abc <br />
92 <title>Denial of Service</title>
94 <p>There are (at least) two forms that denial of service
95 can come in. If you are running a version of httpd prior to
96 version 1.2 then your server will not even boot if one of the
97 two DNS lookups mentioned above fails for any of your virtual
98 hosts. In some cases this DNS lookup may not even be under your
99 control; for example, if <code>abc.dom</code> is one of your
100 customers and they control their own DNS, they can force your
101 (pre-1.2) server to fail while booting simply by deleting the
102 <code>www.abc.dom</code> record.</p>
104 <p>Another form is far more insidious. Consider this
105 configuration snippet:</p>
108 <VirtualHost www.abc.dom><br />
110 ServerAdmin webgirl@abc.dom<br />
111 DocumentRoot /www/abc<br />
113 </VirtualHost><br />
115 <VirtualHost www.def.dom><br />
117 ServerAdmin webguy@def.dom<br />
118 DocumentRoot /www/def<br />
123 <p>Suppose that you've assigned 192.0.2.1 to
124 <code>www.abc.dom</code> and 192.0.2.2 to
125 <code>www.def.dom</code>. Furthermore, suppose that
126 <code>def.dom</code> has control of their own DNS. With this
127 config you have put <code>def.dom</code> into a position where
128 they can steal all traffic destined to <code>abc.dom</code>. To
129 do so, all they have to do is set <code>www.def.dom</code> to
130 192.0.2.1. Since they control their own DNS you can't stop them
131 from pointing the <code>www.def.dom</code> record wherever they
134 <p>Requests coming in to 192.0.2.1 (including all those where
135 users typed in URLs of the form
136 <code>http://www.abc.dom/whatever</code>) will all be served by
137 the <code>def.dom</code> virtual host. To better understand why
138 this happens requires a more in-depth discussion of how httpd
139 matches up incoming requests with the virtual host that will
140 serve it. A rough document describing this <a
141 href="vhosts/details.html">is available</a>.</p>
145 <title>The "main server" Address</title>
147 <p><a href="vhosts/name-based.html">Name-based
148 virtual host support</a> requires httpd to know
149 the IP address(es) of the host that <program>httpd</program>
150 is running on. To get this address it uses either the global
151 <directive module="core">ServerName</directive>
152 (if present) or calls the C function <code>gethostname</code>
153 (which should return the same as typing "hostname" at the
154 command prompt). Then it performs a DNS lookup on this address.
155 At present there is no way to avoid this lookup.</p>
157 <p>If you fear that this lookup might fail because your DNS
158 server is down then you can insert the hostname in
159 <code>/etc/hosts</code> (where you probably already have it so
160 that the machine can boot properly). Then ensure that your
161 machine is configured to use <code>/etc/hosts</code> in the
162 event that DNS fails. Depending on what OS you are using this
163 might be accomplished by editing <code>/etc/resolv.conf</code>,
164 or maybe <code>/etc/nsswitch.conf</code>.</p>
166 <p>If your server doesn't have to perform DNS for any other
167 reason then you might be able to get away with running httpd
168 with the <code>HOSTRESORDER</code> environment variable set to
169 "local". This all depends on what OS and resolver libraries you
170 are using. It also affects CGIs unless you use
171 <module>mod_env</module> to control the environment. It's best
172 to consult the man pages or FAQs for your OS.</p>
176 <title>Tips to Avoid These Problems</title>
181 <directive module="core">VirtualHost</directive>
186 <directive module="mpm_common">Listen</directive>
190 ensure all virtual hosts have an explicit
191 <directive module="core">ServerName</directive>
194 <li>create a <code><VirtualHost _default_:*></code>
195 server that has no pages to serve</li>
199 <section id="appendix">
200 <title>Appendix: Future Directions</title>
202 <p>The situation regarding DNS is highly undesirable. Although
203 we've attempted to make the server at least continue
204 booting in the event of failed DNS, it might not be the
205 best we can do. In any event, requiring the use of explicit IP
206 addresses in configuration files is highly undesirable in
207 today's Internet where renumbering is a necessity.</p>
209 <p>A possible work around to the theft of service attack
210 described above would be to perform a reverse DNS lookup on the
211 IP address returned by the forward lookup and compare the two
212 names -- in the event of a mismatch, the virtualhost would be
213 disabled. This would require reverse DNS to be configured
214 properly (which is something that most admins are familiar with
215 because of the common use of "double-reverse" DNS lookups by
216 FTP servers and TCP wrappers).</p>
218 <p>In any event, it doesn't seem possible to reliably boot a
219 virtual-hosted web server when DNS has failed unless IP
220 addresses are used. Partial solutions such as disabling
221 portions of the configuration might be worse than not booting
222 at all depending on what the webserver is supposed to
225 <p>As HTTP/1.1 is deployed and browsers and proxies start
226 issuing the <code>Host</code> header it will become possible to
227 avoid the use of IP-based virtual hosts entirely. In this case,
228 a webserver has no requirement to do DNS lookups during
229 configuration. But as of March 1997 these features have not
230 been deployed widely enough to be put into use on critical