| 108 |
<chapt> |
<chapt> |
| 109 |
|
|
| 110 |
<heading>TCP/IP</heading> |
<heading>TCP/IP</heading> |
| 111 |
|
<p> |
| 112 |
|
author = Duncan C Thomsonr |
| 113 |
|
<email>duncan@sciuro.demon.co.uk</email></p> |
| 114 |
<p> |
<p> |
| 115 |
author = ? |
topics = IP protocol, TCP protocol, IP addresses, IP interfaces, Routing |
| 116 |
</p> |
</p> |
| 117 |
|
|
|
<p> |
|
|
topics = ? |
|
|
</p> |
|
| 118 |
|
|
| 119 |
|
<sect>Intro |
| 120 |
|
<p>TCP/IP, as the name suggests, is a pair of protocols, and what most |
| 121 |
|
of the Internet is built on. Although physically the Internet is |
| 122 |
|
made up of a wide range of networking technologies, from slow modem |
| 123 |
|
links through Ethernet, to high-speed ATM-based switched networks, |
| 124 |
|
and a wide range of different applications run over it - the WWW and |
| 125 |
|
e-mail to name only two, the protocols which tie everything together |
| 126 |
|
are Internet Protocol (IP), and, perhaps almost as great an extent, |
| 127 |
|
Transmission Control Protocol. Another protocol, UDP, is used |
| 128 |
|
in place of TCP for some applications, especially in LAN |
| 129 |
|
environments, but on the Internet the TCP/IP partnership rules.</p> |
| 130 |
|
|
| 131 |
|
<p>diagram: various physical networks, IP, TCP and UDP, apps</p> |
| 132 |
|
|
| 133 |
|
<p>This chapter describes firstly the basics of IP networking, and |
| 134 |
|
later describes some of the more advanced features of TCP/IP available |
| 135 |
|
to the Debian user.</p> |
| 136 |
|
</sect> |
| 137 |
|
|
| 138 |
|
<sect>IP Addresses |
| 139 |
|
|
| 140 |
|
<p>Every computer connected directly to the Internet (or to any IP-based |
| 141 |
|
network) is identified by an IP address. IP addresses are four bytes |
| 142 |
|
long, and are usually written as four decimal numbers separated by dots, |
| 143 |
|
as in the examples below. |
| 144 |
|
<list> |
| 145 |
|
<item>10.34.92.111</item> |
| 146 |
|
<item>127.0.0.1</item> |
| 147 |
|
<item>172.19.220.2</item> |
| 148 |
|
<item>192.168.50.109</item> |
| 149 |
|
</list> |
| 150 |
|
<p>IP addresses typically identify two things. Firstly, they identify the |
| 151 |
|
network on which a particular computer is located. Secondly, they |
| 152 |
|
identify a particular computer on that network. Both these pieces of |
| 153 |
|
information are present in an IP address, and they can be called the |
| 154 |
|
<em>network part</em> and the <em>host part</em>. |
| 155 |
|
Two special values for the host part |
| 156 |
|
should be mentioned here - if the host part is all zeros, the |
| 157 |
|
address refers to a network (ie it is a <em>network address</em> as |
| 158 |
|
opposed to a <em>host address</em>). If, alternatively, the host part |
| 159 |
|
is all ones, the address refers to all hosts on the network (ie it is a |
| 160 |
|
<em>broadcast</em> address).</p> |
| 161 |
|
|
| 162 |
|
<p>In order to identify which part of the IP address is the host part, |
| 163 |
|
and which part is the network part, there are two methods we can use. The |
| 164 |
|
first (and original) way is the easier by far to understand, so let's start |
| 165 |
|
by having a look at how it works. IP addresses are split into a number of |
| 166 |
|
<em>classes</em>, and it is this class which tells us how to split an IP |
| 167 |
|
address into its network and host parts. |
| 168 |
|
<taglist> |
| 169 |
|
<tag>Class A</tag> |
| 170 |
|
<item>A class A IP address has as its first byte a number between 1 and |
| 171 |
|
126. The first byte of a class A IP address identifies the network, and |
| 172 |
|
the remaining three bytes identify the host.</item> |
| 173 |
|
<tag>Class B</tag> |
| 174 |
|
<item>A class B IP address has as its first byte a number between 128 and |
| 175 |
|
191. Its first two bytes are the network identifier, and the remaining |
| 176 |
|
two bytes are the host identifier on that network.</item> |
| 177 |
|
<tag>Class C</tag> |
| 178 |
|
<item>A class C IP address has as its first byte a number between 192 and |
| 179 |
|
223. Its first three bytes identify the network, and the remaining byte |
| 180 |
|
identifies an individual host on that network.</item> |
| 181 |
|
</taglist></p> |
| 182 |
|
|
| 183 |
|
<p>From the above list you might notice that IP addresses beginning with |
| 184 |
|
bytes from 224 and upwards are missing. These belong to other classes of |
| 185 |
|
IP address, not used for a normal IP host, and are beyond the discussion |
| 186 |
|
in this section.</p> |
| 187 |
|
|
| 188 |
|
<p>You might also notice that IP addresses beginning with 127 are missing. |
| 189 |
|
IP addresses beginning with 127 are known as <em>loopback</em> addresses, |
| 190 |
|
and can be used for testing TCP/IP without actually having a network |
| 191 |
|
connection.</p> |
| 192 |
|
|
| 193 |
|
<p>This is all very well, but what if we have been assigned a single |
| 194 |
|
class C address range, but want to split it among several networks? This |
| 195 |
|
is where the second method of specifying the network and host parts can be |
| 196 |
|
used. This method specifies, along with an IP address, a <em>netmask</em>, |
| 197 |
|
which has its bits set to one in the network part, and set to zero in the |
| 198 |
|
host part. So, for example, the default netmask for the various classes |
| 199 |
|
of network as as below: |
| 200 |
|
<taglist> |
| 201 |
|
<tag>Class A</tag> |
| 202 |
|
<item>255.0.0.0</item> |
| 203 |
|
<tag>Class B</tag> |
| 204 |
|
<item>255.255.0.0</item> |
| 205 |
|
<tag>Class C</tag> |
| 206 |
|
<item>255.255.255.0</item> |
| 207 |
|
</taglist></p> |
| 208 |
|
|
| 209 |
|
<p>These don't give us any new information beyond what the original address |
| 210 |
|
classes told us. The power in using netmasks, though, is that we can |
| 211 |
|
choose arbitrary splits between the network and host parts - for example, |
| 212 |
|
a netmask of 255.255.255.192 would allow us to split a class C network |
| 213 |
|
into four parts, each with 62 host addresses. Confused? Let's look at |
| 214 |
|
that example in more detail.</p> |
| 215 |
|
|
| 216 |
|
<p>Let's suppose we've been allocated a class C network with IP addresses |
| 217 |
|
beginning with 192.168.50. If we convert the netmask 255.255.255.192 into |
| 218 |
|
binary, we can see that in the last byte, the first two bits are one (that |
| 219 |
|
is, they are included in the network part of the address) and the last six |
| 220 |
|
bits are zeros (that is, they form the host part). So, by using the IP |
| 221 |
|
addresses we have been given, along with this netmask, we have split our |
| 222 |
|
network into four, with <em>network addresses</em> given by setting these |
| 223 |
|
two bits to their four possible combinations (00, 01, 10, 11) while |
| 224 |
|
keeping the host part set to zeros (to identify the network): |
| 225 |
|
<list> |
| 226 |
|
<item>192.168.50.0</item> |
| 227 |
|
<item>192.168.50.64</item> |
| 228 |
|
<item>192.168.50.128</item> |
| 229 |
|
<item>192.168.50.192</item> |
| 230 |
|
</list></p> |
| 231 |
|
|
| 232 |
|
<p>Now we know where our four network addresses come from. What about our |
| 233 |
|
host addresses? They come from setting the host part in each <em>subnet</em> |
| 234 |
|
to all values from 000001 to 111110 (remember - all ones is a broadcast |
| 235 |
|
address). That gives us a total of 62 hosts in each network, with addresses: |
| 236 |
|
<list> |
| 237 |
|
<item>192.168.50.1 - 192.168.50.62</item> |
| 238 |
|
<item>192.168.50.65 - 192.168.50.126</item> |
| 239 |
|
<item>192.168.50.129 - 192.168.50.190</item> |
| 240 |
|
<item>192.168.50.193 - 192.168.50.254</item> |
| 241 |
|
</list></p> |
| 242 |
|
|
| 243 |
|
<p>In Linux, if we don't mention what netmask we are using, it's usually |
| 244 |
|
assumed by the software that we want to use the default netmask for that |
| 245 |
|
particular class of IP addresses. You should only need to specify a netmask |
| 246 |
|
if you are using one which is not the standard scheme for a particular class |
| 247 |
|
of IP addresses. It never does any harm to specify it though.</p> |
| 248 |
|
|
| 249 |
|
<p>Each IP address should be <em>unique</em> on the Internet, or whichever |
| 250 |
|
IP network you are connected to. This means that your cannot assign IP |
| 251 |
|
addresses at random to your machines, since most IP addresses are already |
| 252 |
|
in use on the Internet. In order to get a legal set of IP addresses for |
| 253 |
|
your machines, you will normally go through an Internet Service Provider |
| 254 |
|
(ISP). If you have not been assigned such a range of addresses, you |
| 255 |
|
should use one of the range of <em>private</em> IP addresses, set aside for |
| 256 |
|
internet or testing use. Be aware that you will not be able to connect to |
| 257 |
|
the Internet directly from such a network; you will need to use some form |
| 258 |
|
of Network Address Translation (NAT) to do this. The ranges of IP addresses |
| 259 |
|
set aside for private use are: |
| 260 |
|
<list> |
| 261 |
|
<item>10.0.0.0: a single class A network</item> |
| 262 |
|
<item>172.16.0.0 - 172.31.0.0: 16 class B networks</item> |
| 263 |
|
<item>192.168.0.0 - 192.168.255.0: 256 class C networks</item> |
| 264 |
|
</list></p> |
| 265 |
|
|
| 266 |
|
</sect> |
| 267 |
|
|
| 268 |
|
<sect>IP Interface Configuration |
| 269 |
|
|
| 270 |
|
<p>Once we know what IP address we wish to use for our machine, we will |
| 271 |
|
have to bring up one of our network interfaces, and assign that IP address |
| 272 |
|
(possibly along with a netmask) to it. On most Debian systems this is done |
| 273 |
|
when installing the system, and you are seldom likely to need to change |
| 274 |
|
it on a simple system.</p> |
| 275 |
|
|
| 276 |
|
<p>The <prgn>ifconfig</prgn> command is used to configure interfaces in |
| 277 |
|
order to use IP with them. There are a number of different network |
| 278 |
|
interfaces available with the Linux kernel, some of which are summarised |
| 279 |
|
below: |
| 280 |
|
<taglist> |
| 281 |
|
<tag>Loopback</tag> |
| 282 |
|
<item>The loopback interface (<tt>lo</tt>), usually configured as IP |
| 283 |
|
address 127.0.0.1</item> |
| 284 |
|
<tag>Ethernet</tag> |
| 285 |
|
<item>Ethernet interfaces (with names like <tt>eth0</tt>, <tt>eth1</tt>, |
| 286 |
|
<tt>eth2</tt>) are used to access Ethernet cards</item> |
| 287 |
|
<tag>PPP</tag> |
| 288 |
|
<item>PPP stands for Point-to-Point Protocol, and is used to run a variety |
| 289 |
|
of networking protocols, including IP, over any kind of serial lines |
| 290 |
|
(null modem, modem, ISDN). They have names like <tt>ppp0</tt>, |
| 291 |
|
<tt>ppp1</tt></item> |
| 292 |
|
<tag>Token Ring</tag> |
| 293 |
|
<item>Token Ring devices are accessed with device names like <tt>tr0</tt>, |
| 294 |
|
<tt>tr1</tt></item> |
| 295 |
|
<tag>Dummy</tag> |
| 296 |
|
<item>The dummy network drivers are used in systems who have an interface |
| 297 |
|
which is not always used, in order to provide a permanent IP interface |
| 298 |
|
for the relevant address. The device names are <tt>dummy</tt>, or |
| 299 |
|
<tt>dummy0</tt>, <tt>dummy1</tt>, and so on</item> |
| 300 |
|
</taglist> |
| 301 |
|
There are a wide range of other network devices available, including |
| 302 |
|
SLIP, PLIP (serial and parallel line IP), `shaper' devices for controlling |
| 303 |
|
the traffic on certain interfaces, the ability to have several IP addresses |
| 304 |
|
on a single device, as well as frame relay, AX.25, X.25, ARCnet, LocalTalk |
| 305 |
|
and more. Here, though, we'll concentrate on one of the most common - the |
| 306 |
|
Ethernet interface.</p> |
| 307 |
|
|
| 308 |
|
<p>In many cases, if you wish your kernel to automatically load modules |
| 309 |
|
for certain device drviers, you may require to make changes to your |
| 310 |
|
<prgn>/etc/conf.modules</prgn> or <prgn>/etc/modules</prgn> file. For |
| 311 |
|
example, to automatically load the NE2000 driver, you could have the |
| 312 |
|
line: |
| 313 |
|
<example> |
| 314 |
|
alias eth0 ne |
| 315 |
|
</example> |
| 316 |
|
in your <prgn>/etc/conf.modules</prgn> file.</p> |
| 317 |
|
|
| 318 |
|
<p>The simplest way to call <prgn>ifconfig</prgn> is to simply type its |
| 319 |
|
name: |
| 320 |
|
<example> |
| 321 |
|
# /sbin/ifconfig |
| 322 |
|
lo Link encap:Local Loopback |
| 323 |
|
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0 |
| 324 |
|
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1 |
| 325 |
|
RX packets:18584 errors:0 dropped:0 overruns:0 frame:0 |
| 326 |
|
TX packets:18584 errors:0 dropped:0 overruns:0 carrier:0 |
| 327 |
|
Collisions:0 |
| 328 |
|
</example> |
| 329 |
|
which simply returns information about the interfaces currently |
| 330 |
|
configured. If we wish now to bring up an Ethernet interface with the |
| 331 |
|
address 192.168.50.23, we'd specify the interface name and the IP address |
| 332 |
|
on <prgn>ifconfig</prgn>'s command line: |
| 333 |
|
<example> |
| 334 |
|
# /sbin/ifconfig eth0 192.168.50.23 |
| 335 |
|
# /sbin/ifconfig |
| 336 |
|
lo Link encap:Local Loopback |
| 337 |
|
inet addr:127.0.0.1 Bcast:127.255.255.255 Mask:255.0.0.0 |
| 338 |
|
UP BROADCAST LOOPBACK RUNNING MTU:3584 Metric:1 |
| 339 |
|
RX packets:18584 errors:0 dropped:0 overruns:0 frame:0 |
| 340 |
|
TX packets:18584 errors:0 dropped:0 overruns:0 carrier:0 |
| 341 |
|
Collisions:0 |
| 342 |
|
|
| 343 |
|
eth0 Link encap:Ethernet HWaddr 00:00:E8:C5:64:2A |
| 344 |
|
inet addr:192.168.50.23 Bcast:192.168.50.255 Mask:255.255.255.0 |
| 345 |
|
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 |
| 346 |
|
RX packets:55 errors:0 dropped:0 overruns:0 frame:0 |
| 347 |
|
TX packets:5 errors:0 dropped:0 overruns:0 carrier:0 |
| 348 |
|
Collisions:7 |
| 349 |
|
Interrupt:10 Base address:0x300 |
| 350 |
|
</example> |
| 351 |
|
As can be seen from the example, the <prgn>ifconfig</prgn> now gives |
| 352 |
|
information about the new interface, including the netmask, network |
| 353 |
|
statistics, and information about the network driver itself. The |
| 354 |
|
<prgn>ifconfig</prgn> also allows the specification of a netmask when |
| 355 |
|
the interface is configured, for example: |
| 356 |
|
<example> |
| 357 |
|
# /sbin/ifconfig eth0 192.168.50.23 netmask 255.255.255.192 |
| 358 |
|
</example> |
| 359 |
|
Finally, to bring down an interface, use the following invocation of |
| 360 |
|
<prgn>ifconfig</prgn>: |
| 361 |
|
<example> |
| 362 |
|
# /sbin/ifconfig eth0 down |
| 363 |
|
</example> |
| 364 |
|
Full information on the options available to <prgn>ifconfig</prgn> are |
| 365 |
|
available in the manual page - <manref name="ifconfig" section="8">.</p> |
| 366 |
|
|
| 367 |
|
<p>If you set up the IP addressing on your machine when you installed |
| 368 |
|
Debian GNU/Linux, you should find that the <prgn>ifconfig</prgn> command |
| 369 |
|
is run automatically on bootup. This is done from the file |
| 370 |
|
<prgn>/etc/init.d/network</prgn>. Looking at this file should reveal a |
| 371 |
|
number of lines similar to the following: |
| 372 |
|
<example> |
| 373 |
|
IPADDR=192.168.50.23 |
| 374 |
|
NETMASK=255.255.255.0 |
| 375 |
|
BROADCAST=192.168.50.255 |
| 376 |
|
ifconfig eth0 ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST} |
| 377 |
|
</example> |
| 378 |
|
This is where the setting up of the Ethernet interface takes place. Above |
| 379 |
|
these lines, you should see a line setting up the loopback interface, and |
| 380 |
|
you should see a number of lines which appear to run a command called |
| 381 |
|
<prgn>route</prgn>. This program, and its function, is the subject of |
| 382 |
|
the next section.</p> |
| 383 |
|
</sect> |
| 384 |
|
|
| 385 |
|
<sect>Basic IP Routing |
| 386 |
|
<p> |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
</sect> |
| 390 |
</chapt> |
</chapt> |
| 391 |
|
|
| 392 |
<chapt> |
<chapt> |