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 start up),
33 or denial and theft of service attacks (including virtual hosts able
34 to steal hits from other virtual hosts).</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.example.dom> <br />
43 ServerAdmin webgirl@example.dom <br />
44 DocumentRoot /www/example <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.example.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.</p>
59 <p>Suppose that <code>www.example.dom</code> has address 192.0.2.1.
60 Then consider this configuration snippet:</p>
63 # This is a misconfiguration example, do not use on your server <br />
64 <VirtualHost 192.0.2.1> <br />
65 ServerAdmin webgirl@example.dom <br />
66 DocumentRoot /www/example <br />
70 <p>This time httpd needs to use reverse DNS to find the
71 <code>ServerName</code> for this virtualhost. If that reverse
72 lookup fails then it will partially disable the virtualhost.
73 If the virtual host is name-based then it will effectively be
74 totally disabled, but if it is IP-based then it will mostly
75 work. However, if httpd should ever have to generate a full
76 URL for the server which includes the server name (such as when a
77 Redirect is issued), then it will fail to generate a valid URL.</p>
79 <p>Here is a snippet that avoids both of these problems:</p>
82 <VirtualHost 192.0.2.1> <br />
83 ServerName www.example.dom <br />
84 ServerAdmin webgirl@example.dom <br />
85 DocumentRoot /www/example <br />
91 <title>Denial of Service</title>
93 <p>Consider this configuration snippet:</p>
96 <VirtualHost www.example1.dom><br />
98 ServerAdmin webgirl@example1.dom<br />
99 DocumentRoot /www/example1<br />
101 </VirtualHost><br />
103 <VirtualHost www.example2.dom><br />
105 ServerAdmin webguy@example2.dom<br />
106 DocumentRoot /www/example2<br />
111 <p>Suppose that you've assigned 192.0.2.1 to
112 <code>www.example1.dom</code> and 192.0.2.2 to
113 <code>www.example2.dom</code>. Furthermore, suppose that
114 <code>example1.dom</code> has control of their own DNS. With this
115 config you have put <code>example1.dom</code> into a position where
116 they can steal all traffic destined to <code>example2.dom</code>. To
117 do so, all they have to do is set <code>www.example1.dom</code> to
118 192.0.2.2. Since they control their own DNS you can't stop them
119 from pointing the <code>www.example1.dom</code> record wherever they
122 <p>Requests coming in to 192.0.2.2 (including all those where
123 users typed in URLs of the form
124 <code>http://www.example2.dom/whatever</code>) will all be served by
125 the <code>example1.dom</code> virtual host. To better understand why
126 this happens requires a more in-depth discussion of how httpd
127 matches up incoming requests with the virtual host that will
128 serve it. A rough document describing this <a
129 href="vhosts/details.html">is available</a>.</p>
133 <title>The "main server" Address</title>
135 <p><a href="vhosts/name-based.html">Name-based
136 virtual host support</a> requires httpd to know
137 the IP address(es) of the host that <program>httpd</program>
138 is running on. To get this address it uses either the global
139 <directive module="core">ServerName</directive>
140 (if present) or calls the C function <code>gethostname</code>
141 (which should return the same as typing "hostname" at the
142 command prompt). Then it performs a DNS lookup on this address.
143 At present there is no way to avoid this lookup.</p>
145 <p>If you fear that this lookup might fail because your DNS
146 server is down then you can insert the hostname in
147 <code>/etc/hosts</code> (where you probably already have it so
148 that the machine can boot properly). Then ensure that your
149 machine is configured to use <code>/etc/hosts</code> in the
150 event that DNS fails. Depending on what OS you are using this
151 might be accomplished by editing <code>/etc/resolv.conf</code>,
152 or maybe <code>/etc/nsswitch.conf</code>.</p>
154 <p>If your server doesn't have to perform DNS for any other
155 reason then you might be able to get away with running httpd
156 with the <code>HOSTRESORDER</code> environment variable set to
157 "local". This all depends on what OS and resolver libraries you
158 are using. It also affects CGIs unless you use
159 <module>mod_env</module> to control the environment. It's best
160 to consult the man pages or FAQs for your OS.</p>
164 <title>Tips to Avoid These Problems</title>
169 <directive module="core">VirtualHost</directive>
174 <directive module="mpm_common">Listen</directive>
178 ensure all virtual hosts have an explicit
179 <directive module="core">ServerName</directive>
182 <li>create a <code><VirtualHost _default_:*></code>
183 server that has no pages to serve</li>