summaryrefslogtreecommitdiffstats
path: root/chapter_13.xml
blob: 23eae86cc9ad2e59d462996b5ab34353eed4935a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
<?xml version="1.0"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  "/usr/share/xml/docbook/xml-dtd-4.5/docbookx.dtd">

<chapter>
<title>Networking</title>

<section>
<title><application>netconfig</application></title>

<para>
Computers aren't very interesting on their own. Sure, you can install
games on them, but that just turns them into glorified entertainment
consoles. Today, computers need to be able to talk to one another; they
need to be networked. Whether you're installing a business network with
hundreds or thousands of computers or just setting up a single PC for
Internet access, Slackware is simple and easy. This chapter should
teach you how to setup typical wired networks. Common wireless setup will
be thoroughly discussed in the next section, but much of what you read
here will be applicable there as well.
</para>

<para>
There are many different ways to configure your computer to connect to
a network or the Internet, but they fall into two main categories:
static and dymanic. Static addresses are solid; they are set with the
understanding that they will not be changed, at least not anytime soon.
Dynamic addresses are fluid; the assumption is that the address will
change at some time in the future. Typically any sort of network server
requires a static address simply so other machines will know where to
contact it when they need services. Dynamic addresses tend to be used
for workstations, Internet clients, and any machine that doesn't
require a static address for any reason. Dynamic addresses are more
flexible, but present complications of their own.
</para>

<para>
There are many different kinds of network protocols that you might
encounter, but most people will only ever need to deal with Internet
Protocol (IP). For that reason, we'll focus exclusively on IP in this
book.
</para>

</section>

<section>
<title>Manual Configuration</title>

