]> granicus.if.org Git - apache/blob - docs/manual/dns-caveats.xml
xforms
[apache] / docs / manual / dns-caveats.xml
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$ -->
5
6 <!--
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <manualpage metafile="dns-caveats.xml.meta">
24
25   <title>Issues Regarding DNS and Apache HTTP Server</title>
26
27   <summary>
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>
35   </summary>
36
37   <section id="example">
38     <title>A Simple Example</title>
39
40     <example>
41       # This is a misconfiguration example, do not use on your server <br />
42       &lt;VirtualHost www.example.dom&gt; <br />
43       ServerAdmin webgirl@example.dom <br />
44       DocumentRoot /www/example <br />
45       &lt;/VirtualHost&gt;
46     </example>
47
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>
58
59     <p>Suppose that <code>www.example.dom</code> has address 192.0.2.1.
60     Then consider this configuration snippet:</p>
61
62     <example>
63       # This is a misconfiguration example, do not use on your server <br />
64       &lt;VirtualHost 192.0.2.1&gt; <br />
65       ServerAdmin webgirl@example.dom <br />
66       DocumentRoot /www/example <br />
67       &lt;/VirtualHost&gt;
68     </example>
69
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>
78
79     <p>Here is a snippet that avoids both of these problems:</p>
80
81     <example>
82       &lt;VirtualHost 192.0.2.1&gt; <br />
83       ServerName www.example.dom <br />
84       ServerAdmin webgirl@example.dom <br />
85       DocumentRoot /www/example <br />
86       &lt;/VirtualHost&gt;
87     </example>
88   </section>
89
90   <section id="denial">
91     <title>Denial of Service</title>
92
93     <p>Consider this configuration snippet:</p>
94
95     <example>
96       &lt;VirtualHost www.example1.dom&gt;<br />
97       <indent>
98         ServerAdmin webgirl@example1.dom<br />
99         DocumentRoot /www/example1<br />
100       </indent>
101       &lt;/VirtualHost&gt;<br />
102       <br />
103       &lt;VirtualHost www.example2.dom&gt;<br />
104       <indent>
105         ServerAdmin webguy@example2.dom<br />
106         DocumentRoot /www/example2<br />
107       </indent>
108       &lt;/VirtualHost&gt;
109     </example>
110
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
120     wish.</p>
121
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>
130   </section>
131
132   <section id="main">
133     <title>The "main server" Address</title>
134
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>
144
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>
153
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>
161   </section>
162
163   <section id="tips">
164     <title>Tips to Avoid These Problems</title>
165
166     <ul>
167       <li>
168         use IP addresses in
169         <directive module="core">VirtualHost</directive>
170       </li>
171
172       <li>
173         use IP addresses in
174         <directive module="mpm_common">Listen</directive>
175       </li>
176
177       <li>
178         ensure all virtual hosts have an explicit
179         <directive module="core">ServerName</directive>
180       </li>
181
182       <li>create a <code>&lt;VirtualHost _default_:*&gt;</code>
183       server that has no pages to serve</li>
184     </ul>
185   </section>
186
187 </manualpage>