| 1 |
<!-- Debian Network Administartor's Manual - Overview of TCP/IP -->
|
| 2 |
|
| 3 |
<chapt id="tcpip">
|
| 4 |
|
| 5 |
<heading>TCP/IP</heading>
|
| 6 |
|
| 7 |
<p>
|
| 8 |
author = Duncan C Thomson <email>duncan@sciuro.demon.co.uk</email>
|
| 9 |
</p>
|
| 10 |
|
| 11 |
<p>
|
| 12 |
topics = IP protocol, TCP protocol, IP addresses, IP interfaces, Routing
|
| 13 |
</p>
|
| 14 |
|
| 15 |
|
| 16 |
<sect>Intro
|
| 17 |
<p>TCP/IP, as the name suggests, is a pair of protocols, and what most
|
| 18 |
of the Internet is built on. Although physically the Internet is
|
| 19 |
made up of a wide range of networking technologies, from slow modem
|
| 20 |
links through Ethernet, to high-speed ATM-based switched networks,
|
| 21 |
and a wide range of different applications run over it - the WWW and
|
| 22 |
e-mail to name only two, the protocols which tie everything together
|
| 23 |
are Internet Protocol (IP), and, perhaps almost as great an extent,
|
| 24 |
Transmission Control Protocol. Another protocol, UDP, is used
|
| 25 |
in place of TCP for some applications, especially in LAN
|
| 26 |
environments, but on the Internet the TCP/IP partnership rules.</p>
|
| 27 |
|
| 28 |
<p>diagram: various physical networks, IP, TCP and UDP, apps</p>
|
| 29 |
|
| 30 |
<p>This chapter describes firstly the basics of IP networking, and
|
| 31 |
later describes some of the more advanced features of TCP/IP available
|
| 32 |
to the Debian user.</p>
|
| 33 |
</sect>
|
| 34 |
|
| 35 |
<sect>IP Addresses
|
| 36 |
|
| 37 |
<p>Every computer connected directly to the Internet (or to any IP-based
|
| 38 |
network) is identified by an IP address. IP addresses are four bytes
|
| 39 |
long, and are usually written as four decimal numbers separated by dots,
|
| 40 |
as in the examples below.
|
| 41 |
<list>
|
| 42 |
<item>10.34.92.111</item>
|
| 43 |
<item>127.0.0.1</item>
|
| 44 |
<item>172.19.220.2</item>
|
| 45 |
<item>192.168.50.109</item>
|
| 46 |
</list>
|
| 47 |
<p>IP addresses typically identify two things. Firstly, they identify the
|
| 48 |
network on which a particular computer is located. Secondly, they
|
| 49 |
identify a particular computer on that network. Both these pieces of
|
| 50 |
information are present in an IP address, and they can be called the
|
| 51 |
<em>network part</em> and the <em>host part</em>.
|
| 52 |
Two special values for the host part
|
| 53 |
should be mentioned here - if the host part is all zeros, the
|
| 54 |
address refers to a network (ie it is a <em>network address</em> as
|
| 55 |
opposed to a <em>host address</em>). If, alternatively, the host part
|
| 56 |
is all ones, the address refers to all hosts on the network (ie it is a
|
| 57 |
<em>broadcast</em> address).</p>
|
| 58 |
|
| 59 |
<p>In order to identify which part of the IP address is the host part,
|
| 60 |
and which part is the network part, there are two methods we can use. The
|
| 61 |
first (and original) way is the easier by far to understand, so let's start
|
| 62 |
by having a look at how it works. IP addresses are split into a number of
|
| 63 |
<em>classes</em>, and it is this class which tells us how to split an IP
|
| 64 |
address into its network and host parts.
|
| 65 |
<taglist>
|
| 66 |
<tag>Class A</tag>
|
| 67 |
<item>A class A IP address has as its first byte a number between 1 and
|
| 68 |
126. The first byte of a class A IP address identifies the network, and
|
| 69 |
the remaining three bytes identify the host.</item>
|
| 70 |
<tag>Class B</tag>
|
| 71 |
<item>A class B IP address has as its first byte a number between 128 and
|
| 72 |
191. Its first two bytes are the network identifier, and the remaining
|
| 73 |
two bytes are the host identifier on that network.</item>
|
| 74 |
<tag>Class C</tag>
|
| 75 |
<item>A class C IP address has as its first byte a number between 192 and
|
| 76 |
223. Its first three bytes identify the network, and the remaining byte
|
| 77 |
identifies an individual host on that network.</item>
|
| 78 |
</taglist></p>
|
| 79 |
|
| 80 |
<p>From the above list you might notice that IP addresses beginning with
|
| 81 |
bytes from 224 and upwards are missing. These belong to other classes of
|
| 82 |
IP address, not used for a normal IP host, and are beyond the discussion
|
| 83 |
in this section.</p>
|
| 84 |
|
| 85 |
<p>You might also notice that IP addresses beginning with 127 are missing.
|
| 86 |
IP addresses beginning with 127 are known as <em>loopback</em> addresses,
|
| 87 |
and can be used for testing TCP/IP without actually having a network
|
| 88 |
connection.</p>
|
| 89 |
|
| 90 |
<p>This is all very well, but what if we have been assigned a single
|
| 91 |
class C address range, but want to split it among several networks? This
|
| 92 |
is where the second method of specifying the network and host parts can be
|
| 93 |
used. This method specifies, along with an IP address, a <em>netmask</em>,
|
| 94 |
which has its bits set to one in the network part, and set to zero in the
|
| 95 |
host part. So, for example, the default netmask for the various classes
|
| 96 |
of network as as below:
|
| 97 |
<taglist>
|
| 98 |
<tag>Class A</tag>
|
| 99 |
<item>255.0.0.0</item>
|
| 100 |
<tag>Class B</tag>
|
| 101 |
<item>255.255.0.0</item>
|
| 102 |
<tag>Class C</tag>
|
| 103 |
<item>255.255.255.0</item>
|
| 104 |
</taglist></p>
|
| 105 |
|
| 106 |
<p>These don't give us any new information beyond what the original address
|
| 107 |
classes told us. The power in using netmasks, though, is that we can
|
| 108 |
choose arbitrary splits between the network and host parts - for example,
|
| 109 |
a netmask of 255.255.255.192 would allow us to split a class C network
|
| 110 |
into four parts, each with 62 host addresses. Confused? Let's look at
|
| 111 |
that example in more detail.</p>
|
| 112 |
|
| 113 |
<p>Let's suppose we've been allocated a class C network with IP addresses
|
| 114 |
beginning with 192.168.50. If we convert the netmask 255.255.255.192 into
|
| 115 |
binary, we can see that in the last byte, the first two bits are one (that
|
| 116 |
is, they are included in the network part of the address) and the last six
|
| 117 |
bits are zeros (that is, they form the host part). So, by using the IP
|
| 118 |
addresses we have been given, along with this netmask, we have split our
|
| 119 |
network into four, with <em>network addresses</em> given by setting these
|
| 120 |
two bits to their four possible combinations (00, 01, 10, 11) while
|
| 121 |
keeping the host part set to zeros (to identify the network):
|
| 122 |
<list>
|
| 123 |
<item>192.168.50.0</item>
|
| 124 |
<item>192.168.50.64</item>
|
| 125 |
<item>192.168.50.128</item>
|
| 126 |
<item>192.168.50.192</item>
|
| 127 |
</list></p>
|
| 128 |
|
| 129 |
<p>Now we know where our four network addresses come from. What about our
|
| 130 |
host addresses? They come from setting the host part in each <em>subnet</em>
|
| 131 |
to all values from 000001 to 111110 (remember - all ones is a broadcast
|
| 132 |
address). That gives us a total of 62 hosts in each network, with addresses:
|
| 133 |
<list>
|
| 134 |
<item>192.168.50.1 - 192.168.50.62</item>
|
| 135 |
<item>192.168.50.65 - 192.168.50.126</item>
|
| 136 |
<item>192.168.50.129 - 192.168.50.190</item>
|
| 137 |
<item>192.168.50.193 - 192.168.50.254</item>
|
| 138 |
</list></p>
|
| 139 |
|
| 140 |
<p>In Linux, if we don't mention what netmask we are using, it's usually
|
| 141 |
assumed by the software that we want to use the default netmask for that
|
| 142 |
particular class of IP addresses. You should only need to specify a netmask
|
| 143 |
if you are using one which is not the standard scheme for a particular class
|
| 144 |
of IP addresses. It never does any harm to specify it though.</p>
|
| 145 |
|
| 146 |
<p>Each IP address should be <em>unique</em> on the Internet, or whichever
|
| 147 |
IP network you are connected to. This means that your cannot assign IP
|
| 148 |
addresses at random to your machines, since most IP addresses are already
|
| 149 |
in use on the Internet. In order to get a legal set of IP addresses for
|
| 150 |
your machines, you will normally go through an Internet Service Provider
|
| 151 |
(ISP). If you have not been assigned such a range of addresses, you
|
| 152 |
should use one of the range of <em>private</em> IP addresses, set aside for
|
| 153 |
internet or testing use. Be aware that you will not be able to connect to
|
| 154 |
the Internet directly from such a network; you will need to use some form
|
| 155 |
of Network Address Translation (NAT) to do this. The ranges of IP addresses
|
| 156 |
set aside for private use are:
|
| 157 |
<list>
|
| 158 |
<item>10.0.0.0: a single class A network</item>
|
| 159 |
<item>172.16.0.0 - 172.31.0.0: 16 class B networks</item>
|
| 160 |
<item>192.168.0.0 - 192.168.255.0: 256 class C networks</item>
|
| 161 |
</list></p>
|
| 162 |
|
| 163 |
</sect>
|
| 164 |
|
| 165 |
<sect>IP Interface Configuration
|
| 166 |
|
| 167 |
<p>Once we know what IP address we wish to use for our machine, we will
|
| 168 |
have to bring up one of our network interfaces, and assign that IP address
|
| 169 |
(possibly along with a netmask) to it. On most Debian systems this is done
|
| 170 |
when installing the system, and you are seldom likely to need to change
|
| 171 |
it on a simple system.</p>
|
| 172 |
|
| 173 |
<p>The <prgn>ifconfig</prgn> command is used to configure interfaces in
|
| 174 |
order to use IP with them. There are a number of different network
|
| 175 |
interfaces available with the Linux kernel, some of which are summarised
|
| 176 |
below:
|
| 177 |
<taglist>
|
| 178 |
<tag>Loopback</tag>
|
| 179 |
<item>The loopback interface (<tt>lo</tt>), usually configured as IP
|
| 180 |
address 127.0.0.1</item>
|
| 181 |
<tag>Ethernet</tag>
|
| 182 |
<item>Ethernet interfaces (with names like <tt>eth0</tt>, <tt>eth1</tt>,
|
| 183 |
<tt>eth2</tt>) are used to access Ethernet cards</item>
|
| 184 |
<tag>PPP</tag>
|
| 185 |
<item>PPP stands for Point-to-Point Protocol, and is used to run a variety
|
| 186 |
of networking protocols, including IP, over any kind of serial lines
|
| 187 |
(null modem, modem, ISDN). They have names like <tt>ppp0</tt>,
|
| 188 |
<tt>ppp1</tt></item>
|
| 189 |
<tag>Token Ring</tag>
|
| 190 |
<item>Token Ring devices are accessed with device names like <tt>tr0</tt>,
|
| 191 |
<tt>tr1</tt></item>
|
| 192 |
<tag>Dummy</tag>
|
| 193 |
<item>The dummy network drivers are used in systems who have an interface
|
| 194 |
which is not always used, in order to provide a permanent IP interface
|
| 195 |
for the relevant address. The device names are <tt>dummy</tt>, or
|
| 196 |
<tt>dummy0</tt>, <tt>dummy1</tt>, and so on</item>
|
| 197 |
</taglist>
|
| 198 |
There are a wide range of other network devices available, including
|
| 199 |
SLIP, PLIP (serial and parallel line IP), `shaper' devices for controlling
|
| 200 |
the traffic on certain interfaces, the ability to have several IP addresses
|
| 201 |
on a single device, as well as frame relay, AX.25, X.25, ARCnet, LocalTalk
|
| 202 |
and more. Here, though, we'll concentrate on one of the most common - the
|
| 203 |
Ethernet interface.</p>
|
| 204 |
|
| 205 |
<p>In many cases, if you wish your kernel to automatically load modules
|
| 206 |
for certain device drviers, you may require to make changes to your
|
| 207 |
<prgn>/etc/conf.modules</prgn> or <prgn>/etc/modules</prgn> file. For
|
| 208 |
example, to automatically load the NE2000 driver, you could have the
|
| 209 |
line:
|
| 210 |
<example>
|
| 211 |
alias eth0 ne
|
| 212 |
</example>
|
| 213 |
in your <prgn>/etc/conf.modules</prgn> file.</p>
|
| 214 |
|
| 215 |
<p>The simplest way to call <prgn>ifconfig</prgn> is to simply type its
|
| 216 |
name:
|
| 217 |
<example>
|
| 218 |
# /sbin/ifconfig
|
| 219 |
lo Link encap:Local Loopback
|
| 220 |
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
|
| 221 |
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
|
| 222 |
RX packets:18584 errors:0 dropped:0 overruns:0 frame:0
|
| 223 |
TX packets:18584 errors:0 dropped:0 overruns:0 carrier:0
|
| 224 |
Collisions:0
|
| 225 |
</example>
|
| 226 |
which simply returns information about the interfaces currently
|
| 227 |
configured. If we wish now to bring up an Ethernet interface with the
|
| 228 |
address 192.168.50.23, we'd specify the interface name and the IP address
|
| 229 |
on <prgn>ifconfig</prgn>'s command line:
|
| 230 |
<example>
|
| 231 |
# /sbin/ifconfig eth0 192.168.50.23
|
| 232 |
# /sbin/ifconfig
|
| 233 |
lo Link encap:Local Loopback
|
| 234 |
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0
|
| 235 |
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1
|
| 236 |
RX packets:18584 errors:0 dropped:0 overruns:0 frame:0
|
| 237 |
TX packets:18584 errors:0 dropped:0 overruns:0 carrier:0
|
| 238 |
Collisions:0
|
| 239 |
|
| 240 |
eth0 Link encap:Ethernet HWaddr 00:00:E8:C5:64:2A
|
| 241 |
inet addr:192.168.50.23 Bcast:192.168.50.255 Mask:255.255.255.0
|
| 242 |
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
| 243 |
RX packets:55 errors:0 dropped:0 overruns:0 frame:0
|
| 244 |
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
|
| 245 |
Collisions:7
|
| 246 |
Interrupt:10 Base address:0x300
|
| 247 |
</example>
|
| 248 |
As can be seen from the example, the <prgn>ifconfig</prgn> now gives
|
| 249 |
information about the new interface, including the netmask, network
|
| 250 |
statistics, and information about the network driver itself. The
|
| 251 |
<prgn>ifconfig</prgn> also allows the specification of a netmask when
|
| 252 |
the interface is configured, for example:
|
| 253 |
<example>
|
| 254 |
# /sbin/ifconfig eth0 192.168.50.23 netmask 255.255.255.192
|
| 255 |
</example>
|
| 256 |
Finally, to bring down an interface, use the following invocation of
|
| 257 |
<prgn>ifconfig</prgn>:
|
| 258 |
<example>
|
| 259 |
# /sbin/ifconfig eth0 down
|
| 260 |
</example>
|
| 261 |
Full information on the options available to <prgn>ifconfig</prgn> are
|
| 262 |
available in the manual page - <manref name="ifconfig" section="8">.</p>
|
| 263 |
|
| 264 |
<p>If you set up the IP addressing on your machine when you installed
|
| 265 |
Debian GNU/Linux, you should find that the <prgn>ifconfig</prgn> command
|
| 266 |
is run automatically on bootup. This is done from the file
|
| 267 |
<prgn>/etc/init.d/network</prgn>. Looking at this file should reveal a
|
| 268 |
number of lines similar to the following:
|
| 269 |
<example>
|
| 270 |
IPADDR=192.168.50.23
|
| 271 |
NETMASK=255.255.255.0
|
| 272 |
BROADCAST=192.168.50.255
|
| 273 |
ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
|
| 274 |
</example>
|
| 275 |
This is where the setting up of the Ethernet interface takes place. Above
|
| 276 |
these lines, you should see a line setting up the loopback interface, and
|
| 277 |
you should see a number of lines which appear to run a command called
|
| 278 |
<prgn>route</prgn>. This program, and its function, is the subject of
|
| 279 |
the next section.</p>
|
| 280 |
</sect>
|
| 281 |
|
| 282 |
<sect>Basic IP Routing
|
| 283 |
<p>Once an IP interface has been set up, it is necessary that the Linux
|
| 284 |
kernel be told where to send IP information for various machines on the
|
| 285 |
IP network. The kernel holds a table, called a <em>routing table</em>,
|
| 286 |
which lists a number of host or network addresses, along with
|
| 287 |
information on how to send IP packets to these destinations.</p>
|
| 288 |
|
| 289 |
<p>The <prgn>route</prgn> command is use to examine or update this table.
|
| 290 |
If only your loopback interface has been configured, this command used
|
| 291 |
on its own will typically give output which looks something like the
|
| 292 |
following:
|
| 293 |
<example>
|
| 294 |
# /sbin/route
|
| 295 |
Kernel IP routing table
|
| 296 |
Destination Gateway Genmask Flags Metric Ref Use Iface
|
| 297 |
127.0.0.0 * 255.0.0.0 U 0 0 2 lo
|
| 298 |
</example>
|
| 299 |
<p>This says that any traffic for the network identified as `127' should be
|
| 300 |
routed through the loopback interface (<tt>lo</tt>). The `genmask' column
|
| 301 |
specifies, in a similar way to a netmask, that this particular routing
|
| 302 |
table entry should be used to match any IP address beginning with the
|
| 303 |
number 127, no matter what the remainder is.</p>
|
| 304 |
|
| 305 |
<p>If our machine is connected to an Ethernet network, then typically we
|
| 306 |
will want to make sure that the kernel routing table knows how to send
|
| 307 |
information to this. Assuming we have set up our machine to be
|
| 308 |
192.168.50.23, with a default class C netmask, the following command
|
| 309 |
will add a routing table entry for our local network:
|
| 310 |
<example>
|
| 311 |
# /sbin/route add -net 192.168.50.0
|
| 312 |
# /sbin/route
|
| 313 |
Kernel IP routing table
|
| 314 |
Destination Gateway Genmask Flags Metric Ref Use Iface
|
| 315 |
127.0.0.0 * 255.0.0.0 U 0 0 2 lo
|
| 316 |
192.168.50.0 * 255.255.255.0 U 0 0 137 eth0
|
| 317 |
</example>
|
| 318 |
<p>This tells the kernel that any IP addresses which start with 192.168.50 are
|
| 319 |
on our local Ethernet network, and that they should be routed through the
|
| 320 |
`eth0' interface. If you are using a non-standard netmask, this can be
|
| 321 |
specified as a command line option to the <prgn>route</prgn> command:
|
| 322 |
<example>
|
| 323 |
/sbin/route add -net 192.158.50.0 netmask 255.255.255.192
|
| 324 |
</example>
|
| 325 |
<p>A command like one of the above would be sufficient if our TCP/IP network
|
| 326 |
consisted of just a single network, not connected to anywhere else.
|
| 327 |
However, the strengths of TCP/IP are its <em>internetworking</em>
|
| 328 |
abilities, and normally a IP-based network consists of more than one
|
| 329 |
network. In order to route IP packets from your machines to these other
|
| 330 |
networks, you require to specify <em>gateway</em> hosts (often called
|
| 331 |
<em>routers</em>) which deal with sending information to these other
|
| 332 |
networks. There are in general two possibilities.</p>
|
| 333 |
|
| 334 |
<p>The first possibility is that we want to route IP packets to a specific
|
| 335 |
network, and we know the address of a gateway host or router which deals
|
| 336 |
with information for that network. Suppose, for example, that there is
|
| 337 |
a machine 192.168.50.1 on our network, which is a router for the network
|
| 338 |
172.20.0.0 (a class B network). The following options to the
|
| 339 |
<prgn>route</prgn> command specify this:
|
| 340 |
<example>
|
| 341 |
# route add -net 172.20.0.0 gw 192.168.50.1
|
| 342 |
</example>
|
| 343 |
<p>Since our routing table already contains an entry telling us how to
|
| 344 |
send information to 192.168.50.1 (it's on our local network), any traffic
|
| 345 |
for the remote network 172.20.0.0 is now sent to that machine, which deals
|
| 346 |
with it appropriately.</p>
|
| 347 |
|
| 348 |
<p>The other possibility is that we use a certain gateway as a
|
| 349 |
<em>default route</em> - a route used for all IP packets which don't
|
| 350 |
match other rules in our routing table. If, for example, the machine
|
| 351 |
with IP address 192.168.50.254 is our router to the rest of the world
|
| 352 |
(the Internet, for example), we use the <prgn>route</prgn> command as
|
| 353 |
follows:
|
| 354 |
<example>
|
| 355 |
# /sbin/route add default gw 192.168.23.254
|
| 356 |
</example>
|
| 357 |
<p>At this stage, let's have another look at our routing table:
|
| 358 |
<example>
|
| 359 |
# /sbin/route
|
| 360 |
Kernel IP routing table
|
| 361 |
Destination Gateway Genmask Flags Metric Ref Use Iface
|
| 362 |
127.0.0.0 * 255.0.0.0 U 0 0 2 lo
|
| 363 |
192.168.50.0 * 255.255.255.0 U 0 0 137 eth0
|
| 364 |
172.20.0.0 192.168.50.1 255.255.0.0 UG 1 0 7 eth0
|
| 365 |
default 192.168.50.254 0.0.0.0 UG 1 0 36 eth0
|
| 366 |
</example>
|
| 367 |
<p>Going through the above table one line at a time:
|
| 368 |
<enumlist>
|
| 369 |
<item>We first specify a loopback address for all 127.*.*.* addresses</item>
|
| 370 |
<item>Next, we specify how to reach all machines on our local network,
|
| 371 |
identified as 192.168.50.*</item>
|
| 372 |
<item>Next, we give a route to all machines on the network (172.20.*.*)
|
| 373 |
connected to the machine 192.168.50.1, which is a router (or gateway)
|
| 374 |
for that network</item>
|
| 375 |
<item>Finally, we specify that the machine 192.168.50.254 will deal with
|
| 376 |
all other IP traffic</item>
|
| 377 |
</enumlist>
|
| 378 |
</p>
|
| 379 |
<p>For now, we won't look at what the the various `flags', `metric' and
|
| 380 |
`ref' entries mean.</p>
|
| 381 |
|
| 382 |
<p>Let's have another look at a typical <prgn>/etc/init.d/network</prgn>
|
| 383 |
file, setup by Debian's installation procedure on a typical
|
| 384 |
Ethernet-connected machine:
|
| 385 |
<example>
|
| 386 |
#! /bin/sh
|
| 387 |
ifconfig lo 127.0.0.1
|
| 388 |
route add -net 127.0.0.0
|
| 389 |
IPADDR=192.168.50.23
|
| 390 |
NETMASK=255.255.255.0
|
| 391 |
NETWORK=192.168.50.0
|
| 392 |
BROADCAST=192.168.50.255
|
| 393 |
GATEWAY=192.168.50.254
|
| 394 |
ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
|
| 395 |
route add -net ${NETWORK}
|
| 396 |
[ "${GATEWAY}" ] && route add default gw ${GATEWAY} metric 1
|
| 397 |
</example>
|
| 398 |
<p>The first two lines of this shell script set up the loopback interface,
|
| 399 |
and add an entry to the routing table for it. The variables which follow
|
| 400 |
set up the IP address of our machine, the netmask, the address of our
|
| 401 |
local network, the broadcast address, and the IP address of our default
|
| 402 |
router. Finally, our local Ethernet interface is set up with
|
| 403 |
<prgn>ifconfig</prgn>, and two invocations of the <prgn>route</prgn>
|
| 404 |
command add routing table entries for firstly the local network and
|
| 405 |
secondly our default gateway.</p>
|
| 406 |
|
| 407 |
<p>You may well find that the addresses (of networks and of machines)
|
| 408 |
in the output from the <prgn>route</prgn> command do not appear as
|
| 409 |
IP addresses, but are named. The names of networks can be set up in
|
| 410 |
the <prgn>/etc/networks</prgn> file (which is normally set up by a
|
| 411 |
Debian's network setup routines at installation times), and the names
|
| 412 |
of hosts can come from a variety of machines, including the
|
| 413 |
<prgn>/etc/hosts</prgn> file and the Domain Name Service (DNS).
|
| 414 |
Let's now have a look at what DNS is and what it does.</p>
|
| 415 |
|
| 416 |
</sect>
|
| 417 |
|
| 418 |
<sect>Domain Name Service (DNS)
|
| 419 |
<p>Every computer connected to the Internet, or any network using
|
| 420 |
IP as its network protocol, has an IP address, in order that information
|
| 421 |
be able to be routed correctly to and from it. IP addresses, though,
|
| 422 |
are a bit difficult for humans to remember, and for this reason, each
|
| 423 |
machine is also normally given a name. When you install Debian, this
|
| 424 |
is one of the questions you will be asked - what the name of your
|
| 425 |
computer will be.</p>
|
| 426 |
|
| 427 |
<p>The name of your computer will be stored in a few locations. You can
|
| 428 |
find out the name of your computer by typing the <prgn>hostname</prgn>
|
| 429 |
command, which returns the value in the file <prgn>/etc/hostname</prgn>.
|
| 430 |
If you are connected to the Internet, this name will usually have several
|
| 431 |
parts, separated from each other by dots, for example:
|
| 432 |
<example>
|
| 433 |
debian.anon.com
|
| 434 |
</example>
|
| 435 |
It is only the first part of this which is the name of your own
|
| 436 |
computer - the rest is known as the <em>domain name</em> - this is
|
| 437 |
the <tt>anon.com</tt> part. Since there are likely to be several
|
| 438 |
computers with the same name on the Internet, each one is made unique
|
| 439 |
by putting it in its own domain. Within a domain, normally one person
|
| 440 |
is responsible for giving out computers names, and administering a
|
| 441 |
database which holds all the names and addresses of the computers in
|
| 442 |
that domain. This system is known as DNS, and is like a telephone
|
| 443 |
directory - you can look up a computer by name, and find out its IP
|
| 444 |
address.</p>
|
| 445 |
|
| 446 |
<p>Before DNS, people had to remember IP addresses in order to use
|
| 447 |
the Internet, and names were only known for a small subset of machines -
|
| 448 |
typically the machines in the local network, and maybe one or two machines
|
| 449 |
which were permanently connected to our site. These names were stored in
|
| 450 |
a single file - <prgn>/etc/hosts</prgn> - and you'll normally find that
|
| 451 |
your own machine's name and IP address were added to that file when Debian
|
| 452 |
was installed.</p>
|
| 453 |
|
| 454 |
<p>DNS is a fairly complex system, and we'll look into more detail on it
|
| 455 |
later, along with the software (<prgn>bind</prgn>) which allows you to
|
| 456 |
look after your own DNS domain.</p>
|
| 457 |
|
| 458 |
<p>Here, though, we'll have a look at how DNS works from a <em>client's</em>
|
| 459 |
point of view - ie from the point of view of a machine which only needs to
|
| 460 |
look up machines in the DNS, rather than one which has to provide a DNS
|
| 461 |
service.</p>
|
| 462 |
|
| 463 |
<p>When a Debian machine needs to look up another computer's name in order
|
| 464 |
to find out its IP address, it uses a set of routines in the C library
|
| 465 |
called the <em>resolver</em>. The resolver routines, in turn, consult
|
| 466 |
firstly the file <prgn>/etc/nsswitch.conf</prgn>, which, against an entry
|
| 467 |
for <tt>hosts</tt> will list the places that the resolver should check in
|
| 468 |
order to find out the IP address. There are three possible entries here,
|
| 469 |
and if more than one of them is present, the resolver will check each one
|
| 470 |
in order. These entries are:
|
| 471 |
<taglist>
|
| 472 |
<tag>files
|
| 473 |
<item>Check the file <prgn>/etc/hosts</prgn> for an entry for the particular
|
| 474 |
hostname
|
| 475 |
<tag>nis
|
| 476 |
<item>Check the NIS database (which we will look at later) for the hostname
|
| 477 |
<tag>dns
|
| 478 |
<item>Check the Domain Name Service
|
| 479 |
</taglist>
|
| 480 |
A typical entry in <prgn>/etc/nsswitch</prgn> might be:
|
| 481 |
<example>
|
| 482 |
hosts: files dns
|
| 483 |
</example>
|
| 484 |
This tells the resolver to check firstly the file <prgn>/etc/hosts</prgn>
|
| 485 |
and then query the DNS.</p>
|
| 486 |
|
| 487 |
<p>The DNS is configured by the file <prgn>/etc/resolv.conf</prgn>. This
|
| 488 |
file normally specifies two things - firstly, the domain in which our
|
| 489 |
machine is, and secondly, a number of nameservers to ask for information.
|
| 490 |
An example would be:
|
| 491 |
<example>
|
| 492 |
domain anon.org
|
| 493 |
nameserver 172.19.0.1
|
| 494 |
nameserver 172.19.5.1
|
| 495 |
</example>
|
| 496 |
The first line tells the resolver library that if we ask for a machine
|
| 497 |
and don't specify a domain name, it should have <tt>anon.org</tt> appended
|
| 498 |
to it - ie the resolver, assuming that the machine is in our own domain,
|
| 499 |
should search it. The two lines beginning with <tt>nameserver</tt> specify
|
| 500 |
the IP addresses of machines which we should query using DNS. These should
|
| 501 |
always be IP addresses - not names - for obvious reasons.</p>
|
| 502 |
|
| 503 |
<p>Most networking utilities will automatically look up a machine's IP
|
| 504 |
address if you specify a name, but if you want to query the DNS directly,
|
| 505 |
the <tt>dnsutils</tt> package contains a program called
|
| 506 |
<prgn>nslookup</prgn>. <prgn>nslookup</prgn> can be used either
|
| 507 |
one-off, by giving the name of the machine you are searching for,
|
| 508 |
possibly along with command-line arguments, or interactively, by
|
| 509 |
just typing <prgn>nslookup</prgn> on its own. The interactive mode
|
| 510 |
allows a number of searches to be made, and provides some limited
|
| 511 |
help.</p>
|
| 512 |
|
| 513 |
<p><prgn>nslookup</prgn>, along with other programs to query the DNS,
|
| 514 |
and the software to provide a DNS service, will all be described in
|
| 515 |
more detail later.</p>
|
| 516 |
|
| 517 |
<p>For more information on DNS, please see <ref id="bind">.
|
| 518 |
|
| 519 |
</sect>
|
| 520 |
|
| 521 |
<sect>ICMP and IP Troubleshooting
|
| 522 |
</sect>
|
| 523 |
|
| 524 |
<sect>TCP and UDP
|
| 525 |
</sect>
|
| 526 |
|
| 527 |
<sect>Servers, Daemons and the Superserver
|
| 528 |
</sect>
|
| 529 |
|
| 530 |
|
| 531 |
</chapt>
|
| 532 |
|
| 533 |
<!-- Keep this comment at the end of the file
|
| 534 |
Local variables:
|
| 535 |
mode: sgml
|
| 536 |
sgml-omittag:t
|
| 537 |
sgml-shorttag:t
|
| 538 |
sgml-minimize-attributes:nil
|
| 539 |
sgml-always-quote-attributes:t
|
| 540 |
sgml-indent-step:2
|
| 541 |
sgml-indent-data:t
|
| 542 |
sgml-parent-document:"network-administrator.sgml chapt sect"
|
| 543 |
sgml-exposed-tags:nil
|
| 544 |
sgml-local-catalogs:"/usr/lib/sgml/catalog"
|
| 545 |
sgml-local-ecat-files:nil
|
| 546 |
End:
|
| 547 |
-->
|
| 548 |
|