<para>
Ok, so you've installed Slackware, you've setup a desktop, but you
can't get it to connect to the Internet or your business's LAN (local
area network), what do you do? Fortunately, the answer to that question
is simple. Slackware includes a number of tools to configure your
network connection. The first we will look at today is the very
powerful <application>ifconfig</application>(8).
<application>ifconfig</application> is used to setup or modify the
configuration of a Network Interface Card (NIC or Ethernet Card), the
most common hardware for connecting to networks today.
<application>ifconfig</application> is an incredibly powerful tool
capable of doing much more than setting IP addresses. For a complete
introduction, you should read its man page. For now, we're just going
to use it to display and change the network addresses of some ethernet
controllers.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>ifconfig</userinput>
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:699 errors:0 dropped:0 overruns:0 frame:0
          TX packets:699 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:39518 (38.5 KiB)  TX bytes:39518 (38.5 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:1c:b3:ba:ad:4c  
          inet addr:192.168.1.198  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:b3ff:feba:ad4c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1630677 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1183224 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1627370207 (1.5 GiB)  TX bytes:163308463 (155.7 MiB)

wmaster0  Link encap:UNSPEC  HWaddr 00-1C-B3-BA-AD-4C-00-00-00-00-00-00-00-00-00-00  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
</screen>


<para>
As you can clearly see here, when run without any arguments,
<application>ifconfig</application> will display all the information it
has on all the ethernet cards (and wireless ethernet cards) present on
your system. The above represents a typical wireless connection from my
laptop, so don't be afraid if what you see on your system doesn't
match.  If you don't see any ethX or wlanX interfaces though, the
interface may be down. To show all currently present NICs whether they are
"up" or "down", simply pass the <arg>-a</arg> argument.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>ifconfig -a</userinput>
eth0      Link encap:Ethernet  HWaddr 00:19:e3:45:90:44  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:122780 errors:0 dropped:0 overruns:0 frame:0
          TX packets:124347 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:60495452 (57.6 MiB)  TX bytes:17185220 (16.3 MiB)
          Interrupt:16 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:699 errors:0 dropped:0 overruns:0 frame:0
          TX packets:699 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:39518 (38.5 KiB)  TX bytes:39518 (38.5 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:1c:b3:ba:ad:4c  
          inet addr:192.168.1.198  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:b3ff:feba:ad4c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1630677 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1183224 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1627370207 (1.5 GiB)  TX bytes:163308463 (155.7 MiB)

wmaster0  Link encap:UNSPEC  HWaddr 00-1C-B3-BA-AD-4C-00-00-00-00-00-00-00-00-00-00  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
</screen>

<para>Notice that the eth0 interface is now listed among the returns.
<application>ifconfig</application> can also change the current
settings on a NIC. Typically, you would need to change the IP address
and subnet mask, but you can change virtually any parameters.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>ifconfig eth0 192.168.1.1 netmask 255.255.255.0</userinput>
<prompt>darkstar:~# </prompt><userinput>ifconfig eth0</userinput>
eth0      Link encap:Ethernet  HWaddr 00:19:e3:45:90:44  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:122780 errors:0 dropped:0 overruns:0 frame:0
          TX packets:124347 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:60495452 (57.6 MiB)  TX bytes:17185220 (16.3 MiB)
          Interrupt:16 
</screen>

<para>
If you look carefully, you'll notice that the interface now has the
192.168.1.1 IP address and a 255.255.255.0 subnet mask. We've now setup
the basics for connecting to our network, but we still need to setup a
default gateway and our DNS servers. In order to do that, we'll need to
look at a few more tools.
</para>

<para>
Next on our stop through networking land is the equally powerful
<application>route</application>(8). This tool is responsible for
modifying the Linux kernel's routing table which affects all data
transmission on a network. Routing tables can become immensely complex
or they can be straight-forward and simple. Most users will only ever
need to setup a default gateway, so we'll show you how to do that here.
If for some reason you need a more complex routing table, you would be
well advised to read the entire man page for
<application>route</application> as well as consulting other sources.
For now, let's take a look at our routing table immediately after
setting up eth0.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>route</userinput>
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
</screen>

<para>
I won't explain everything here, but the general information should be
easy to pick up if you're familiar with networking at all. The
Destination and Genmask fields specify a range of IP addresses to
match. If a Gateway is defined, information in the form of packets will
be sent to that host for forwarding. We also specify an interface in
the final field that the information should traverse. Right now, we can
only communicate with computers with addresses between 192.168.1.0 and
192.168.1.255 and ourselves through the loopback interface, a type of
virtual NIC that is used for routing information from this computer to
itself.  In order to reach the rest of the world, we'll need to
setup a default gateway.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>route add default gw 192.168.1.254</userinput>
<prompt>darkstar:~# </prompt><userinput>route</userinput>
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
default         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
</screen>

<para>
You should immediately notice the addition of a default route. This
specifies what router should be used to reach any addresses that aren't
specified elsewhere in our routing table. Now, when we try to connect
to say, 64.57.102.34, the information will be sent to 192.168.1.254
which is responsible for delivering the data for us. Unfortunately,
we're still not quite through. We need some way of converting domain
names like slackware.com into IP addresses that the computer can use.
For that, we need to make use of a DNS server.
</para>

<para>
Fortunately, setting up your computer to use an external (or even an
internal) DNS server is very easy. You'll need to use your favorite
text editor and open the <filename>/etc/resolv.conf</filename> file.
Don't ask me what happened to the <keycap>e</keycap>. On my computer,
<filename>resolv.conf</filename> looks like this.
</para>

<screen>
# /etc/resolv.conf
search lizella.net
nameserver 192.168.1.254
</screen>

<para>
Most users won't need the "search" line. This is used to map hostnames
to domain names. Basically, if I attempt to connect to "barnowl", the
computer knows to look for "barnowl.lizella.net" thanks to this search
line. We're mainly interested in the "nameserver" line. This tells
Slackware what domain name servers (DNS) to connect to. Generally
speaking, these should always be specified by IP address. If you know
what DNS servers you should use, you can just add them one at a time to
individual nameserver lines. In fact, I don't know of any practical
limit to the number of nameservers that can be specified in
<filename>resolv.conf</filename>, so add as many as you like. Once this
is done, you should be able to communicate with other hosts via their
fully qualified domain name.
</para>

<para>
But Alan! That's a lot of hard work! I don't want to do this time and
again for dozens or even hundreds of machines. You're absolutely right,
and that's why smarter people than you and me created DHCP.  DHCP
stands for Dynamic Host Control Protocol and is a method for
automatically configuring computers with unique IP addresses, netmasks,
gateways, and DNS servers. Most of the time, you'll want to use DHCP.
The majority of wireless routers, DSL or cable modems, even firewalls
all have DHCP servers to can make your life much easier. Slackware
includes two main tools for connecting to an exising DHCP server and
can even act as a DHCP server for other computers. For now though,
we're just going to look at DHCP clients.
</para>

<para>
First on our list is <application>dhcpcd</application>(8), part of the
ISC DHCP utilities. Assuming your computer is physically connected to
your network, and that you have an operating DHCP server on that
network, you can configure your NIC in one shot.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>dhcpcd eth0</userinput>
</screen>

<para>
If everything went according to plan, your NIC should be properly
configured, and you should be able to communicate with other computers
on your network, and with the Internet at large. If for some reason,
<application>dhcpcd</application> fails, you may want to try
<application>dhclient</application>(8).
<application>dhclient</application> is an alternative to
<application>dhcpcd</application> and works in basically the same way.
</para>

<screen><prompt>darkstar:~# </prompt><userinput>dhclient eth0</userinput>
Listening on LPF/eth0/00:1c:b3:ba:ad:4c
Sending on   LPF/eth0/00:1c:b3:ba:ad:4c
Sending on   Socket/fallback
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.254
bound to 192.168.1.198 -- renewal in 8547 seconds.
</screen>

<para>
So why does Slackware include two DHCP clients? Sometimes a particular
DHCP server may be broken and not respond well to either 
<application>dhcpcd</application> or
<application>dhclient</application>. In those cases, you can fall back
to the other DHCP client in hopes of getting a valid response from the
server. Traditionally, Slackware uses
<application>dhcpcd</application>, and this works in the vast majority
of cases, but it may become necessary at some point for you to use
<application>dhclient</application> instead. Both are excellent DHCP
clients, so use whichever you prefer.
</para>

</section>

<section>
<title>Automatic Configuration with rc.inet1.conf</title>

<para>
Manually configuring interfaces is an important skill to have, but it
can become tedious.  No one wants to manually setup their Internet
connection every time the system boots.  More importantly, you may not
always have physical access to the machine when it boots.  Slackware
makes it easy to automatically configure ethernet (and wireless) cards
at system startup with <filename>/etc/rc.d/rc.inet1.conf</filename>.
For now, we're going to focus on traditional wired ethernet networking;
the next chapter will discuss various wireless options.
</para>

<para>
<filename>rc.inet1.conf</filename> is an incredibly powerful
configuration file, capable of configuring most of your network cards
automatically when Slackware is started. The file is filled with useful
comments, but there is also a man page that more thoroughly discusses
its use.  To begin, we're going to look at some of the options used on
one of my personal machines.
</para>

<screen>
# Config information for eth0:
IPADDR[0]="192.168.1.250"
NETMASK[0]="255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""
# Some lines ommitted.
GATEWAY="192.168.1.254"
</screen>

<para>
This represents most of the information necessary to configure a static
IP address on a single ethernet controller.
<application>netconfig</application> will usually fill in these values 
for a single ethernet device for you.  If you have multiple network
cards in your machine and need all of them activated automatically at
boot time, then you'll need to edit or add additional entries into this
file in the same manner as above.  First, let me go over some of the
basics.
</para>

<para>
As you may have already guessed, IPADDR[n] is the Internet Protocol
Address for the "n" network interface card.  Typically, "n" corrosponds
to eth0, eth1, and so on, but this isn't always the case.  You can
specify these values to pertain to a different network controller with
the INFAME[n] variable, but we will reserve that for the next chapter
on wireless networking, as it more commonly pertains to wireless
network controllers.  Likewise, NETMASK[n] is the subnet mask to use
for the network controller.  If these lines are left empty, then static
IP addresses will not be automatically assigned to this network
controller.  The USE_DHCP[n] variable tells Slackware to (naturally)
use DHCP to configure the interface.  DHCP_HOSTNAME[n] is rarely used,
but some DHCP servers may require it.  In that case, it must be set to
a valid hostname. Finally, we come to the GATEWAY variable.  It is
actually set lower in the file than it appears in my example, and it
controls the default gateway to use. You may be wondering why there is
no GATEWAY[n] variable. The answer to that lies in how Internet
Protocol works. I won't go into an indepth discussion on that subject,
but suffice it to say that there is only ever one default route that a
computer can use no matter how many interfaces are attached to it.
</para>

<para>
If you need to use static IP addressing, you will have to obtain a
unique static IP address and the subnet mask for the interface, as well
as the default gateway address, and enter those here. There is no place
to enter DNS information in <filename>rc.inet1.conf</filename>, so DNS
servers will have to be manually placed into
<filename>resolv.conf</filename> as we discussed above. Of course, if
you use <application>netconfig</application>, this will be handled for
you by that program.  Now let's take a look at another interface on my
computer.
</para>

<screen>
# Config information for eth1:
IPADDR[1]=""
NETMASK[1]=""
USE_DHCP[1]="yes"
DHCP_HOSTNAME[1]=""
</screen>

<para>
Here I am telling Slackware to configure eth1 using DHCP. I do not need
to set the IPADDR[1] or NETMASK[1] variables when using DHCP (in fact,
if they are set, they will be ignored). Slackware will happily contact
a DHCP server as soon as the machine begins to boot.
</para>

</section>

</chapter>