]> granicus.if.org Git - apache/blob - docs/manual/dns-caveats.xml
move es and fr targets to *.utf8 extension. Update transformation
[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     <highlight language="config">
41 # This is a misconfiguration example, do not use on your server
42 &lt;VirtualHost www.example.dom&gt;
43   ServerAdmin webgirl@example.dom
44   DocumentRoot "/www/example"
45 &lt;/VirtualHost&gt;
46     </highlight>
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     <highlight language="config">
63 # This is a misconfiguration example, do not use on your server
64 &lt;VirtualHost 192.0.2.1&gt;
65   ServerAdmin webgirl@example.dom
66   DocumentRoot "/www/example"
67 &lt;/VirtualHost&gt;
68     </highlight>
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     <highlight language="config">
82 &lt;VirtualHost 192.0.2.1&gt;
83   ServerName www.example.dom
84   ServerAdmin webgirl@example.dom
85   DocumentRoot "/www/example"
86 &lt;/VirtualHost&gt;
87     </highlight>
88   </section>
89
90   <section id="denial">
91     <title>Denial of Service</title>
92
93     <p>Consider this configuration snippet:</p>
94
95     <highlight language="config">
96 &lt;VirtualHost www.example1.dom&gt;
97   ServerAdmin webgirl@example1.dom
98   DocumentRoot "/www/example1"
99 &lt;/VirtualHost&gt;
100 &lt;VirtualHost www.example2.dom&gt;
101   ServerAdmin webguy@example2.dom
102   DocumentRoot "/www/example2"
103 &lt;/VirtualHost&gt;
104     </highlight>
105
106     <p>Suppose that you've assigned 192.0.2.1 to
107     <code>www.example1.dom</code> and 192.0.2.2 to
108     <code>www.example2.dom</code>. Furthermore, suppose that
109     <code>example1.dom</code> has control of their own DNS. With this
110     config you have put <code>example1.dom</code> into a position where
111     they can steal all traffic destined to <code>example2.dom</code>. To
112     do so, all they have to do is set <code>www.example1.dom</code> to
113     192.0.2.2. Since they control their own DNS you can't stop them
114     from pointing the <code>www.example1.dom</code> record wherever they
115     wish.</p>
116
117     <p>Requests coming in to 192.0.2.2 (including all those where
118     users typed in URLs of the form
119     <code>http://www.example2.dom/whatever</code>) will all be served by
120     the <code>example1.dom</code> virtual host. To better understand why
121     this happens requires a more in-depth discussion of how httpd
122     matches up incoming requests with the virtual host that will
123     serve it. A rough document describing this <a
124     href="vhosts/details.html">is available</a>.</p>
125   </section>
126
127   <section id="main">
128     <title>The "main server" Address</title>
129
130     <p><a href="vhosts/name-based.html">Name-based
131     virtual host support</a> requires httpd to know
132     the IP address(es) of the host that <program>httpd</program>
133     is running on. To get this address it uses either the global
134     <directive module="core">ServerName</directive>
135     (if present) or calls the C function <code>gethostname</code>
136     (which should return the same as typing "hostname" at the
137     command prompt). Then it performs a DNS lookup on this address.
138     At present there is no way to avoid this lookup.</p>
139
140     <p>If you fear that this lookup might fail because your DNS
141     server is down then you can insert the hostname in
142     <code>/etc/hosts</code> (where you probably already have it so
143     that the machine can boot properly). Then ensure that your
144     machine is configured to use <code>/etc/hosts</code> in the
145     event that DNS fails. Depending on what OS you are using this
146     might be accomplished by editing <code>/etc/resolv.conf</code>,
147     or maybe <code>/etc/nsswitch.conf</code>.</p>
148
149     <p>If your server doesn't have to perform DNS for any other
150     reason then you might be able to get away with running httpd
151     with the <code>HOSTRESORDER</code> environment variable set to
152     "local". This all depends on what OS and resolver libraries you
153     are using. It also affects CGIs unless you use
154     <module>mod_env</module> to control the environment. It's best
155     to consult the man pages or FAQs for your OS.</p>
156   </section>
157
158   <section id="tips">
159     <title>Tips to Avoid These Problems</title>
160
161     <ul>
162       <li>
163         use IP addresses in
164         <directive module="core">VirtualHost</directive>
165       </li>
166
167       <li>
168         use IP addresses in
169         <directive module="mpm_common">Listen</directive>
170       </li>
171
172       <li>
173         ensure all virtual hosts have an explicit
174         <directive module="core">ServerName</directive>
175       </li>
176
177       <li>create a <code>&lt;VirtualHost _default_:*&gt;</code>
178       server that has no pages to serve</li>
179     </ul>
180   </section>
181
182 </manualpage>