/[doc]/head/en_US.ISO8859-1/books/handbook/advanced-networking/chapter.xml
ViewVC logotype

Contents of /head/en_US.ISO8859-1/books/handbook/advanced-networking/chapter.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 49799 - (show annotations) (download) (as text)
Fri Jan 6 20:02:33 2017 UTC (7 years, 5 months ago) by sevan
File MIME type: text/sgml
File size: 211763 byte(s)
Specify the correct filename for the snmpd configuration file.
Closes #4

Submitted by:	@erwinlem on Github
Approved by:	bcr (mentor)
Differential Revision:	https://reviews.freebsd.org/D9068

1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!--
3 The FreeBSD Documentation Project
4
5 $FreeBSD$
6 -->
7 <chapter xmlns="http://docbook.org/ns/docbook"
8 xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0"
9 xml:id="advanced-networking">
10 <title>Advanced Networking</title>
11
12 <sect1 xml:id="advanced-networking-synopsis">
13 <title>Synopsis</title>
14
15 <para>This chapter covers a number of advanced networking
16 topics.</para>
17
18 <para>After reading this chapter, you will know:</para>
19
20 <itemizedlist>
21 <listitem>
22 <para>The basics of gateways and routes.</para>
23 </listitem>
24
25 <listitem>
26 <para>How to set up USB tethering.</para>
27 </listitem>
28
29 <listitem>
30 <para>How to set up &ieee; 802.11 and &bluetooth;
31 devices.</para>
32 </listitem>
33
34 <listitem>
35 <para>How to make &os; act as a bridge.</para>
36 </listitem>
37
38 <listitem>
39 <para>How to set up network <acronym>PXE</acronym>
40 booting.</para>
41 </listitem>
42
43 <listitem>
44 <para>How to set up <acronym>IPv6</acronym> on a &os;
45 machine.</para>
46 </listitem>
47
48 <listitem>
49 <para>How to enable and utilize the features of the Common
50 Address Redundancy Protocol (<acronym>CARP</acronym>) in
51 &os;.</para>
52 </listitem>
53
54 <listitem>
55 <para>How to configure multiple <acronym>VLANs</acronym> on
56 &os;.</para>
57 </listitem>
58 </itemizedlist>
59
60 <para>Before reading this chapter, you should:</para>
61
62 <itemizedlist>
63 <listitem>
64 <para>Understand the basics of the
65 <filename>/etc/rc</filename> scripts.</para>
66 </listitem>
67
68 <listitem>
69 <para>Be familiar with basic network terminology.</para>
70 </listitem>
71
72 <listitem>
73 <para>Know how to configure and install a new &os; kernel
74 (<xref linkend="kernelconfig"/>).</para>
75 </listitem>
76
77 <listitem>
78 <para>Know how to install additional third-party software
79 (<xref linkend="ports"/>).</para>
80 </listitem>
81
82 </itemizedlist>
83 </sect1>
84
85 <sect1 xml:id="network-routing">
86 <info>
87 <title>Gateways and Routes</title>
88
89 <authorgroup>
90 <author>
91 <personname>
92 <firstname>Coranth</firstname>
93 <surname>Gryphon</surname>
94 </personname>
95 <contrib>Contributed by </contrib>
96 </author>
97 </authorgroup>
98 </info>
99
100 <indexterm>
101 <primary>routing</primary>
102 </indexterm>
103 <indexterm>
104 <primary>gateway</primary>
105 </indexterm>
106 <indexterm>
107 <primary>subnet</primary>
108 </indexterm>
109
110 <para><firstterm>Routing</firstterm> is the mechanism that allows
111 a system to find the network path to another system. A
112 <firstterm>route</firstterm> is a defined pair of addresses
113 which represent the <quote>destination</quote> and a
114 <quote>gateway</quote>. The route indicates that when trying
115 to get to the specified destination, send the packets through
116 the specified gateway. There are three types of destinations:
117 individual hosts, subnets, and <quote>default</quote>. The
118 <quote>default route</quote> is used if no other routes apply.
119 There are also three types of gateways: individual hosts,
120 interfaces, also called links, and Ethernet hardware
121 (<acronym>MAC</acronym>) addresses. Known routes are stored in
122 a routing table.</para>
123
124 <para>This section provides an overview of routing basics. It
125 then demonstrates how to configure a &os; system as a router and
126 offers some troubleshooting tips.</para>
127
128 <sect2 xml:id="network-routing-default">
129 <title>Routing Basics</title>
130
131 <para>To view the routing table of a &os; system, use
132 &man.netstat.1;:</para>
133
134 <screen>&prompt.user; <userinput>netstat -r</userinput>
135 Routing tables
136
137 Internet:
138 Destination Gateway Flags Refs Use Netif Expire
139 default outside-gw UGS 37 418 em0
140 localhost localhost UH 0 181 lo0
141 test0 0:e0:b5:36:cf:4f UHLW 5 63288 re0 77
142 10.20.30.255 link#1 UHLW 1 2421
143 example.com link#1 UC 0 0
144 host1 0:e0:a8:37:8:1e UHLW 3 4601 lo0
145 host2 0:e0:a8:37:8:1e UHLW 0 5 lo0 =&gt;
146 host2.example.com link#1 UC 0 0
147 224 link#1 UC 0 0</screen>
148
149 <para>The entries in this example are as follows:</para>
150
151 <variablelist>
152 <varlistentry>
153 <term>default</term>
154 <listitem>
155 <para>The first route in this table specifies the
156 <literal>default</literal> route. When the local system
157 needs to make a connection to a remote host, it checks
158 the routing table to determine if a known path exists.
159 If the remote host matches an entry in the table, the
160 system checks to see if it can connect using the
161 interface specified in that entry.</para>
162
163 <para>If the destination does not match an entry, or if
164 all known paths fail, the system uses the entry for the
165 default route. For hosts on a local area network, the
166 <literal>Gateway</literal> field in the default route is
167 set to the system which has a direct connection to the
168 Internet. When reading this entry, verify that the
169 <literal>Flags</literal> column indicates that the
170 gateway is usable (<literal>UG</literal>).</para>
171
172 <para>The default route for a machine which itself is
173 functioning as the gateway to the outside world will be
174 the gateway machine at the Internet Service Provider
175 (<acronym>ISP</acronym>).</para>
176 </listitem>
177 </varlistentry>
178
179 <varlistentry>
180 <term>localhost</term>
181 <listitem>
182 <para>The second route is the <literal>localhost</literal>
183 route. The interface specified in the
184 <literal>Netif</literal> column for
185 <literal>localhost</literal> is
186 <filename>lo0</filename>, also known as the loopback
187 device. This indicates that all traffic for this
188 destination should be internal, rather than sending it
189 out over the network.</para>
190 </listitem>
191 </varlistentry>
192
193 <varlistentry>
194 <term>MAC address</term>
195 <listitem>
196 <para>The addresses beginning with <systemitem
197 class="etheraddress">0:e0:</systemitem> are
198 <acronym>MAC</acronym> addresses. &os; will
199 automatically identify any hosts,
200 <systemitem>test0</systemitem> in the example, on the
201 local Ethernet and add a route for that host over the
202 Ethernet interface, <filename>re0</filename>. This type
203 of route has a timeout, seen in the
204 <literal>Expire</literal> column, which is used if the
205 host does not respond in a specific amount of time.
206 When this happens, the route to this host will be
207 automatically deleted. These hosts are identified using
208 the Routing Information Protocol
209 (<acronym>RIP</acronym>), which calculates routes to
210 local hosts based upon a shortest path
211 determination.</para>
212 </listitem>
213 </varlistentry>
214
215 <varlistentry>
216 <term>subnet</term>
217 <listitem>
218 <para>&os; will automatically add subnet routes for the
219 local subnet. In this example, <systemitem
220 class="ipaddress">10.20.30.255</systemitem> is the
221 broadcast address for the subnet <systemitem
222 class="ipaddress">10.20.30</systemitem> and
223 <systemitem
224 class="fqdomainname">example.com</systemitem> is the
225 domain name associated with that subnet. The
226 designation <literal>link#1</literal> refers to the
227 first Ethernet card in the machine.</para>
228
229 <para>Local network hosts and local subnets have their
230 routes automatically configured by a daemon called
231 &man.routed.8;. If it is not running, only routes which
232 are statically defined by the administrator will
233 exist.</para>
234 </listitem>
235 </varlistentry>
236
237 <varlistentry>
238 <term>host</term>
239 <listitem>
240 <para>The <literal>host1</literal> line refers to the host
241 by its Ethernet address. Since it is the sending host,
242 &os; knows to use the loopback interface
243 (<filename>lo0</filename>) rather than the Ethernet
244 interface.</para>
245
246 <para>The two <literal>host2</literal> lines represent
247 aliases which were created using &man.ifconfig.8;. The
248 <literal>=&gt;</literal> symbol after the
249 <filename>lo0</filename> interface says that an alias
250 has been set in addition to the loopback address. Such
251 routes only show up on the host that supports the alias
252 and all other hosts on the local network will have a
253 <literal>link#1</literal> line for such routes.</para>
254 </listitem>
255 </varlistentry>
256
257 <varlistentry>
258 <term>224</term>
259 <listitem>
260 <para>The final line (destination subnet <systemitem
261 class="ipaddress">224</systemitem>) deals with
262 multicasting.</para>
263 </listitem>
264 </varlistentry>
265 </variablelist>
266
267 <para>Various attributes of each route can be seen in the
268 <literal>Flags</literal> column. <xref linkend="routeflags"/>
269 summarizes some of these flags and their meanings:</para>
270
271 <table xml:id="routeflags" frame="none" pgwide="1">
272 <title>Commonly Seen Routing Table Flags</title>
273
274 <tgroup cols="2">
275 <thead>
276 <row>
277 <entry>Command</entry>
278 <entry>Purpose</entry>
279 </row>
280 </thead>
281
282 <tbody>
283 <row>
284 <entry>U</entry>
285 <entry>The route is active (up).</entry>
286 </row>
287
288 <row>
289 <entry>H</entry>
290 <entry>The route destination is a single host.</entry>
291 </row>
292
293 <row>
294 <entry>G</entry>
295 <entry>Send anything for this destination on to this
296 gateway, which will figure out from there where to
297 send it.</entry>
298 </row>
299
300 <row>
301 <entry>S</entry>
302 <entry>This route was statically configured.</entry>
303 </row>
304
305 <row>
306 <entry>C</entry>
307 <entry>Clones a new route based upon this route for
308 machines to connect to. This type of route is
309 normally used for local networks.</entry>
310 </row>
311
312 <row>
313 <entry>W</entry>
314 <entry>The route was auto-configured based upon a local
315 area network (clone) route.</entry>
316 </row>
317
318 <row>
319 <entry>L</entry>
320 <entry>Route involves references to Ethernet (link)
321 hardware.</entry>
322 </row>
323 </tbody>
324 </tgroup>
325 </table>
326
327 <para>On a &os; system, the default route can defined in
328 <filename>/etc/rc.conf</filename> by specifying the
329 <acronym>IP</acronym> address of the default gateway:</para>
330
331 <programlisting>defaultrouter="10.20.30.1"</programlisting>
332
333 <para>It is also possible to manually add the route using
334 <command>route</command>:</para>
335
336 <screen>&prompt.root; <userinput>route add default 10.20.30.1</userinput></screen>
337
338 <para>Note that manually added routes will not survive a reboot.
339 For more information on manual manipulation of network
340 routing tables, refer to &man.route.8;.</para>
341 </sect2>
342
343 <sect2 xml:id="network-static-routes">
344 <info>
345 <title>Configuring a Router with Static Routes</title>
346
347 <authorgroup>
348 <author>
349 <personname>
350 <firstname>Al</firstname>
351 <surname>Hoang</surname>
352 </personname>
353 <contrib>Contributed by </contrib>
354 </author>
355 </authorgroup>
356 </info>
357 <!-- Feb 2004 -->
358
359 <indexterm>
360 <primary>dual homed hosts</primary>
361 </indexterm>
362
363 <para>A &os; system can be configured as the default gateway, or
364 router, for a network if it is a dual-homed system. A
365 dual-homed system is a host which resides on at least two
366 different networks. Typically, each network is connected to a
367 separate network interface, though <acronym>IP</acronym>
368 aliasing can be used to bind multiple addresses, each on a
369 different subnet, to one physical interface.</para>
370
371 <indexterm>
372 <primary>router</primary>
373 </indexterm>
374
375 <para>In order for the system to forward packets between
376 interfaces, &os; must be configured as a router. Internet
377 standards and good engineering practice prevent the &os;
378 Project from enabling this feature by default, but it can be
379 configured to start at boot by adding this line to
380 <filename>/etc/rc.conf</filename>:</para>
381
382 <programlisting>gateway_enable="YES" # Set to YES if this host will be a gateway</programlisting>
383
384 <para>To enable routing now, set the &man.sysctl.8; variable
385 <varname>net.inet.ip.forwarding</varname> to
386 <literal>1</literal>. To stop routing, reset this variable to
387 <literal>0</literal>.</para>
388
389 <indexterm>
390 <primary>BGP</primary>
391 </indexterm>
392 <indexterm>
393 <primary>RIP</primary>
394 </indexterm>
395 <indexterm>
396 <primary>OSPF</primary>
397 </indexterm>
398
399 <para>The routing table of a router needs additional routes so
400 it knows how to reach other networks. Routes can be either
401 added manually using static routes or routes can be
402 automatically learned using a routing protocol. Static routes
403 are appropriate for small networks and this section describes
404 how to add a static routing entry for a small network.</para>
405
406 <note>
407 <para>For large networks, static routes quickly become
408 unscalable. &os; comes with the standard
409 <acronym>BSD</acronym> routing daemon &man.routed.8;, which
410 provides the routing protocols <acronym>RIP</acronym>,
411 versions 1 and 2, and <acronym>IRDP</acronym>. Support for
412 the <acronym>BGP</acronym> and <acronym>OSPF</acronym>
413 routing protocols can be installed using the
414 <package>net/zebra</package> package or port.</para>
415 </note>
416
417 <para>Consider the following network:</para>
418
419 <mediaobject>
420 <imageobject>
421 <imagedata fileref="advanced-networking/static-routes"/>
422 </imageobject>
423
424 <textobject>
425 <literallayout class="monospaced">
426 INTERNET
427 | (10.0.0.1/24) Default Router to Internet
428 |
429 |Interface xl0
430 |10.0.0.10/24
431 +------+
432 | | RouterA
433 | | (FreeBSD gateway)
434 +------+
435 | Interface xl1
436 | 192.168.1.1/24
437 |
438 +--------------------------------+
439 Internal Net 1 | 192.168.1.2/24
440 |
441 +------+
442 | | RouterB
443 | |
444 +------+
445 | 192.168.2.1/24
446 |
447 Internal Net 2</literallayout>
448 </textobject>
449 </mediaobject>
450
451 <para>In this scenario, <systemitem>RouterA</systemitem> is a
452 &os; machine that is acting as a router to the rest of the
453 Internet. It has a default route set to <systemitem
454 class="ipaddress">10.0.0.1</systemitem> which allows it to
455 connect with the outside world.
456 <systemitem>RouterB</systemitem> is already configured to use
457 <systemitem class="ipaddress">192.168.1.1</systemitem> as its
458 default gateway.</para>
459
460 <para>Before adding any static routes, the routing table on
461 <systemitem>RouterA</systemitem> looks like this:</para>
462
463 <screen>&prompt.user; <userinput>netstat -nr</userinput>
464 Routing tables
465
466 Internet:
467 Destination Gateway Flags Refs Use Netif Expire
468 default 10.0.0.1 UGS 0 49378 xl0
469 127.0.0.1 127.0.0.1 UH 0 6 lo0
470 10.0.0.0/24 link#1 UC 0 0 xl0
471 192.168.1.0/24 link#2 UC 0 0 xl1</screen>
472
473 <para>With the current routing table,
474 <systemitem>RouterA</systemitem> does not have a route to the
475 <systemitem class="ipaddress">192.168.2.0/24</systemitem>
476 network. The following command adds the <literal>Internal Net
477 2</literal> network to <systemitem>RouterA</systemitem>'s
478 routing table using <systemitem
479 class="ipaddress">192.168.1.2</systemitem> as the next
480 hop:</para>
481
482 <screen>&prompt.root; <userinput>route add -net 192.168.2.0/24 192.168.1.2</userinput></screen>
483
484 <para>Now, <systemitem>RouterA</systemitem> can reach any host
485 on the <systemitem
486 class="ipaddress">192.168.2.0/24</systemitem> network.
487 However, the routing information will not persist if the &os;
488 system reboots. If a static route needs to be persistent, add
489 it to <filename>/etc/rc.conf</filename>:</para>
490
491 <programlisting># Add Internal Net 2 as a persistent static route
492 static_routes="internalnet2"
493 route_internalnet2="-net 192.168.2.0/24 192.168.1.2"</programlisting>
494
495 <para>The <literal>static_routes</literal> configuration
496 variable is a list of strings separated by a space, where each
497 string references a route name. The variable
498 <literal>route_<replaceable>internalnet2</replaceable></literal>
499 contains the static route for that route name.</para>
500
501 <para>Using more than one string in
502 <literal>static_routes</literal> creates multiple static
503 routes. The following shows an example of adding static
504 routes for the <systemitem
505 class="ipaddress">192.168.0.0/24</systemitem> and
506 <systemitem class="ipaddress">192.168.1.0/24</systemitem>
507 networks:</para>
508
509 <programlisting>static_routes="net1 net2"
510 route_net1="-net 192.168.0.0/24 192.168.0.1"
511 route_net2="-net 192.168.1.0/24 192.168.1.1"</programlisting>
512 </sect2>
513
514 <sect2 xml:id="network-routing-troubleshooting">
515 <title>Troubleshooting</title>
516
517 <para>When an address space is assigned to a network, the
518 service provider configures their routing tables so that all
519 traffic for the network will be sent to the link for the site.
520 But how do external sites know to send their packets to the
521 network's <acronym>ISP</acronym>?</para>
522
523 <para>There is a system that keeps track of all assigned
524 address spaces and defines their point of connection to the
525 Internet backbone, or the main trunk lines that carry Internet
526 traffic across the country and around the world. Each
527 backbone machine has a copy of a master set of tables, which
528 direct traffic for a particular network to a specific
529 backbone carrier, and from there down the chain of service
530 providers until it reaches a particular network.</para>
531
532 <para>It is the task of the service provider to advertise to
533 the backbone sites that they are the point of connection, and
534 thus the path inward, for a site. This is known as route
535 propagation.</para>
536
537 <indexterm>
538 <primary>&man.traceroute.8;</primary>
539 </indexterm>
540
541 <para>Sometimes, there is a problem with route propagation and
542 some sites are unable to connect. Perhaps the most useful
543 command for trying to figure out where routing is breaking
544 down is <command>traceroute</command>. It is useful when
545 <command>ping</command> fails.</para>
546
547 <para>When using <command>traceroute</command>, include the
548 address of the remote host to connect to. The output will
549 show the gateway hosts along the path of the attempt,
550 eventually either reaching the target host, or terminating
551 because of a lack of connection. For more information, refer
552 to &man.traceroute.8;.</para>
553 </sect2>
554
555 <sect2 xml:id="network-routing-multicast">
556 <title>Multicast Considerations</title>
557
558 <indexterm>
559 <primary>multicast routing</primary>
560 </indexterm>
561 <indexterm>
562 <primary>kernel options</primary>
563 <secondary>MROUTING</secondary>
564 </indexterm>
565
566 <para>&os; natively supports both multicast applications and
567 multicast routing. Multicast applications do not require any
568 special configuration in order to run on &os;. Support for
569 multicast routing requires that the following option be
570 compiled into a custom kernel:</para>
571
572 <programlisting>options MROUTING</programlisting>
573
574 <para>The multicast routing daemon,
575 <application>mrouted</application> can be installed using the
576 <package>net/mrouted</package> package or port. This daemon
577 implements the <acronym>DVMRP</acronym> multicast routing
578 protocol and is configured by editing
579 <filename>/usr/local/etc/mrouted.conf</filename> in order to
580 set up the tunnels and <acronym>DVMRP</acronym>. The
581 installation of <application>mrouted</application> also
582 installs <application>map-mbone</application> and
583 <application>mrinfo</application>, as well as their associated
584 man pages. Refer to these for configuration examples.</para>
585
586 <note>
587 <para><acronym>DVMRP</acronym> has largely been replaced by
588 the <acronym>PIM</acronym> protocol in many multicast
589 installations. Refer to &man.pim.4; for more
590 information.</para>
591 </note>
592 </sect2>
593 </sect1>
594
595 <sect1 xml:id="network-wireless">
596 <info>
597 <title>Wireless Networking</title>
598
599 <authorgroup>
600 <author>
601 <personname>
602 <othername>Loader</othername>
603 </personname>
604 </author>
605 <author>
606 <personname>
607 <firstname>Marc</firstname>
608 <surname>Fonvieille</surname>
609 </personname>
610 </author>
611 <author>
612 <personname>
613 <firstname>Murray</firstname>
614 <surname>Stokely</surname>
615 </personname>
616 </author>
617 </authorgroup>
618 </info>
619
620 <indexterm>
621 <primary>wireless networking</primary>
622 </indexterm>
623 <indexterm>
624 <primary>802.11</primary>
625 <see>wireless networking</see>
626 </indexterm>
627
628 <sect2>
629 <title>Wireless Networking Basics</title>
630
631 <para>Most wireless networks are based on the &ieee; 802.11
632 standards. A basic wireless network consists of multiple
633 stations communicating with radios that broadcast in either
634 the 2.4GHz or 5GHz band, though this varies according to the
635 locale and is also changing to enable communication in the
636 2.3GHz and 4.9GHz ranges.</para>
637
638 <para>802.11 networks are organized in two ways. In
639 <emphasis>infrastructure mode</emphasis>, one station acts as
640 a
641 master with all the other stations associating to it, the
642 network is known as a <acronym>BSS</acronym>, and the master
643 station is termed an access point (<acronym>AP</acronym>).
644 In a <acronym>BSS</acronym>, all communication passes through
645 the <acronym>AP</acronym>; even when one station wants to
646 communicate with another wireless station, messages must go
647 through the <acronym>AP</acronym>. In the second form of
648 network, there is no master and stations communicate directly.
649 This form of network is termed an <acronym>IBSS</acronym>
650 and is commonly known as an <emphasis>ad-hoc
651 network</emphasis>.</para>
652
653 <para>802.11 networks were first deployed in the 2.4GHz band
654 using protocols defined by the &ieee; 802.11 and 802.11b
655 standard. These specifications include the operating
656 frequencies and the <acronym>MAC</acronym> layer
657 characteristics, including framing and transmission rates,
658 as communication can occur at various rates. Later, the
659 802.11a standard defined operation in the 5GHz band, including
660 different signaling mechanisms and higher transmission rates.
661 Still later, the 802.11g standard defined the use of 802.11a
662 signaling and transmission mechanisms in the 2.4GHz band in
663 such a way as to be backwards compatible with 802.11b
664 networks.</para>
665
666 <para>Separate from the underlying transmission techniques,
667 802.11 networks have a variety of security mechanisms. The
668 original 802.11 specifications defined a simple security
669 protocol called <acronym>WEP</acronym>. This protocol uses a
670 fixed pre-shared key and the RC4 cryptographic cipher to
671 encode data transmitted on a network. Stations must all
672 agree on the fixed key in order to communicate. This scheme
673 was shown to be easily broken and is now rarely used except
674 to discourage transient users from joining networks. Current
675 security practice is given by the &ieee; 802.11i specification
676 that defines new cryptographic ciphers and an additional
677 protocol to authenticate stations to an access point and
678 exchange keys for data communication. Cryptographic keys
679 are periodically refreshed and there are mechanisms for
680 detecting and countering intrusion attempts. Another
681 security protocol specification commonly used in wireless
682 networks is termed <acronym>WPA</acronym>, which was a
683 precursor to 802.11i. <acronym>WPA</acronym> specifies a
684 subset of the requirements found in 802.11i and is designed
685 for implementation on legacy hardware. Specifically,
686 <acronym>WPA</acronym> requires only the
687 <acronym>TKIP</acronym> cipher that is derived from the
688 original <acronym>WEP</acronym> cipher. 802.11i permits use
689 of <acronym>TKIP</acronym> but also requires support for a
690 stronger cipher, AES-CCM, for encrypting data. The
691 <acronym>AES</acronym> cipher was not required in
692 <acronym>WPA</acronym> because it was deemed too
693 computationally costly to be implemented on legacy
694 hardware.</para>
695
696 <para>The other standard to be aware of is 802.11e. It defines
697 protocols for deploying multimedia applications, such as
698 streaming video and voice over IP (<acronym>VoIP</acronym>),
699 in an 802.11 network. Like 802.11i, 802.11e also has a
700 precursor specification termed <acronym>WME</acronym> (later
701 renamed <acronym>WMM</acronym>) that has been defined by an
702 industry group as a subset of 802.11e that can be deployed now
703 to enable multimedia applications while waiting for the final
704 ratification of 802.11e. The most important thing to know
705 about 802.11e and
706 <acronym>WME</acronym>/<acronym>WMM</acronym> is that it
707 enables prioritized traffic over a wireless network through
708 Quality of Service (<acronym>QoS</acronym>) protocols and
709 enhanced media access protocols. Proper implementation of
710 these protocols enables high speed bursting of data and
711 prioritized traffic flow.</para>
712
713 <para>&os; supports networks that operate using 802.11a,
714 802.11b, and 802.11g. The <acronym>WPA</acronym> and 802.11i
715 security protocols are likewise supported (in conjunction with
716 any of 11a, 11b, and 11g) and <acronym>QoS</acronym> and
717 traffic prioritization required by the
718 <acronym>WME</acronym>/<acronym>WMM</acronym> protocols are
719 supported for a limited set of wireless devices.</para>
720 </sect2>
721
722 <sect2 xml:id="network-wireless-quick-start">
723 <title>Quick Start</title>
724
725 <para>Connecting a computer to an existing wireless network is
726 a very common situation. This procedure shows the steps
727 required.</para>
728
729 <procedure>
730 <step>
731 <para>Obtain the <acronym>SSID</acronym> (Service Set
732 Identifier) and <acronym>PSK</acronym> (Pre-Shared Key)
733 for the wireless network from the network
734 administrator.</para>
735 </step>
736
737 <step>
738 <para>Identify the wireless adapter. The &os;
739 <filename>GENERIC</filename> kernel includes drivers for
740 many common wireless adapters. If the wireless adapter is
741 one of those models, it will be shown in the output from
742 &man.ifconfig.8;:</para>
743
744 <screen>&prompt.user; <userinput>ifconfig | grep -B3 -i wireless</userinput></screen>
745
746 <para>If a wireless adapter is not listed, an additional
747 kernel module might be required, or it might be a model
748 not supported by &os;.</para>
749 <!-- WB: refer to section that shows how to identify a
750 wireless adapter and load the kernel modules for it. -->
751
752 <para>This example shows the Atheros <literal>ath0</literal>
753 wireless adapter.</para>
754 </step>
755
756 <step>
757 <para>Add an entry for this network to
758 <filename>/etc/wpa_supplicant.conf</filename>. If the
759 file does not exist, create it. Replace
760 <replaceable>myssid</replaceable> and
761 <replaceable>mypsk</replaceable> with the
762 <acronym>SSID</acronym> and <acronym>PSK</acronym>
763 provided by the network administrator.</para>
764
765 <programlisting>network={
766 ssid="<replaceable>myssid</replaceable>"
767 psk="<replaceable>mypsk</replaceable>"
768 }</programlisting>
769 </step>
770
771 <step>
772 <para>Add entries to <filename>/etc/rc.conf</filename> to
773 configure the network on startup:</para>
774
775 <programlisting>wlans_<replaceable>ath0</replaceable>="wlan0"
776 ifconfig_wlan0="WPA SYNCDHCP"</programlisting>
777 </step>
778
779 <step>
780 <para>Restart the computer, or restart the network service
781 to connect to the network:</para>
782
783 <screen>&prompt.root; <userinput>service netif restart</userinput></screen>
784 </step>
785 </procedure>
786 </sect2>
787
788 <sect2 xml:id="network-wireless-basic">
789 <title>Basic Setup</title>
790
791 <sect3>
792 <title>Kernel Configuration</title>
793
794 <para>To use wireless networking, a wireless networking card
795 is needed and the kernel needs to be configured with the
796 appropriate wireless networking support. The kernel is
797 separated into multiple modules so that only the required
798 support needs to be configured.</para>
799
800 <para>The most
801 commonly used wireless devices are those that use parts made
802 by Atheros. These devices are supported by &man.ath.4;
803 and require the following line to be added to
804 <filename>/boot/loader.conf</filename>:</para>
805
806 <programlisting>if_ath_load="YES"</programlisting>
807
808 <para>The Atheros driver is split up into three separate
809 pieces: the driver (&man.ath.4;), the hardware support
810 layer that handles chip-specific functions
811 (&man.ath.hal.4;), and an algorithm for selecting the
812 rate for transmitting frames. When this support is loaded
813 as kernel modules, any dependencies are automatically
814 handled. To load support for a different type of wireless
815 device, specify the module for that device. This example
816 is for devices based on the Intersil Prism parts
817 (&man.wi.4;) driver:</para>
818
819 <programlisting>if_wi_load="YES"</programlisting>
820
821 <note>
822 <para>The examples in this section use an &man.ath.4;
823 device and the device name in the examples must be
824 changed according to the configuration. A list of
825 available wireless drivers and supported adapters can be
826 found in the &os; Hardware Notes, available on
827 the <link
828 xlink:href="http://www.FreeBSD.org/releases/index.html">Release
829 Information</link> page of the &os; website. If a
830 native &os; driver for the wireless device does not
831 exist, it may be possible to use the &windows; driver
832 with the help of the <link
833 linkend="config-network-ndis">NDIS</link> driver
834 wrapper.</para>
835 </note>
836
837 <para>In addition, the modules that implement cryptographic
838 support for the security protocols to use must be loaded.
839 These are intended to be dynamically loaded on demand by
840 the &man.wlan.4; module, but for now they must be manually
841 configured. The following modules are available:
842 &man.wlan.wep.4;, &man.wlan.ccmp.4;, and &man.wlan.tkip.4;.
843 The &man.wlan.ccmp.4; and &man.wlan.tkip.4; drivers are
844 only needed when using the <acronym>WPA</acronym> or
845 802.11i security protocols. If the network does not use
846 encryption, &man.wlan.wep.4; support is not needed. To
847 load these modules at boot time, add the following lines to
848 <filename>/boot/loader.conf</filename>:</para>
849
850 <programlisting>wlan_wep_load="YES"
851 wlan_ccmp_load="YES"
852 wlan_tkip_load="YES"</programlisting>
853
854 <para>Once this information has been added to
855 <filename>/boot/loader.conf</filename>, reboot the &os;
856 box. Alternately, load the modules by hand using
857 &man.kldload.8;.</para>
858
859 <note>
860 <para>For users who do not want to use modules, it is
861 possible to compile these drivers into the kernel by
862 adding the following lines to a custom kernel
863 configuration file:</para>
864
865 <programlisting>device wlan # 802.11 support
866 device wlan_wep # 802.11 WEP support
867 device wlan_ccmp # 802.11 CCMP support
868 device wlan_tkip # 802.11 TKIP support
869 device wlan_amrr # AMRR transmit rate control algorithm
870 device ath # Atheros pci/cardbus NIC's
871 device ath_hal # pci/cardbus chip support
872 options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors
873 device ath_rate_sample # SampleRate tx rate control for ath</programlisting>
874
875 <para>With this information in the kernel configuration
876 file, recompile the kernel and reboot the &os;
877 machine.</para>
878 </note>
879
880 <para>Information about the wireless device should appear
881 in the boot messages, like this:</para>
882
883 <screen>ath0: &lt;Atheros 5212&gt; mem 0x88000000-0x8800ffff irq 11 at device 0.0 on cardbus1
884 ath0: [ITHREAD]
885 ath0: AR2413 mac 7.9 RF2413 phy 4.5</screen>
886 </sect3>
887 </sect2>
888
889 <sect2>
890 <title>Infrastructure Mode</title>
891
892 <para>Infrastructure (<acronym>BSS</acronym>) mode is the
893 mode that is typically used. In this mode, a number of
894 wireless access points are connected to a wired network.
895 Each wireless network has its own name, called the
896 <acronym>SSID</acronym>. Wireless clients connect to the
897 wireless access points.</para>
898
899 <sect3>
900 <title>&os; Clients</title>
901
902 <sect4>
903 <title>How to Find Access Points</title>
904
905 <para>To scan for available networks, use &man.ifconfig.8;.
906 This request may take a few moments to complete as it
907 requires the system to switch to each available wireless
908 frequency and probe for available access points. Only
909 the superuser can initiate a scan:</para>
910
911 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable></userinput>
912 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> up scan</userinput>
913 SSID/MESH ID BSSID CHAN RATE S:N INT CAPS
914 dlinkap 00:13:46:49:41:76 11 54M -90:96 100 EPS WPA WME
915 freebsdap 00:11:95:c3:0d:ac 1 54M -83:96 100 EPS WPA</screen>
916
917 <note>
918 <para>The interface must be <option>up</option> before
919 it can scan. Subsequent scan requests do not require
920 the interface to be marked as up again.</para>
921 </note>
922
923 <para>The output of a scan request lists each
924 <acronym>BSS</acronym>/<acronym>IBSS</acronym> network
925 found. Besides listing the name of the network, the
926 <literal>SSID</literal>, the output also shows the
927 <literal>BSSID</literal>, which is the
928 <acronym>MAC</acronym> address of the access point. The
929 <literal>CAPS</literal> field identifies the type of
930 each network and the capabilities of the stations
931 operating there:</para>
932
933 <table frame="none" pgwide="0">
934 <title>Station Capability Codes</title>
935
936 <tgroup cols="2">
937 <thead>
938 <row>
939 <entry>Capability Code</entry>
940 <entry>Meaning</entry>
941 </row>
942 </thead>
943
944 <tbody>
945 <row>
946 <entry><literal>E</literal></entry>
947 <entry>Extended Service Set
948 (<acronym>ESS</acronym>). Indicates that
949 the station is part of an infrastructure network
950 rather than an <acronym>IBSS</acronym>/ad-hoc
951 network.</entry>
952 </row>
953
954 <row>
955 <entry><literal>I</literal></entry>
956 <entry><acronym>IBSS</acronym>/ad-hoc network.
957 Indicates that the station is part of an ad-hoc
958 network rather than an <acronym>ESS</acronym>
959 network.</entry>
960 </row>
961
962 <row>
963 <entry><literal>P</literal></entry>
964 <entry>Privacy. Encryption is required for all
965 data frames exchanged within the
966 <acronym>BSS</acronym> using cryptographic means
967 such as <acronym>WEP</acronym>,
968 <acronym>TKIP</acronym> or
969 <acronym>AES</acronym>-<acronym>CCMP</acronym>.</entry>
970 </row>
971
972 <row>
973 <entry><literal>S</literal></entry>
974 <entry>Short Preamble. Indicates that the network
975 is using short preambles, defined in 802.11b High
976 Rate/DSSS PHY, and utilizes a 56 bit sync field
977 rather than the 128 bit field used in long
978 preamble mode.</entry>
979 </row>
980
981 <row>
982 <entry><literal>s</literal></entry>
983 <entry>Short slot time. Indicates that the 802.11g
984 network is using a short slot time because there
985 are no legacy (802.11b) stations present.</entry>
986 </row>
987 </tbody>
988 </tgroup>
989 </table>
990
991 <para>One can also display the current list of known
992 networks with:</para>
993
994 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> list scan</userinput></screen>
995
996 <para>This information may be updated automatically by the
997 adapter or manually with a <option>scan</option> request.
998 Old data is automatically removed from the cache, so over
999 time this list may shrink unless more scans are
1000 done.</para>
1001 </sect4>
1002
1003 <sect4>
1004 <title>Basic Settings</title>
1005
1006 <para>This section provides a simple example of how to make
1007 the wireless network adapter work in &os; without
1008 encryption. Once familiar with these concepts, it is
1009 strongly recommend to use <link
1010 linkend="network-wireless-wpa">WPA</link> to set up
1011 the wireless network.</para>
1012
1013 <para>There are three basic steps to configure a wireless
1014 network: select an access point, authenticate the
1015 station, and configure an <acronym>IP</acronym> address.
1016 The following sections discuss each step.</para>
1017
1018 <sect5>
1019 <title>Selecting an Access Point</title>
1020
1021 <para>Most of the time, it is sufficient to let the system
1022 choose an access point using the builtin heuristics.
1023 This is the default behavior when an interface is
1024 marked as up or it is listed in
1025 <filename>/etc/rc.conf</filename>:</para>
1026
1027 <programlisting>wlans_ath0="wlan0"
1028 ifconfig_wlan0="DHCP"</programlisting>
1029
1030 <para>If there are multiple access points, a specific
1031 one can be selected by its
1032 <acronym>SSID</acronym>:</para>
1033
1034 <programlisting>wlans_ath0="wlan0"
1035 ifconfig_wlan0="ssid <replaceable>your_ssid_here</replaceable> DHCP"</programlisting>
1036
1037 <para>In an environment where there are multiple access
1038 points with the same <acronym>SSID</acronym>, which
1039 is often done to simplify roaming, it may be necessary
1040 to associate to one specific device. In this case, the
1041 <acronym>BSSID</acronym> of the access point can be
1042 specified, with or without the
1043 <acronym>SSID</acronym>:</para>
1044
1045 <programlisting>wlans_ath0="wlan0"
1046 ifconfig_wlan0="ssid <replaceable>your_ssid_here</replaceable> bssid <replaceable>xx:xx:xx:xx:xx:xx</replaceable> DHCP"</programlisting>
1047
1048 <para>There are other ways to constrain the choice of an
1049 access point, such as limiting the set of frequencies
1050 the system will scan on. This may be useful for a
1051 multi-band wireless card as scanning all the possible
1052 channels can be time-consuming. To limit operation to a
1053 specific band, use the <option>mode</option>
1054 parameter:</para>
1055
1056 <programlisting>wlans_ath0="wlan0"
1057 ifconfig_wlan0="mode <replaceable>11g</replaceable> ssid <replaceable>your_ssid_here</replaceable> DHCP"</programlisting>
1058
1059 <para>This example will force the card to operate in
1060 802.11g, which is defined only for 2.4GHz frequencies
1061 so any 5GHz channels will not be considered. This can
1062 also be achieved with the
1063 <option>channel</option> parameter, which locks
1064 operation to one specific frequency, and the
1065 <option>chanlist</option> parameter, to specify a list
1066 of channels for scanning. More information about these
1067 parameters can be found in &man.ifconfig.8;.</para>
1068 </sect5>
1069
1070 <sect5>
1071 <title>Authentication</title>
1072
1073 <para>Once an access point is selected, the station
1074 needs to authenticate before it can pass data.
1075 Authentication can happen in several ways. The most
1076 common scheme, open authentication, allows any station
1077 to join the network and communicate. This is the
1078 authentication to use for test purposes the first time
1079 a wireless network is setup. Other schemes require
1080 cryptographic handshakes to be completed before data
1081 traffic can flow, either using pre-shared keys or
1082 secrets, or more complex schemes that involve backend
1083 services such as <acronym>RADIUS</acronym>. Open
1084 authentication is the default setting. The next most
1085 common setup is <acronym>WPA-PSK</acronym>, also
1086 known as <acronym>WPA</acronym> Personal, which is
1087 described in <xref
1088 linkend="network-wireless-wpa-wpa-psk"/>.</para>
1089
1090 <note>
1091 <para>If using an &apple; &airport; Extreme base
1092 station for an access point, shared-key authentication
1093 together with a <acronym>WEP</acronym> key needs to
1094 be configured. This can be configured in
1095 <filename>/etc/rc.conf</filename> or by using
1096 &man.wpa.supplicant.8;. For a single &airport; base
1097 station, access can be configured with:</para>
1098
1099 <programlisting>wlans_ath0="wlan0"
1100 ifconfig_wlan0="authmode shared wepmode on weptxkey <replaceable>1</replaceable> wepkey <replaceable>01234567</replaceable> DHCP"</programlisting>
1101
1102 <para>In general, shared key authentication should be
1103 avoided because it uses the <acronym>WEP</acronym> key
1104 material in a highly-constrained manner, making it
1105 even easier to crack the key. If
1106 <acronym>WEP</acronym> must be used for compatibility
1107 with legacy devices, it is better to use
1108 <acronym>WEP</acronym> with <literal>open</literal>
1109 authentication. More information regarding
1110 <acronym>WEP</acronym> can be found in <xref
1111 linkend="network-wireless-wep"/>.</para>
1112 </note>
1113 </sect5>
1114
1115 <sect5>
1116 <title>Getting an <acronym>IP</acronym> Address with
1117 <acronym>DHCP</acronym></title>
1118
1119 <para>Once an access point is selected and the
1120 authentication parameters are set, an
1121 <acronym>IP</acronym> address must be obtained in
1122 order to communicate. Most of the time, the
1123 <acronym>IP</acronym> address is obtained via
1124 <acronym>DHCP</acronym>. To achieve that, edit
1125 <filename>/etc/rc.conf</filename> and add
1126 <literal>DHCP</literal> to the configuration for the
1127 device:</para>
1128
1129 <programlisting>wlans_ath0="wlan0"
1130 ifconfig_wlan0="DHCP"</programlisting>
1131
1132 <para>The
1133 wireless interface is now ready to bring up:</para>
1134
1135 <screen>&prompt.root; <userinput>service netif start</userinput></screen>
1136
1137 <para>Once the interface is running, use &man.ifconfig.8;
1138 to see the status of the interface
1139 <filename>ath0</filename>:</para>
1140
1141 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1142 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1143 ether 00:11:95:d5:43:62
1144 inet 192.168.1.100 netmask 0xffffff00 broadcast 192.168.1.255
1145 media: IEEE 802.11 Wireless Ethernet OFDM/54Mbps mode 11g
1146 status: associated
1147 ssid dlinkap channel 11 (2462 Mhz 11g) bssid 00:13:46:49:41:76
1148 country US ecm authmode OPEN privacy OFF txpower 21.5 bmiss 7
1149 scanvalid 60 bgscan bgscanintvl 300 bgscanidle 250 roam:rssi 7
1150 roam:rate 5 protmode CTS wme burst</screen>
1151
1152 <para>The <literal>status: associated</literal> line means
1153 that it is connected to the wireless network. The
1154 <literal>bssid 00:13:46:49:41:76</literal> is the
1155 <acronym>MAC</acronym> address of the access point and
1156 <literal>authmode OPEN</literal> indicates that the
1157 communication is not encrypted.</para>
1158 </sect5>
1159
1160 <sect5>
1161 <title>Static <acronym>IP</acronym> Address</title>
1162
1163 <para>If an <acronym>IP</acronym> address cannot be
1164 obtained from a <acronym>DHCP</acronym> server, set a
1165 fixed <acronym>IP</acronym> address. Replace the
1166 <literal>DHCP</literal> keyword shown above with the
1167 address information. Be sure to retain any other
1168 parameters for selecting the access point:</para>
1169
1170 <programlisting>wlans_ath0="wlan0"
1171 ifconfig_wlan0="inet <replaceable>192.168.1.100</replaceable> netmask <replaceable>255.255.255.0</replaceable> ssid <replaceable>your_ssid_here</replaceable>"</programlisting>
1172 </sect5>
1173 </sect4>
1174
1175 <sect4 xml:id="network-wireless-wpa">
1176 <title><acronym>WPA</acronym></title>
1177
1178 <para>Wi-Fi Protected Access (<acronym>WPA</acronym>) is a
1179 security protocol used together with 802.11 networks to
1180 address the lack of proper authentication and the weakness
1181 of <acronym>WEP</acronym>. WPA leverages the 802.1X
1182 authentication protocol and uses one of several ciphers
1183 instead of <acronym>WEP</acronym> for data integrity.
1184 The only cipher required by <acronym>WPA</acronym> is the
1185 Temporary Key Integrity Protocol
1186 (<acronym>TKIP</acronym>). <acronym>TKIP</acronym> is a
1187 cipher that extends the basic RC4 cipher used by
1188 <acronym>WEP</acronym> by adding integrity checking,
1189 tamper detection, and measures for responding to detected
1190 intrusions. <acronym>TKIP</acronym> is designed to work
1191 on legacy hardware with only software modification. It
1192 represents a compromise that improves security but is
1193 still not entirely immune to attack.
1194 <acronym>WPA</acronym> also specifies the
1195 <acronym>AES-CCMP</acronym> cipher as an alternative to
1196 <acronym>TKIP</acronym>, and that is preferred when
1197 possible. For this specification, the term
1198 <acronym>WPA2</acronym> or <acronym>RSN</acronym> is
1199 commonly used.</para>
1200
1201 <para><acronym>WPA</acronym> defines authentication and
1202 encryption protocols. Authentication is most commonly
1203 done using one of two techniques: by 802.1X and a backend
1204 authentication service such as <acronym>RADIUS</acronym>,
1205 or by a minimal handshake between the station and the
1206 access point using a pre-shared secret. The former is
1207 commonly termed <acronym>WPA</acronym> Enterprise and the
1208 latter is known as <acronym>WPA</acronym> Personal. Since
1209 most people will not set up a <acronym>RADIUS</acronym>
1210 backend server for their wireless network,
1211 <acronym>WPA-PSK</acronym> is by far the most commonly
1212 encountered configuration for
1213 <acronym>WPA</acronym>.</para>
1214
1215 <para>The control of the wireless connection and the key
1216 negotiation or authentication with a server is done using
1217 &man.wpa.supplicant.8;. This program requires a
1218 configuration file,
1219 <filename>/etc/wpa_supplicant.conf</filename>, to run.
1220 More information regarding this file can be found in
1221 &man.wpa.supplicant.conf.5;.</para>
1222
1223 <sect5 xml:id="network-wireless-wpa-wpa-psk">
1224 <title><acronym>WPA-PSK</acronym></title>
1225
1226 <para><acronym>WPA-PSK</acronym>, also known as
1227 <acronym>WPA</acronym> Personal, is based on a
1228 pre-shared key (<acronym>PSK</acronym>) which is
1229 generated from a given password and used as the master
1230 key in the wireless network. This means every wireless
1231 user will share the same key.
1232 <acronym>WPA-PSK</acronym> is intended for small
1233 networks where the use of an authentication server is
1234 not possible or desired.</para>
1235
1236 <warning>
1237 <para>Always use strong passwords that are sufficiently
1238 long and made from a rich alphabet so that they will
1239 not be easily guessed or attacked.</para>
1240 </warning>
1241
1242 <para>The first step is the configuration of
1243 <filename>/etc/wpa_supplicant.conf</filename> with
1244 the <acronym>SSID</acronym> and the pre-shared key of
1245 the network:</para>
1246
1247 <programlisting>network={
1248 ssid="freebsdap"
1249 psk="freebsdmall"
1250 }</programlisting>
1251
1252 <para>Then, in <filename>/etc/rc.conf</filename>,
1253 indicate that the wireless device configuration will be
1254 done with <acronym>WPA</acronym> and the
1255 <acronym>IP</acronym> address will be obtained with
1256 <acronym>DHCP</acronym>:</para>
1257
1258 <programlisting>wlans_ath0="wlan0"
1259 ifconfig_wlan0="WPA DHCP"</programlisting>
1260
1261 <para>Then, bring up the interface:</para>
1262
1263 <screen>&prompt.root; <userinput>service netif start</userinput>
1264 Starting wpa_supplicant.
1265 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 5
1266 DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 6
1267 DHCPOFFER from 192.168.0.1
1268 DHCPREQUEST on wlan0 to 255.255.255.255 port 67
1269 DHCPACK from 192.168.0.1
1270 bound to 192.168.0.254 -- renewal in 300 seconds.
1271 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1272 ether 00:11:95:d5:43:62
1273 inet 192.168.0.254 netmask 0xffffff00 broadcast 192.168.0.255
1274 media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
1275 status: associated
1276 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1277 country US ecm authmode WPA2/802.11i privacy ON deftxkey UNDEF
1278 AES-CCM 3:128-bit txpower 21.5 bmiss 7 scanvalid 450 bgscan
1279 bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5 protmode CTS
1280 wme burst roaming MANUAL</screen>
1281
1282 <para>Or, try to configure the interface manually using
1283 the information in
1284 <filename>/etc/wpa_supplicant.conf</filename>:</para>
1285
1286 <screen>&prompt.root; <userinput>wpa_supplicant -i <replaceable>wlan0</replaceable> -c /etc/wpa_supplicant.conf</userinput>
1287 Trying to associate with 00:11:95:c3:0d:ac (SSID='freebsdap' freq=2412 MHz)
1288 Associated with 00:11:95:c3:0d:ac
1289 WPA: Key negotiation completed with 00:11:95:c3:0d:ac [PTK=CCMP GTK=CCMP]
1290 CTRL-EVENT-CONNECTED - Connection to 00:11:95:c3:0d:ac completed (auth) [id=0 id_str=]</screen>
1291
1292 <para>The next operation is to launch &man.dhclient.8;
1293 to get the <acronym>IP</acronym> address from the
1294 <acronym>DHCP</acronym> server:</para>
1295
1296 <screen>&prompt.root; <userinput>dhclient <replaceable>wlan0</replaceable></userinput>
1297 DHCPREQUEST on wlan0 to 255.255.255.255 port 67
1298 DHCPACK from 192.168.0.1
1299 bound to 192.168.0.254 -- renewal in 300 seconds.
1300 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1301 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1302 ether 00:11:95:d5:43:62
1303 inet 192.168.0.254 netmask 0xffffff00 broadcast 192.168.0.255
1304 media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
1305 status: associated
1306 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1307 country US ecm authmode WPA2/802.11i privacy ON deftxkey UNDEF
1308 AES-CCM 3:128-bit txpower 21.5 bmiss 7 scanvalid 450 bgscan
1309 bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5 protmode CTS
1310 wme burst roaming MANUAL</screen>
1311
1312 <note>
1313 <para>If <filename>/etc/rc.conf</filename> has an
1314 <literal>ifconfig_wlan0="DHCP"</literal> entry,
1315 &man.dhclient.8; will be launched automatically after
1316 &man.wpa.supplicant.8; associates with the access
1317 point.</para>
1318 </note>
1319
1320 <para>If <acronym>DHCP</acronym> is not possible or
1321 desired, set a static <acronym>IP</acronym> address
1322 after &man.wpa.supplicant.8; has authenticated the
1323 station:</para>
1324
1325 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.0.100</replaceable> netmask <replaceable>255.255.255.0</replaceable></userinput>
1326 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1327 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1328 ether 00:11:95:d5:43:62
1329 inet 192.168.0.100 netmask 0xffffff00 broadcast 192.168.0.255
1330 media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
1331 status: associated
1332 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1333 country US ecm authmode WPA2/802.11i privacy ON deftxkey UNDEF
1334 AES-CCM 3:128-bit txpower 21.5 bmiss 7 scanvalid 450 bgscan
1335 bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5 protmode CTS
1336 wme burst roaming MANUAL</screen>
1337
1338 <para>When <acronym>DHCP</acronym> is not used, the
1339 default gateway and the nameserver also have to be
1340 manually set:</para>
1341
1342 <screen>&prompt.root; <userinput>route add default <replaceable>your_default_router</replaceable></userinput>
1343 &prompt.root; <userinput>echo "nameserver <replaceable>your_DNS_server</replaceable>" &gt;&gt; /etc/resolv.conf</userinput></screen>
1344 </sect5>
1345
1346 <sect5 xml:id="network-wireless-wpa-eap-tls">
1347 <title><acronym>WPA</acronym> with
1348 <acronym>EAP-TLS</acronym></title>
1349
1350 <para>The second way to use <acronym>WPA</acronym> is with
1351 an 802.1X backend authentication server. In this case,
1352 <acronym>WPA</acronym> is called
1353 <acronym>WPA</acronym> Enterprise to differentiate it
1354 from the less secure <acronym>WPA</acronym> Personal.
1355 Authentication in <acronym>WPA</acronym> Enterprise is
1356 based on the Extensible Authentication Protocol
1357 (<acronym>EAP</acronym>).</para>
1358
1359 <para><acronym>EAP</acronym> does not come with an
1360 encryption method. Instead, <acronym>EAP</acronym> is
1361 embedded inside an encrypted tunnel. There are many
1362 <acronym>EAP</acronym> authentication methods, but
1363 <acronym>EAP-TLS</acronym>, <acronym>EAP-TTLS</acronym>,
1364 and <acronym>EAP-PEAP</acronym> are the most
1365 common.</para>
1366
1367 <para>EAP with Transport Layer Security
1368 (<acronym>EAP-TLS</acronym>) is a well-supported
1369 wireless authentication protocol since it was the
1370 first <acronym>EAP</acronym> method to be certified
1371 by the <link
1372 xlink:href="http://www.wi-fi.org/">Wi-Fi
1373 Alliance</link>. <acronym>EAP-TLS</acronym> requires
1374 three certificates to run: the certificate of the
1375 Certificate Authority (<acronym>CA</acronym>) installed
1376 on all machines, the server certificate for the
1377 authentication server, and one client certificate for
1378 each wireless client. In this <acronym>EAP</acronym>
1379 method, both the authentication server and wireless
1380 client authenticate each other by presenting their
1381 respective certificates, and then verify that these
1382 certificates were signed by the organization's
1383 <acronym>CA</acronym>.</para>
1384
1385 <para>As previously, the configuration is done via
1386 <filename>/etc/wpa_supplicant.conf</filename>:</para>
1387
1388 <programlisting>network={
1389 ssid="freebsdap" <co xml:id="co-tls-ssid"/>
1390 proto=RSN <co xml:id="co-tls-proto"/>
1391 key_mgmt=WPA-EAP <co xml:id="co-tls-kmgmt"/>
1392 eap=TLS <co xml:id="co-tls-eap"/>
1393 identity="loader" <co xml:id="co-tls-id"/>
1394 ca_cert="/etc/certs/cacert.pem" <co xml:id="co-tls-cacert"/>
1395 client_cert="/etc/certs/clientcert.pem" <co xml:id="co-tls-clientcert"/>
1396 private_key="/etc/certs/clientkey.pem" <co xml:id="co-tls-pkey"/>
1397 private_key_passwd="freebsdmallclient" <co xml:id="co-tls-pwd"/>
1398 }</programlisting>
1399
1400 <calloutlist>
1401 <callout arearefs="co-tls-ssid">
1402 <para>This field indicates the network name
1403 (<acronym>SSID</acronym>).</para>
1404 </callout>
1405
1406 <callout arearefs="co-tls-proto">
1407 <para>This example uses the <acronym>RSN</acronym>
1408 &ieee; 802.11i protocol, also known as
1409 <acronym>WPA2</acronym>.</para>
1410 </callout>
1411
1412 <callout arearefs="co-tls-kmgmt">
1413 <para>The <literal>key_mgmt</literal> line refers to
1414 the key management protocol to use. In this
1415 example, it is <acronym>WPA</acronym> using
1416 <acronym>EAP</acronym> authentication.</para>
1417 </callout>
1418
1419 <callout arearefs="co-tls-eap">
1420 <para>This field indicates the <acronym>EAP</acronym>
1421 method for the connection.</para>
1422 </callout>
1423
1424 <callout arearefs="co-tls-id">
1425 <para>The <literal>identity</literal> field contains
1426 the identity string for
1427 <acronym>EAP</acronym>.</para>
1428 </callout>
1429
1430 <callout arearefs="co-tls-cacert">
1431 <para>The <literal>ca_cert</literal> field indicates
1432 the pathname of the <acronym>CA</acronym>
1433 certificate file. This file is needed to verify
1434 the server certificate.</para>
1435 </callout>
1436
1437 <callout arearefs="co-tls-clientcert">
1438 <para>The <literal>client_cert</literal> line gives
1439 the pathname to the client certificate file. This
1440 certificate is unique to each wireless client of the
1441 network.</para>
1442 </callout>
1443
1444 <callout arearefs="co-tls-pkey">
1445 <para>The <literal>private_key</literal> field is the
1446 pathname to the client certificate private key
1447 file.</para>
1448 </callout>
1449
1450 <callout arearefs="co-tls-pwd">
1451 <para>The <literal>private_key_passwd</literal> field
1452 contains the passphrase for the private key.</para>
1453 </callout>
1454 </calloutlist>
1455
1456 <para>Then, add the following lines to
1457 <filename>/etc/rc.conf</filename>:</para>
1458
1459 <programlisting>wlans_ath0="wlan0"
1460 ifconfig_wlan0="WPA DHCP"</programlisting>
1461
1462 <para>The next step is to bring up the interface:</para>
1463
1464 <screen>&prompt.root; <userinput>service netif start</userinput>
1465 Starting wpa_supplicant.
1466 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 7
1467 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 15
1468 DHCPACK from 192.168.0.20
1469 bound to 192.168.0.254 -- renewal in 300 seconds.
1470 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1471 ether 00:11:95:d5:43:62
1472 inet 192.168.0.254 netmask 0xffffff00 broadcast 192.168.0.255
1473 media: IEEE 802.11 Wireless Ethernet DS/11Mbps mode 11g
1474 status: associated
1475 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1476 country US ecm authmode WPA2/802.11i privacy ON deftxkey UNDEF
1477 AES-CCM 3:128-bit txpower 21.5 bmiss 7 scanvalid 450 bgscan
1478 bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5 protmode CTS
1479 wme burst roaming MANUAL</screen>
1480
1481 <para>It is also possible to bring up the interface
1482 manually using &man.wpa.supplicant.8; and
1483 &man.ifconfig.8;.</para>
1484 </sect5>
1485
1486 <sect5 xml:id="network-wireless-wpa-eap-ttls">
1487 <title><acronym>WPA</acronym> with
1488 <acronym>EAP-TTLS</acronym></title>
1489
1490 <para>With <acronym>EAP-TLS</acronym>, both the
1491 authentication server and the client need a certificate.
1492 With <acronym>EAP-TTLS</acronym>, a client certificate
1493 is optional. This method is similar to a web server
1494 which creates a secure <acronym>SSL</acronym> tunnel
1495 even if visitors do not have client-side certificates.
1496 <acronym>EAP-TTLS</acronym> uses an encrypted
1497 <acronym>TLS</acronym> tunnel for safe transport of
1498 the authentication data.</para>
1499
1500 <para>The required configuration can be added to
1501 <filename>/etc/wpa_supplicant.conf</filename>:</para>
1502
1503 <programlisting>network={
1504 ssid="freebsdap"
1505 proto=RSN
1506 key_mgmt=WPA-EAP
1507 eap=TTLS <co xml:id="co-ttls-eap"/>
1508 identity="test" <co xml:id="co-ttls-id"/>
1509 password="test" <co xml:id="co-ttls-passwd"/>
1510 ca_cert="/etc/certs/cacert.pem" <co xml:id="co-ttls-cacert"/>
1511 phase2="auth=MD5" <co xml:id="co-ttls-pha2"/>
1512 }</programlisting>
1513
1514 <calloutlist>
1515 <callout arearefs="co-ttls-eap">
1516 <para>This field specifies the <acronym>EAP</acronym>
1517 method for the connection.</para>
1518 </callout>
1519
1520 <callout arearefs="co-ttls-id">
1521 <para>The <literal>identity</literal> field contains
1522 the identity string for <acronym>EAP</acronym>
1523 authentication inside the encrypted
1524 <acronym>TLS</acronym> tunnel.</para>
1525 </callout>
1526
1527 <callout arearefs="co-ttls-passwd">
1528 <para>The <literal>password</literal> field contains
1529 the passphrase for the <acronym>EAP</acronym>
1530 authentication.</para>
1531 </callout>
1532
1533 <callout arearefs="co-ttls-cacert">
1534 <para>The <literal>ca_cert</literal> field indicates
1535 the pathname of the <acronym>CA</acronym>
1536 certificate file. This file is needed to verify
1537 the server certificate.</para>
1538 </callout>
1539
1540 <callout arearefs="co-ttls-pha2">
1541 <para>This field specifies the authentication
1542 method used in the encrypted <acronym>TLS</acronym>
1543 tunnel. In this example,
1544 <acronym>EAP</acronym> with MD5-Challenge is used.
1545 The <quote>inner authentication</quote> phase is
1546 often called <quote>phase2</quote>.</para>
1547 </callout>
1548 </calloutlist>
1549
1550 <para>Next, add the following lines to
1551 <filename>/etc/rc.conf</filename>:</para>
1552
1553 <programlisting>wlans_ath0="wlan0"
1554 ifconfig_wlan0="WPA DHCP"</programlisting>
1555
1556 <para>The next step is to bring up the interface:</para>
1557
1558 <screen>&prompt.root; <userinput>service netif start</userinput>
1559 Starting wpa_supplicant.
1560 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 7
1561 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 15
1562 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 21
1563 DHCPACK from 192.168.0.20
1564 bound to 192.168.0.254 -- renewal in 300 seconds.
1565 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1566 ether 00:11:95:d5:43:62
1567 inet 192.168.0.254 netmask 0xffffff00 broadcast 192.168.0.255
1568 media: IEEE 802.11 Wireless Ethernet DS/11Mbps mode 11g
1569 status: associated
1570 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1571 country US ecm authmode WPA2/802.11i privacy ON deftxkey UNDEF
1572 AES-CCM 3:128-bit txpower 21.5 bmiss 7 scanvalid 450 bgscan
1573 bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5 protmode CTS
1574 wme burst roaming MANUAL</screen>
1575 </sect5>
1576
1577 <sect5 xml:id="network-wireless-wpa-eap-peap">
1578 <title><acronym>WPA</acronym> with
1579 <acronym>EAP-PEAP</acronym></title>
1580
1581 <note>
1582 <para><acronym>PEAPv0/EAP-MSCHAPv2</acronym> is the most
1583 common <acronym>PEAP</acronym> method. In this
1584 chapter, the term <acronym>PEAP</acronym> is used to
1585 refer to that method.</para>
1586 </note>
1587
1588 <para>Protected EAP (<acronym>PEAP</acronym>) is designed
1589 as an alternative to <acronym>EAP-TTLS</acronym> and
1590 is the most used <acronym>EAP</acronym> standard after
1591 <acronym>EAP-TLS</acronym>. In a network with mixed
1592 operating systems, <acronym>PEAP</acronym> should be
1593 the most supported standard after
1594 <acronym>EAP-TLS</acronym>.</para>
1595
1596 <para><acronym>PEAP</acronym> is similar to
1597 <acronym>EAP-TTLS</acronym> as it uses a server-side
1598 certificate to authenticate clients by creating an
1599 encrypted <acronym>TLS</acronym> tunnel between the
1600 client and the authentication server, which protects
1601 the ensuing exchange of authentication information.
1602 <acronym>PEAP</acronym> authentication differs from
1603 <acronym>EAP-TTLS</acronym> as it broadcasts the
1604 username in the clear and only the password is sent
1605 in the encrypted <acronym>TLS</acronym> tunnel.
1606 <acronym>EAP-TTLS</acronym> will use the
1607 <acronym>TLS</acronym> tunnel for both the username
1608 and password.</para>
1609
1610 <para>Add the following lines to
1611 <filename>/etc/wpa_supplicant.conf</filename> to
1612 configure the <acronym>EAP-PEAP</acronym> related
1613 settings:</para>
1614
1615 <programlisting>network={
1616 ssid="freebsdap"
1617 proto=RSN
1618 key_mgmt=WPA-EAP
1619 eap=PEAP <co xml:id="co-peap-eap"/>
1620 identity="test" <co xml:id="co-peap-id"/>
1621 password="test" <co xml:id="co-peap-passwd"/>
1622 ca_cert="/etc/certs/cacert.pem" <co xml:id="co-peap-cacert"/>
1623 phase1="peaplabel=0" <co xml:id="co-peap-pha1"/>
1624 phase2="auth=MSCHAPV2" <co xml:id="co-peap-pha2"/>
1625 }</programlisting>
1626
1627 <calloutlist>
1628 <callout arearefs="co-peap-eap">
1629 <para>This field specifies the <acronym>EAP</acronym>
1630 method for the connection.</para>
1631 </callout>
1632
1633 <callout arearefs="co-peap-id">
1634 <para>The <literal>identity</literal> field contains
1635 the identity string for <acronym>EAP</acronym>
1636 authentication inside the encrypted
1637 <acronym>TLS</acronym> tunnel.</para>
1638 </callout>
1639
1640 <callout arearefs="co-peap-passwd">
1641 <para>The <literal>password</literal> field contains
1642 the passphrase for the <acronym>EAP</acronym>
1643 authentication.</para>
1644 </callout>
1645
1646 <callout arearefs="co-peap-cacert">
1647 <para>The <literal>ca_cert</literal> field indicates
1648 the pathname of the <acronym>CA</acronym>
1649 certificate file. This file is needed to verify
1650 the server certificate.</para>
1651 </callout>
1652
1653 <callout arearefs="co-peap-pha1">
1654 <para>This field contains the parameters for the
1655 first phase of authentication, the
1656 <acronym>TLS</acronym> tunnel. According to the
1657 authentication server used, specify a specific
1658 label for authentication. Most of the time, the
1659 label will be <quote>client <acronym>EAP</acronym>
1660 encryption</quote> which is set by using
1661 <literal>peaplabel=0</literal>. More information
1662 can be found in &man.wpa.supplicant.conf.5;.</para>
1663 </callout>
1664
1665 <callout arearefs="co-peap-pha2">
1666 <para>This field specifies the authentication
1667 protocol used in the encrypted
1668 <acronym>TLS</acronym> tunnel. In the
1669 case of <acronym>PEAP</acronym>, it is
1670 <literal>auth=MSCHAPV2</literal>.</para>
1671 </callout>
1672 </calloutlist>
1673
1674 <para>Add the following to
1675 <filename>/etc/rc.conf</filename>:</para>
1676
1677 <programlisting>wlans_ath0="wlan0"
1678 ifconfig_wlan0="WPA DHCP"</programlisting>
1679
1680 <para>Then, bring up the interface:</para>
1681
1682 <screen>&prompt.root; <userinput>service netif start</userinput>
1683 Starting wpa_supplicant.
1684 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 7
1685 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 15
1686 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 interval 21
1687 DHCPACK from 192.168.0.20
1688 bound to 192.168.0.254 -- renewal in 300 seconds.
1689 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; mtu 1500
1690 ether 00:11:95:d5:43:62
1691 inet 192.168.0.254 netmask 0xffffff00 broadcast 192.168.0.255
1692 media: IEEE 802.11 Wireless Ethernet DS/11Mbps mode 11g
1693 status: associated
1694 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1695 country US ecm authmode WPA2/802.11i privacy ON deftxkey UNDEF
1696 AES-CCM 3:128-bit txpower 21.5 bmiss 7 scanvalid 450 bgscan
1697 bgscanintvl 300 bgscanidle 250 roam:rssi 7 roam:rate 5 protmode CTS
1698 wme burst roaming MANUAL</screen>
1699 </sect5>
1700 </sect4>
1701
1702 <sect4 xml:id="network-wireless-wep">
1703 <title><acronym>WEP</acronym></title>
1704
1705 <para>Wired Equivalent Privacy (<acronym>WEP</acronym>) is
1706 part of the original 802.11 standard. There is no
1707 authentication mechanism, only a weak form of access
1708 control which is easily cracked.</para>
1709
1710 <para><acronym>WEP</acronym> can be set up using
1711 &man.ifconfig.8;:</para>
1712
1713 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable></userinput>
1714 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.1.100</replaceable> netmask <replaceable>255.255.255.0</replaceable> \
1715 ssid <replaceable>my_net</replaceable> wepmode on weptxkey <replaceable>3</replaceable> wepkey <replaceable>3:0x3456789012</replaceable></userinput></screen>
1716
1717 <itemizedlist>
1718 <listitem>
1719
1720 <para>The <literal>weptxkey</literal> specifies which
1721 <acronym>WEP</acronym> key will be used in the
1722 transmission. This example uses the third key.
1723 This must match the setting on the access point.
1724 When unsure which key is used by the access point,
1725 try <literal>1</literal> (the first key) for this
1726 value.</para>
1727 </listitem>
1728
1729 <listitem>
1730 <para>The <literal>wepkey</literal> selects one of the
1731 <acronym>WEP</acronym> keys. It should be in the
1732 format <replaceable>index:key</replaceable>. Key
1733 <literal>1</literal> is used by default; the index
1734 only needs to be set when using a key other than the
1735 first key.</para>
1736
1737 <note>
1738 <para>Replace the <literal>0x3456789012</literal>
1739 with the key configured for use on the access
1740 point.</para>
1741 </note>
1742 </listitem>
1743 </itemizedlist>
1744
1745 <para>Refer to &man.ifconfig.8; for further
1746 information.</para>
1747
1748 <para>The &man.wpa.supplicant.8; facility can be used to
1749 configure a wireless interface with
1750 <acronym>WEP</acronym>. The example above can be set up
1751 by adding the following lines to
1752 <filename>/etc/wpa_supplicant.conf</filename>:</para>
1753
1754 <programlisting>network={
1755 ssid="my_net"
1756 key_mgmt=NONE
1757 wep_key3=3456789012
1758 wep_tx_keyidx=3
1759 }</programlisting>
1760
1761 <para>Then:</para>
1762
1763 <screen>&prompt.root; <userinput>wpa_supplicant -i <replaceable>wlan0</replaceable> -c /etc/wpa_supplicant.conf</userinput>
1764 Trying to associate with 00:13:46:49:41:76 (SSID='dlinkap' freq=2437 MHz)
1765 Associated with 00:13:46:49:41:76</screen>
1766 </sect4>
1767 </sect3>
1768 </sect2>
1769
1770 <sect2>
1771 <title>Ad-hoc Mode</title>
1772
1773 <para><acronym>IBSS</acronym> mode, also called ad-hoc mode, is
1774 designed for point to point connections. For example, to
1775 establish an ad-hoc network between the machines
1776 <systemitem>A</systemitem> and <systemitem>B</systemitem>,
1777 choose two <acronym>IP</acronym> addresses and a
1778 <acronym>SSID</acronym>.</para>
1779
1780 <para>On <systemitem>A</systemitem>:</para>
1781
1782 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable> wlanmode adhoc</userinput>
1783 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.0.1</replaceable> netmask <replaceable>255.255.255.0</replaceable> ssid <replaceable>freebsdap</replaceable></userinput>
1784 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1785 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
1786 ether 00:11:95:c3:0d:ac
1787 inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
1788 media: IEEE 802.11 Wireless Ethernet autoselect mode 11g &lt;adhoc&gt;
1789 status: running
1790 ssid freebsdap channel 2 (2417 Mhz 11g) bssid 02:11:95:c3:0d:ac
1791 country US ecm authmode OPEN privacy OFF txpower 21.5 scanvalid 60
1792 protmode CTS wme burst</screen>
1793
1794 <para>The <literal>adhoc</literal> parameter indicates that the
1795 interface is running in <acronym>IBSS</acronym> mode.</para>
1796
1797 <para><systemitem>B</systemitem> should now be able to detect
1798 <systemitem>A</systemitem>:</para>
1799
1800 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable> wlanmode adhoc</userinput>
1801 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> up scan</userinput>
1802 SSID/MESH ID BSSID CHAN RATE S:N INT CAPS
1803 freebsdap 02:11:95:c3:0d:ac 2 54M -64:-96 100 IS WME</screen>
1804
1805 <para>The <literal>I</literal> in the output confirms that
1806 <systemitem>A</systemitem> is in ad-hoc mode. Now, configure
1807 <systemitem>B</systemitem> with a different
1808 <acronym>IP</acronym> address:</para>
1809
1810 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.0.2</replaceable> netmask <replaceable>255.255.255.0</replaceable> ssid <replaceable>freebsdap</replaceable></userinput>
1811 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1812 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
1813 ether 00:11:95:d5:43:62
1814 inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255
1815 media: IEEE 802.11 Wireless Ethernet autoselect mode 11g &lt;adhoc&gt;
1816 status: running
1817 ssid freebsdap channel 2 (2417 Mhz 11g) bssid 02:11:95:c3:0d:ac
1818 country US ecm authmode OPEN privacy OFF txpower 21.5 scanvalid 60
1819 protmode CTS wme burst</screen>
1820
1821 <para>Both <systemitem>A</systemitem> and
1822 <systemitem>B</systemitem> are now ready to exchange
1823 information.</para>
1824 </sect2>
1825
1826 <sect2 xml:id="network-wireless-ap">
1827 <title>&os; Host Access Points</title>
1828
1829 <para>&os; can act as an Access Point (<acronym>AP</acronym>)
1830 which eliminates the need to buy a hardware
1831 <acronym>AP</acronym> or run an ad-hoc network. This can
1832 be particularly useful when a &os; machine is acting as a
1833 gateway to another network such as the Internet.</para>
1834
1835 <sect3 xml:id="network-wireless-ap-basic">
1836 <title>Basic Settings</title>
1837
1838 <para>Before configuring a &os; machine as an
1839 <acronym>AP</acronym>, the kernel must be configured with
1840 the appropriate networking support for the wireless card
1841 as well as the security protocols being used. For more
1842 details, see <xref
1843 linkend="network-wireless-basic"/>.</para>
1844
1845 <note>
1846 <para>The <acronym>NDIS</acronym> driver wrapper for
1847 &windows; drivers does not currently support
1848 <acronym>AP</acronym> operation. Only native &os;
1849 wireless drivers support <acronym>AP</acronym>
1850 mode.</para>
1851 </note>
1852
1853 <para>Once wireless networking support is loaded, check if
1854 the wireless device supports the host-based access point
1855 mode, also known as hostap mode:</para>
1856
1857 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable></userinput>
1858 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> list caps</userinput>
1859 drivercaps=6f85edc1&lt;STA,FF,TURBOP,IBSS,HOSTAP,AHDEMO,TXPMGT,SHSLOT,SHPREAMBLE,MONITOR,MBSS,WPA1,WPA2,BURST,WME,WDS,BGSCAN,TXFRAG&gt;
1860 cryptocaps=1f&lt;WEP,TKIP,AES,AES_CCM,TKIPMIC&gt;</screen>
1861
1862 <para>This output displays the card's capabilities. The
1863 <literal>HOSTAP</literal> word confirms that this wireless
1864 card can act as an <acronym>AP</acronym>. Various supported
1865 ciphers are also listed: <acronym>WEP</acronym>,
1866 <acronym>TKIP</acronym>, and <acronym>AES</acronym>. This
1867 information indicates which security protocols can be used
1868 on the <acronym>AP</acronym>.</para>
1869
1870 <para>The wireless device can only be put into hostap mode
1871 during the creation of the network pseudo-device, so a
1872 previously created device must be destroyed first:</para>
1873
1874 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> destroy</userinput></screen>
1875
1876 <para>then regenerated with the correct option before setting
1877 the other parameters:</para>
1878
1879 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable> wlanmode hostap</userinput>
1880 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.0.1</replaceable> netmask <replaceable>255.255.255.0</replaceable> ssid <replaceable>freebsdap</replaceable> mode 11g channel 1</userinput></screen>
1881
1882 <para>Use &man.ifconfig.8; again to see the status of the
1883 <filename>wlan0</filename> interface:</para>
1884
1885 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1886 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
1887 ether 00:11:95:c3:0d:ac
1888 inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
1889 media: IEEE 802.11 Wireless Ethernet autoselect mode 11g &lt;hostap&gt;
1890 status: running
1891 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1892 country US ecm authmode OPEN privacy OFF txpower 21.5 scanvalid 60
1893 protmode CTS wme burst dtimperiod 1 -dfs</screen>
1894
1895 <para>The <literal>hostap</literal> parameter indicates the
1896 interface is running in the host-based access point
1897 mode.</para>
1898
1899 <para>The interface configuration can be done automatically at
1900 boot time by adding the following lines to
1901 <filename>/etc/rc.conf</filename>:</para>
1902
1903 <programlisting>wlans_ath0="wlan0"
1904 create_args_wlan0="wlanmode hostap"
1905 ifconfig_wlan0="inet <replaceable>192.168.0.1</replaceable> netmask <replaceable>255.255.255.0</replaceable> ssid <replaceable>freebsdap</replaceable> mode 11g channel <replaceable>1</replaceable>"</programlisting>
1906 </sect3>
1907
1908 <sect3>
1909 <title>Host-based Access Point Without Authentication or
1910 Encryption</title>
1911
1912 <para>Although it is not recommended to run an
1913 <acronym>AP</acronym> without any authentication or
1914 encryption, this is a simple way to check if the
1915 <acronym>AP</acronym> is working. This configuration is
1916 also important for debugging client issues.</para>
1917
1918 <para>Once the <acronym>AP</acronym> is configured, initiate
1919 a scan from another wireless machine to find the
1920 <acronym>AP</acronym>:</para>
1921
1922 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable></userinput>
1923 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> up scan</userinput>
1924 SSID/MESH ID BSSID CHAN RATE S:N INT CAPS
1925 freebsdap 00:11:95:c3:0d:ac 1 54M -66:-96 100 ES WME</screen>
1926
1927 <para>The client machine found the <acronym>AP</acronym> and
1928 can be associated with it:</para>
1929
1930 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.0.2</replaceable> netmask <replaceable>255.255.255.0</replaceable> ssid <replaceable>freebsdap</replaceable></userinput>
1931 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
1932 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
1933 ether 00:11:95:d5:43:62
1934 inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255
1935 media: IEEE 802.11 Wireless Ethernet OFDM/54Mbps mode 11g
1936 status: associated
1937 ssid freebsdap channel 1 (2412 Mhz 11g) bssid 00:11:95:c3:0d:ac
1938 country US ecm authmode OPEN privacy OFF txpower 21.5 bmiss 7
1939 scanvalid 60 bgscan bgscanintvl 300 bgscanidle 250 roam:rssi 7
1940 roam:rate 5 protmode CTS wme burst</screen>
1941 </sect3>
1942
1943 <sect3 xml:id="network-wireless-ap-wpa">
1944 <title><acronym>WPA2</acronym> Host-based Access Point</title>
1945
1946 <para>This section focuses on setting up a &os;
1947 access point using the <acronym>WPA2</acronym>
1948 security protocol. More details regarding
1949 <acronym>WPA</acronym> and the configuration of
1950 <acronym>WPA</acronym>-based wireless clients can be found
1951 in <xref linkend="network-wireless-wpa"/>.</para>
1952
1953 <para>The &man.hostapd.8; daemon is used to deal with client
1954 authentication and key management on the
1955 <acronym>WPA2</acronym>-enabled
1956 <acronym>AP</acronym>.</para>
1957
1958 <para>The following configuration operations are performed
1959 on the &os; machine acting as the <acronym>AP</acronym>.
1960 Once the <acronym>AP</acronym> is correctly working,
1961 &man.hostapd.8; can be automatically started at boot
1962 with this line in
1963 <filename>/etc/rc.conf</filename>:</para>
1964
1965 <programlisting>hostapd_enable="YES"</programlisting>
1966
1967 <para>Before trying to configure &man.hostapd.8;, first
1968 configure the basic settings introduced in <xref
1969 linkend="network-wireless-ap-basic"/>.</para>
1970
1971 <sect4>
1972 <title><acronym>WPA2-PSK</acronym></title>
1973
1974 <para><acronym>WPA2-PSK</acronym> is intended for small
1975 networks where the use of a backend authentication server
1976 is not possible or desired.</para>
1977
1978 <para>The configuration is done in
1979 <filename>/etc/hostapd.conf</filename>:</para>
1980
1981 <programlisting>interface=wlan0 <co xml:id="co-ap-wpapsk-iface"/>
1982 debug=1 <co xml:id="co-ap-wpapsk-dbug"/>
1983 ctrl_interface=/var/run/hostapd <co xml:id="co-ap-wpapsk-ciface"/>
1984 ctrl_interface_group=wheel <co xml:id="co-ap-wpapsk-cifacegrp"/>
1985 ssid=freebsdap <co xml:id="co-ap-wpapsk-ssid"/>
1986 wpa=2 <co xml:id="co-ap-wpapsk-wpa"/>
1987 wpa_passphrase=freebsdmall <co xml:id="co-ap-wpapsk-pass"/>
1988 wpa_key_mgmt=WPA-PSK <co xml:id="co-ap-wpapsk-kmgmt"/>
1989 wpa_pairwise=CCMP <co xml:id="co-ap-wpapsk-pwise"/></programlisting>
1990
1991 <calloutlist>
1992 <callout arearefs="co-ap-wpapsk-iface">
1993 <para>Wireless interface used
1994 for the access point.</para>
1995 </callout>
1996
1997 <callout arearefs="co-ap-wpapsk-dbug">
1998 <para>Level of verbosity used during the
1999 execution of &man.hostapd.8;. A value of
2000 <literal>1</literal> represents the minimal
2001 level.</para>
2002 </callout>
2003
2004 <callout arearefs="co-ap-wpapsk-ciface">
2005 <para>Pathname of the directory used by &man.hostapd.8;
2006 to store domain socket files for communication
2007 with external programs such as &man.hostapd.cli.8;.
2008 The default value is used in this example.</para>
2009 </callout>
2010
2011 <callout arearefs="co-ap-wpapsk-cifacegrp">
2012 <para>The group allowed to access the control
2013 interface files.</para>
2014 </callout>
2015
2016 <callout arearefs="co-ap-wpapsk-ssid">
2017 <para>The wireless network name, or
2018 <acronym>SSID</acronym>, that will appear in wireless
2019 scans.</para>
2020 </callout>
2021
2022 <callout arearefs="co-ap-wpapsk-wpa">
2023 <para>Enable
2024 <acronym>WPA</acronym> and specify which
2025 <acronym>WPA</acronym> authentication protocol will
2026 be required. A value of <literal>2</literal>
2027 configures the <acronym>AP</acronym> for
2028 <acronym>WPA2</acronym> and is recommended.
2029 Set to <literal>1</literal> only if the obsolete
2030 <acronym>WPA</acronym> is required.</para>
2031 </callout>
2032
2033 <callout arearefs="co-ap-wpapsk-pass">
2034 <para>ASCII passphrase for
2035 <acronym>WPA</acronym> authentication.</para>
2036
2037 <warning>
2038 <para>Always use strong passwords that are at least
2039 8 characters long and made from a rich alphabet so
2040 that they will not be easily guessed or
2041 attacked.</para>
2042 </warning>
2043 </callout>
2044
2045 <callout arearefs="co-ap-wpapsk-kmgmt">
2046 <para>The
2047 key management protocol to use. This example
2048 sets <acronym>WPA-PSK</acronym>.</para>
2049 </callout>
2050
2051 <callout arearefs="co-ap-wpapsk-pwise">
2052 <para>Encryption algorithms accepted by
2053 the access point. In this example, only
2054 the
2055 <acronym>CCMP</acronym> (<acronym>AES</acronym>)
2056 cipher is accepted. <acronym>CCMP</acronym>
2057 is an alternative to <acronym>TKIP</acronym>
2058 and is strongly preferred when possible.
2059 <acronym>TKIP</acronym> should be allowed only when
2060 there are stations incapable of using
2061 <acronym>CCMP</acronym>.</para>
2062 </callout>
2063 </calloutlist>
2064
2065 <para>The next step is to start &man.hostapd.8;:</para>
2066
2067 <screen>&prompt.root; <userinput>service hostapd forcestart</userinput></screen>
2068
2069 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
2070 wlan0: flags=8943&lt;UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
2071 ether 04:f0:21:16:8e:10
2072 inet6 fe80::6f0:21ff:fe16:8e10%wlan0 prefixlen 64 scopeid 0x9
2073 nd6 options=21&lt;PERFORMNUD,AUTO_LINKLOCAL&gt;
2074 media: IEEE 802.11 Wireless Ethernet autoselect mode 11na &lt;hostap&gt;
2075 status: running
2076 ssid No5ignal channel 36 (5180 MHz 11a ht/40+) bssid 04:f0:21:16:8e:10
2077 country US ecm authmode WPA2/802.11i privacy MIXED deftxkey 2
2078 AES-CCM 2:128-bit AES-CCM 3:128-bit txpower 17 mcastrate 6 mgmtrate 6
2079 scanvalid 60 ampdulimit 64k ampdudensity 8 shortgi wme burst
2080 dtimperiod 1 -dfs
2081 groups: wlan</screen>
2082
2083 <para>Once the <acronym>AP</acronym> is running, the
2084 clients can associate with it. See <xref
2085 linkend="network-wireless-wpa"/> for more details. It
2086 is possible to see the stations associated with the
2087 <acronym>AP</acronym> using <command>ifconfig
2088 <replaceable>wlan0</replaceable> list
2089 sta</command>.</para>
2090 </sect4>
2091 </sect3>
2092
2093 <sect3>
2094 <title><acronym>WEP</acronym> Host-based Access Point</title>
2095
2096 <para>It is not recommended to use <acronym>WEP</acronym> for
2097 setting up an <acronym>AP</acronym> since there is no
2098 authentication mechanism and the encryption is easily
2099 cracked. Some legacy wireless cards only support
2100 <acronym>WEP</acronym> and these cards will only support
2101 an <acronym>AP</acronym> without authentication or
2102 encryption.</para>
2103
2104 <para>The wireless device can now be put into hostap mode and
2105 configured with the correct <acronym>SSID</acronym> and
2106 <acronym>IP</acronym> address:</para>
2107
2108 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable> wlanmode hostap</userinput>
2109 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> inet <replaceable>192.168.0.1</replaceable> netmask <replaceable>255.255.255.0</replaceable> \
2110 ssid <replaceable>freebsdap</replaceable> wepmode on weptxkey <replaceable>3</replaceable> wepkey <replaceable>3:0x3456789012</replaceable> mode 11g</userinput></screen>
2111
2112 <itemizedlist>
2113 <listitem>
2114 <para>The <literal>weptxkey</literal> indicates which
2115 <acronym>WEP</acronym> key will be used in the
2116 transmission. This example uses the third key as key
2117 numbering starts with <literal>1</literal>. This
2118 parameter must be specified in order to encrypt the
2119 data.</para>
2120 </listitem>
2121
2122 <listitem>
2123 <para>The <literal>wepkey</literal> sets the selected
2124 <acronym>WEP</acronym> key. It should be in the format
2125 <replaceable>index:key</replaceable>. If the index is
2126 not given, key <literal>1</literal> is set. The index
2127 needs to be set when using keys other than the first
2128 key.</para>
2129 </listitem>
2130 </itemizedlist>
2131
2132 <para>Use &man.ifconfig.8; to see the status of the
2133 <filename>wlan0</filename> interface:</para>
2134
2135 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable></userinput>
2136 wlan0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
2137 ether 00:11:95:c3:0d:ac
2138 inet 192.168.0.1 netmask 0xffffff00 broadcast 192.168.0.255
2139 media: IEEE 802.11 Wireless Ethernet autoselect mode 11g &lt;hostap&gt;
2140 status: running
2141 ssid freebsdap channel 4 (2427 Mhz 11g) bssid 00:11:95:c3:0d:ac
2142 country US ecm authmode OPEN privacy ON deftxkey 3 wepkey 3:40-bit
2143 txpower 21.5 scanvalid 60 protmode CTS wme burst dtimperiod 1 -dfs</screen>
2144
2145 <para>From another wireless machine, it is now possible to
2146 initiate a scan to find the <acronym>AP</acronym>:</para>
2147
2148 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>ath0</replaceable></userinput>
2149 &prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> up scan</userinput>
2150 SSID BSSID CHAN RATE S:N INT CAPS
2151 freebsdap 00:11:95:c3:0d:ac 1 54M 22:1 100 EPS</screen>
2152
2153 <para>In this example, the client machine found the
2154 <acronym>AP</acronym> and can associate with it using the
2155 correct parameters. See <xref
2156 linkend="network-wireless-wep"/> for more details.</para>
2157 </sect3>
2158 </sect2>
2159
2160 <sect2>
2161 <title>Using Both Wired and Wireless Connections</title>
2162
2163 <para>A wired connection provides better performance and
2164 reliability, while a wireless connection provides flexibility
2165 and mobility. Laptop users typically want to roam seamlessly
2166 between the two types of connections.</para>
2167
2168 <para>On &os;, it is possible to combine two or even more
2169 network interfaces together in a <quote>failover</quote>
2170 fashion. This type of configuration uses the most preferred
2171 and available connection from a group of network interfaces,
2172 and the operating system switches automatically when the link
2173 state changes.</para>
2174
2175 <para>Link aggregation and failover is covered in <xref
2176 linkend="network-aggregation"/> and an example for using
2177 both wired and wireless connections is provided at <xref
2178 linkend="networking-lagg-wired-and-wireless"/>.</para>
2179 </sect2>
2180
2181 <sect2>
2182 <title>Troubleshooting</title>
2183
2184 <para>This section describes
2185 a number of steps to help troubleshoot common wireless
2186 networking problems.</para>
2187
2188 <itemizedlist>
2189 <listitem>
2190 <para>If the access point is not listed when scanning,
2191 check that the configuration has not limited the wireless
2192 device to a limited set of channels.</para>
2193 </listitem>
2194
2195 <listitem>
2196 <para>If the device cannot associate with an access point,
2197 verify that the configuration matches the settings on the
2198 access point. This includes the authentication scheme and
2199 any security protocols. Simplify the configuration as
2200 much as possible. If using a security protocol such as
2201 <acronym>WPA</acronym> or <acronym>WEP</acronym>,
2202 configure the access point for open authentication and
2203 no security to see if traffic will pass.</para>
2204
2205 <para>Debugging support is provided by
2206 &man.wpa.supplicant.8;. Try running this utility manually
2207 with <option>-dd</option> and look at the
2208 system logs.</para>
2209 </listitem>
2210
2211 <listitem>
2212 <para>Once the system can associate with the access point,
2213 diagnose the network configuration using tools like
2214 &man.ping.8;.</para>
2215 </listitem>
2216
2217 <listitem>
2218 <para>There are many lower-level debugging tools.
2219 Debugging messages can be enabled in the 802.11 protocol
2220 support layer using &man.wlandebug.8;.
2221 For example, to enable console messages related to
2222 scanning for access points and the 802.11 protocol
2223 handshakes required to arrange communication:</para>
2224
2225 <screen>&prompt.root; <userinput>wlandebug -i <replaceable>ath0</replaceable> +scan+auth+debug+assoc</userinput>
2226 net.wlan.0.debug: 0 =&gt; 0xc80000&lt;assoc,auth,scan&gt;</screen>
2227
2228 <para>Many useful statistics are maintained by the 802.11
2229 layer and <command>wlanstats</command>, found in <filename
2230 >/usr/src/tools/tools/net80211</filename>,
2231 will dump this information. These statistics should
2232 display all errors identified by the 802.11 layer.
2233 However, some errors are identified in the device drivers
2234 that lie below the 802.11 layer so they may not show up.
2235 To diagnose device-specific problems, refer to the
2236 drivers' documentation.</para>
2237 </listitem>
2238 </itemizedlist>
2239
2240 <para>If the above information does not help to clarify the
2241 problem, submit a problem report and include output from the
2242 above tools.</para>
2243 </sect2>
2244 </sect1>
2245
2246 <sect1 xml:id="network-usb-tethering">
2247 <info>
2248 <title>USB Tethering</title>
2249 </info>
2250
2251 <indexterm>
2252 <primary>tether</primary>
2253 </indexterm>
2254
2255 <para>Many cellphones provide the option to share their data
2256 connection over USB (often called "tethering"). This feature
2257 uses either the <acronym>RNDIS</acronym>, <acronym>CDC</acronym>
2258 or a custom &apple; &iphone;/&ipad;
2259 protocol.</para>
2260
2261 <itemizedlist>
2262 <listitem>
2263 <para>&android; devices generally use the &man.urndis.4;
2264 driver.</para>
2265 </listitem>
2266
2267 <listitem>
2268 <para>&apple; devices use the &man.ipheth.4; driver.</para>
2269 </listitem>
2270
2271 <listitem>
2272 <para>Older devices will often use the &man.cdce.4;
2273 driver.</para>
2274 </listitem>
2275 </itemizedlist>
2276
2277 <para>Before attaching a device, load the appropriate driver
2278 into the kernel:</para>
2279
2280 <screen>&prompt.root; <userinput>kldload if_urndis
2281 &prompt.root; kldload if_cdce
2282 &prompt.root; kldload if_ipheth</userinput></screen>
2283
2284 <para>Once the device is attached
2285 <literal>ue</literal><replaceable>0</replaceable> will be
2286 available for use like a normal network device. Be sure that
2287 the <quote>USB tethering</quote> option is enabled on the
2288 device.</para>
2289 </sect1>
2290
2291 <sect1 xml:id="network-bluetooth">
2292 <info>
2293 <title>Bluetooth</title>
2294
2295 <authorgroup>
2296 <author>
2297 <personname>
2298 <firstname>Pav</firstname>
2299 <surname>Lucistnik</surname>
2300 </personname>
2301 <contrib>Written by </contrib>
2302 <email>pav@FreeBSD.org</email>
2303 </author>
2304 </authorgroup>
2305 </info>
2306
2307 <indexterm>
2308 <primary>Bluetooth</primary>
2309 </indexterm>
2310
2311 <para>Bluetooth is a wireless technology for creating personal
2312 networks operating in the 2.4 GHz unlicensed band, with a
2313 range of 10 meters. Networks are usually formed ad-hoc from
2314 portable devices such as cellular phones, handhelds, and
2315 laptops. Unlike Wi-Fi wireless technology, Bluetooth offers
2316 higher level service profiles, such as
2317 <acronym>FTP</acronym>-like file servers, file pushing, voice
2318 transport, serial line emulation, and more.</para>
2319
2320 <para>This section describes the use of a <acronym>USB</acronym>
2321 Bluetooth dongle on a &os; system. It then describes the
2322 various Bluetooth protocols and utilities.</para>
2323
2324 <sect2>
2325 <title>Loading Bluetooth Support</title>
2326
2327 <para>The Bluetooth stack in &os; is implemented using the
2328 &man.netgraph.4; framework. A broad variety of Bluetooth
2329 <acronym>USB</acronym> dongles is supported by &man.ng.ubt.4;.
2330 Broadcom BCM2033 based Bluetooth devices are supported by the
2331 &man.ubtbcmfw.4; and &man.ng.ubt.4; drivers. The 3Com
2332 Bluetooth PC Card 3CRWB60-A is supported by the
2333 &man.ng.bt3c.4; driver. Serial and UART based Bluetooth
2334 devices are supported by &man.sio.4;, &man.ng.h4.4;, and
2335 &man.hcseriald.8;.</para>
2336
2337 <para>Before attaching a device, determine which of the above
2338 drivers it uses, then load the driver. For example, if the
2339 device uses the &man.ng.ubt.4; driver:</para>
2340
2341 <screen>&prompt.root; <userinput>kldload ng_ubt</userinput></screen>
2342
2343 <para>If the Bluetooth device will be attached to the system
2344 during system startup, the system can be configured to load
2345 the module at boot time by adding the driver to
2346 <filename>/boot/loader.conf</filename>:</para>
2347
2348 <programlisting>ng_ubt_load="YES"</programlisting>
2349
2350 <para>Once the driver is loaded, plug in the
2351 <acronym>USB</acronym> dongle. If the driver load was
2352 successful, output similar to the following should appear on
2353 the console and in
2354 <filename>/var/log/messages</filename>:</para>
2355
2356 <screen>ubt0: vendor 0x0a12 product 0x0001, rev 1.10/5.25, addr 2
2357 ubt0: Interface 0 endpoints: interrupt=0x81, bulk-in=0x82, bulk-out=0x2
2358 ubt0: Interface 1 (alt.config 5) endpoints: isoc-in=0x83, isoc-out=0x3,
2359 wMaxPacketSize=49, nframes=6, buffer size=294</screen>
2360
2361 <para>To start and stop the Bluetooth stack, use its startup
2362 script. It is a good idea to stop the stack before unplugging
2363 the device. When starting the stack, the output should be
2364 similar to the following:</para>
2365
2366 <screen>&prompt.root; <userinput>service bluetooth start ubt0</userinput>
2367 BD_ADDR: 00:02:72:00:d4:1a
2368 Features: 0xff 0xff 0xf 00 00 00 00 00
2369 &lt;3-Slot&gt; &lt;5-Slot&gt; &lt;Encryption&gt; &lt;Slot offset&gt;
2370 &lt;Timing accuracy&gt; &lt;Switch&gt; &lt;Hold mode&gt; &lt;Sniff mode&gt;
2371 &lt;Park mode&gt; &lt;RSSI&gt; &lt;Channel quality&gt; &lt;SCO link&gt;
2372 &lt;HV2 packets&gt; &lt;HV3 packets&gt; &lt;u-law log&gt; &lt;A-law log&gt; &lt;CVSD&gt;
2373 &lt;Paging scheme&gt; &lt;Power control&gt; &lt;Transparent SCO data&gt;
2374 Max. ACL packet size: 192 bytes
2375 Number of ACL packets: 8
2376 Max. SCO packet size: 64 bytes
2377 Number of SCO packets: 8</screen>
2378 </sect2>
2379
2380 <sect2>
2381 <title>Finding Other Bluetooth Devices</title>
2382
2383 <indexterm>
2384 <primary>HCI</primary>
2385 </indexterm>
2386
2387 <para>The Host Controller Interface (<acronym>HCI</acronym>)
2388 provides a uniform method for accessing Bluetooth baseband
2389 capabilities. In &os;, a netgraph <acronym>HCI</acronym> node
2390 is created for each Bluetooth device. For more details, refer
2391 to &man.ng.hci.4;.</para>
2392
2393 <para>One of the most common tasks is discovery of Bluetooth
2394 devices within <acronym>RF</acronym> proximity. This
2395 operation is called <emphasis>inquiry</emphasis>. Inquiry and
2396 other <acronym>HCI</acronym> related operations are done using
2397 &man.hccontrol.8;. The example below shows how to find out
2398 which Bluetooth devices are in range. The list of devices
2399 should be displayed in a few seconds. Note that a remote
2400 device will only answer the inquiry if it is set to
2401 <emphasis>discoverable</emphasis> mode.</para>
2402
2403 <screen>&prompt.user; <userinput>hccontrol -n ubt0hci inquiry</userinput>
2404 Inquiry result, num_responses=1
2405 Inquiry result #0
2406 BD_ADDR: 00:80:37:29:19:a4
2407 Page Scan Rep. Mode: 0x1
2408 Page Scan Period Mode: 00
2409 Page Scan Mode: 00
2410 Class: 52:02:04
2411 Clock offset: 0x78ef
2412 Inquiry complete. Status: No error [00]</screen>
2413
2414 <para>The <literal>BD_ADDR</literal> is the unique address of a
2415 Bluetooth device, similar to the <acronym>MAC</acronym>
2416 address of a network card. This address is needed for further
2417 communication with a device and it is possible to assign a
2418 human readable name to a BD_ADDR. Information regarding the
2419 known Bluetooth hosts is contained in
2420 <filename>/etc/bluetooth/hosts</filename>. The following
2421 example shows how to obtain the human readable name that was
2422 assigned to the remote device:</para>
2423
2424 <screen>&prompt.user; <userinput>hccontrol -n ubt0hci remote_name_request 00:80:37:29:19:a4</userinput>
2425 BD_ADDR: 00:80:37:29:19:a4
2426 Name: Pav's T39</screen>
2427
2428 <para>If an inquiry is performed on a remote Bluetooth device,
2429 it will find the computer as
2430 <quote>your.host.name (ubt0)</quote>. The name assigned to
2431 the local device can be changed at any time.</para>
2432
2433 <para>The Bluetooth system provides a point-to-point connection
2434 between two Bluetooth units, or a point-to-multipoint
2435 connection which is shared among several Bluetooth devices.
2436 The following example shows how to obtain the list of active
2437 baseband connections for the local device:</para>
2438
2439 <screen>&prompt.user; <userinput>hccontrol -n ubt0hci read_connection_list</userinput>
2440 Remote BD_ADDR Handle Type Mode Role Encrypt Pending Queue State
2441 00:80:37:29:19:a4 41 ACL 0 MAST NONE 0 0 OPEN</screen>
2442
2443 <para>A <emphasis>connection handle</emphasis> is useful when
2444 termination of the baseband connection is required, though
2445 it is normally not required to do this by hand. The stack
2446 will automatically terminate inactive baseband
2447 connections.</para>
2448
2449 <screen>&prompt.root; <userinput>hccontrol -n ubt0hci disconnect 41</userinput>
2450 Connection handle: 41
2451 Reason: Connection terminated by local host [0x16]</screen>
2452
2453 <para>Type <command>hccontrol help</command> for a complete
2454 listing of available <acronym>HCI</acronym> commands. Most
2455 of the <acronym>HCI</acronym> commands do not require
2456 superuser privileges.</para>
2457 </sect2>
2458
2459 <sect2>
2460 <title>Device Pairing</title>
2461
2462 <para>By default, Bluetooth communication is not authenticated,
2463 and any device can talk to any other device. A Bluetooth
2464 device, such as a cellular phone, may choose to require
2465 authentication to provide a particular service. Bluetooth
2466 authentication is normally done with a
2467 <emphasis><acronym>PIN</acronym> code</emphasis>, an ASCII
2468 string up to 16 characters in length. The user is required
2469 to enter the same <acronym>PIN</acronym> code on both devices.
2470 Once the user has entered the <acronym>PIN</acronym> code,
2471 both devices will generate a <emphasis>link key</emphasis>.
2472 After that, the link key can be stored either in the devices
2473 or in a persistent storage. Next time, both devices will
2474 use the previously generated link key. This procedure is
2475 called <emphasis>pairing</emphasis>. Note that if the link
2476 key is lost by either device, the pairing must be
2477 repeated.</para>
2478
2479 <para>The &man.hcsecd.8; daemon is responsible for handling
2480 Bluetooth authentication requests. The default configuration
2481 file is <filename>/etc/bluetooth/hcsecd.conf</filename>. An
2482 example section for a cellular phone with the
2483 <acronym>PIN</acronym> code set to <literal>1234</literal> is
2484 shown below:</para>
2485
2486 <programlisting>device {
2487 bdaddr 00:80:37:29:19:a4;
2488 name "Pav's T39";
2489 key nokey;
2490 pin "1234";
2491 }</programlisting>
2492
2493 <para>The only limitation on <acronym>PIN</acronym> codes is
2494 length. Some devices, such as Bluetooth headsets, may have
2495 a fixed <acronym>PIN</acronym> code built in. The
2496 <option>-d</option> switch forces &man.hcsecd.8; to stay in
2497 the foreground, so it is easy to see what is happening. Set
2498 the remote device to receive pairing and initiate the
2499 Bluetooth connection to the remote device. The remote device
2500 should indicate that pairing was accepted and request the
2501 <acronym>PIN</acronym> code. Enter the same
2502 <acronym>PIN</acronym> code listed in
2503 <filename>hcsecd.conf</filename>. Now the computer and the
2504 remote device are paired. Alternatively, pairing can be
2505 initiated on the remote device.</para>
2506
2507 <para>The following line can be added to
2508 <filename>/etc/rc.conf</filename> to configure &man.hcsecd.8;
2509 to start automatically on system start:</para>
2510
2511 <programlisting>hcsecd_enable="YES"</programlisting>
2512
2513 <para>The following is a sample of the &man.hcsecd.8; daemon
2514 output:</para>
2515
2516 <programlisting>hcsecd[16484]: Got Link_Key_Request event from 'ubt0hci', remote bdaddr 0:80:37:29:19:a4
2517 hcsecd[16484]: Found matching entry, remote bdaddr 0:80:37:29:19:a4, name 'Pav's T39', link key doesn't exist
2518 hcsecd[16484]: Sending Link_Key_Negative_Reply to 'ubt0hci' for remote bdaddr 0:80:37:29:19:a4
2519 hcsecd[16484]: Got PIN_Code_Request event from 'ubt0hci', remote bdaddr 0:80:37:29:19:a4
2520 hcsecd[16484]: Found matching entry, remote bdaddr 0:80:37:29:19:a4, name 'Pav's T39', PIN code exists
2521 hcsecd[16484]: Sending PIN_Code_Reply to 'ubt0hci' for remote bdaddr 0:80:37:29:19:a4</programlisting>
2522 </sect2>
2523
2524 <sect2>
2525 <title>Network Access with
2526 <acronym>PPP</acronym> Profiles</title>
2527
2528 <para>A Dial-Up Networking (<acronym>DUN</acronym>) profile can
2529 be used to configure a cellular phone as a wireless modem for
2530 connecting to a dial-up Internet access server. It can also
2531 be used to configure a computer to receive data calls from a
2532 cellular phone.</para>
2533
2534 <para>Network access with a <acronym>PPP</acronym> profile can
2535 be used to provide <acronym>LAN</acronym> access for a single
2536 Bluetooth device or multiple Bluetooth devices. It can also
2537 provide <acronym>PC</acronym> to <acronym>PC</acronym>
2538 connection using <acronym>PPP</acronym> networking over serial
2539 cable emulation.</para>
2540
2541 <para>In &os;, these profiles are implemented with &man.ppp.8;
2542 and the &man.rfcomm.pppd.8; wrapper which converts a
2543 Bluetooth connection into something
2544 <acronym>PPP</acronym> can use. Before a profile can be used,
2545 a new <acronym>PPP</acronym> label must be created in
2546 <filename>/etc/ppp/ppp.conf</filename>. Consult
2547 &man.rfcomm.pppd.8; for examples.</para>
2548
2549 <para>In this example, &man.rfcomm.pppd.8; is used to open a
2550 connection to a remote device with a
2551 <literal>BD_ADDR</literal> of
2552 <literal>00:80:37:29:19:a4</literal> on a
2553 <acronym>DUN</acronym> <acronym>RFCOMM</acronym>
2554 channel:</para>
2555
2556 <screen>&prompt.root; <userinput>rfcomm_pppd -a 00:80:37:29:19:a4 -c -C dun -l rfcomm-dialup</userinput></screen>
2557
2558 <para>The actual channel number will be obtained from the remote
2559 device using the <acronym>SDP</acronym> protocol. It is
2560 possible to specify the <acronym>RFCOMM</acronym> channel by
2561 hand, and in this case &man.rfcomm.pppd.8; will not perform
2562 the <acronym>SDP</acronym> query. Use &man.sdpcontrol.8; to
2563 find out the <acronym>RFCOMM</acronym> channel on the remote
2564 device.</para>
2565
2566 <para>In order to provide network access with the
2567 <acronym>PPP</acronym> <acronym>LAN</acronym> service,
2568 &man.sdpd.8; must be running and a new entry for
2569 <acronym>LAN</acronym> clients must be created in
2570 <filename>/etc/ppp/ppp.conf</filename>. Consult
2571 &man.rfcomm.pppd.8; for examples. Finally, start the
2572 <acronym>RFCOMM</acronym> <acronym>PPP</acronym> server on a
2573 valid <acronym>RFCOMM</acronym> channel number. The
2574 <acronym>RFCOMM</acronym> <acronym>PPP</acronym> server will
2575 automatically register the Bluetooth <acronym>LAN</acronym>
2576 service with the local <acronym>SDP</acronym> daemon. The
2577 example below shows how to start the <acronym>RFCOMM</acronym>
2578 <acronym>PPP</acronym> server.</para>
2579
2580 <screen>&prompt.root; <userinput>rfcomm_pppd -s -C 7 -l rfcomm-server</userinput></screen>
2581 </sect2>
2582
2583 <sect2>
2584 <title>Bluetooth Protocols</title>
2585
2586 <para>This section provides an overview of the various Bluetooth
2587 protocols, their function, and associated utilities.</para>
2588
2589 <sect3>
2590 <title>Logical Link Control and Adaptation Protocol
2591 (<acronym>L2CAP</acronym>)</title>
2592
2593 <indexterm>
2594 <primary>L2CAP</primary>
2595 </indexterm>
2596
2597 <para>The Logical Link Control and Adaptation Protocol
2598 (<acronym>L2CAP</acronym>) provides connection-oriented and
2599 connectionless data services to upper layer protocols.
2600 <acronym>L2CAP</acronym> permits higher level protocols and
2601 applications to transmit and receive
2602 <acronym>L2CAP</acronym> data packets up to 64 kilobytes in
2603 length.</para>
2604
2605 <para><acronym>L2CAP</acronym> is based around the concept of
2606 <emphasis>channels</emphasis>. A channel is a logical
2607 connection on top of a baseband connection, where each
2608 channel is bound to a single protocol in a many-to-one
2609 fashion. Multiple channels can be bound to the same
2610 protocol, but a channel cannot be bound to multiple
2611 protocols. Each <acronym>L2CAP</acronym> packet received on
2612 a channel is directed to the appropriate higher level
2613 protocol. Multiple channels can share the same baseband
2614 connection.</para>
2615
2616 <para>In &os;, a netgraph <acronym>L2CAP</acronym> node is
2617 created for each Bluetooth device. This node is normally
2618 connected to the downstream Bluetooth <acronym>HCI</acronym>
2619 node and upstream Bluetooth socket nodes. The default name
2620 for the <acronym>L2CAP</acronym> node is
2621 <quote>devicel2cap</quote>. For more details refer to
2622 &man.ng.l2cap.4;.</para>
2623
2624 <para>A useful command is &man.l2ping.8;, which can be used to
2625 ping other devices. Some Bluetooth implementations might
2626 not return all of the data sent to them, so <literal>0
2627 bytes</literal> in the following example is normal.</para>
2628
2629 <screen>&prompt.root; <userinput>l2ping -a 00:80:37:29:19:a4</userinput>
2630 0 bytes from 0:80:37:29:19:a4 seq_no=0 time=48.633 ms result=0
2631 0 bytes from 0:80:37:29:19:a4 seq_no=1 time=37.551 ms result=0
2632 0 bytes from 0:80:37:29:19:a4 seq_no=2 time=28.324 ms result=0
2633 0 bytes from 0:80:37:29:19:a4 seq_no=3 time=46.150 ms result=0</screen>
2634
2635 <para>The &man.l2control.8; utility is used to perform various
2636 operations on <acronym>L2CAP</acronym> nodes. This example
2637 shows how to obtain the list of logical connections
2638 (channels) and the list of baseband connections for the
2639 local device:</para>
2640
2641 <screen>&prompt.user; <userinput>l2control -a 00:02:72:00:d4:1a read_channel_list</userinput>
2642 L2CAP channels:
2643 Remote BD_ADDR SCID/ DCID PSM IMTU/ OMTU State
2644 00:07:e0:00:0b:ca 66/ 64 3 132/ 672 OPEN
2645 &prompt.user; <userinput>l2control -a 00:02:72:00:d4:1a read_connection_list</userinput>
2646 L2CAP connections:
2647 Remote BD_ADDR Handle Flags Pending State
2648 00:07:e0:00:0b:ca 41 O 0 OPEN</screen>
2649
2650 <para>Another diagnostic tool is &man.btsockstat.1;. It is
2651 similar to &man.netstat.1;, but for Bluetooth
2652 network-related data structures. The example below shows
2653 the same logical connection as &man.l2control.8;
2654 above.</para>
2655
2656 <screen>&prompt.user; <userinput>btsockstat</userinput>
2657 Active L2CAP sockets
2658 PCB Recv-Q Send-Q Local address/PSM Foreign address CID State
2659 c2afe900 0 0 00:02:72:00:d4:1a/3 00:07:e0:00:0b:ca 66 OPEN
2660 Active RFCOMM sessions
2661 L2PCB PCB Flag MTU Out-Q DLCs State
2662 c2afe900 c2b53380 1 127 0 Yes OPEN
2663 Active RFCOMM sockets
2664 PCB Recv-Q Send-Q Local address Foreign address Chan DLCI State
2665 c2e8bc80 0 250 00:02:72:00:d4:1a 00:07:e0:00:0b:ca 3 6 OPEN</screen>
2666 </sect3>
2667
2668 <sect3>
2669 <title>Radio Frequency Communication
2670 (<acronym>RFCOMM</acronym>)</title>
2671
2672 <para>The <acronym>RFCOMM</acronym> protocol provides
2673 emulation of serial ports over the <acronym>L2CAP</acronym>
2674 protocol. <acronym>RFCOMM</acronym> is a simple transport
2675 protocol, with additional provisions for emulating the 9
2676 circuits of RS-232 (EIATIA-232-E) serial ports. It
2677 supports up to 60 simultaneous connections
2678 (<acronym>RFCOMM</acronym> channels) between two Bluetooth
2679 devices.</para>
2680
2681 <para>For the purposes of <acronym>RFCOMM</acronym>, a
2682 complete communication path involves two applications
2683 running on the communication endpoints with a communication
2684 segment between them. <acronym>RFCOMM</acronym> is intended
2685 to cover applications that make use of the serial ports of
2686 the devices in which they reside. The communication segment
2687 is a direct connect Bluetooth link from one device to
2688 another.</para>
2689
2690 <para><acronym>RFCOMM</acronym> is only concerned with the
2691 connection between the devices in the direct connect case,
2692 or between the device and a modem in the network case.
2693 <acronym>RFCOMM</acronym> can support other configurations,
2694 such as modules that communicate via Bluetooth wireless
2695 technology on one side and provide a wired interface on the
2696 other side.</para>
2697
2698 <para>In &os;, <acronym>RFCOMM</acronym> is implemented at the
2699 Bluetooth sockets layer.</para>
2700 </sect3>
2701
2702 <sect3>
2703 <title>Service Discovery Protocol
2704 (<acronym>SDP</acronym>)</title>
2705
2706 <indexterm>
2707 <primary>SDP</primary>
2708 </indexterm>
2709
2710 <para>The Service Discovery Protocol (<acronym>SDP</acronym>)
2711 provides the means for client applications to discover the
2712 existence of services provided by server applications as
2713 well as the attributes of those services. The attributes of
2714 a service include the type or class of service offered and
2715 the mechanism or protocol information needed to utilize the
2716 service.</para>
2717
2718 <para><acronym>SDP</acronym> involves communication between a
2719 <acronym>SDP</acronym> server and a <acronym>SDP</acronym>
2720 client. The server maintains a list of service records that
2721 describe the characteristics of services associated with the
2722 server. Each service record contains information about a
2723 single service. A client may retrieve information from a
2724 service record maintained by the <acronym>SDP</acronym>
2725 server by issuing a <acronym>SDP</acronym> request. If the
2726 client, or an application associated with the client,
2727 decides to use a service, it must open a separate connection
2728 to the service provider in order to utilize the service.
2729 <acronym>SDP</acronym> provides a mechanism for discovering
2730 services and their attributes, but it does not provide a
2731 mechanism for utilizing those services.</para>
2732
2733 <para>Normally, a <acronym>SDP</acronym> client searches for
2734 services based on some desired characteristics of the
2735 services. However, there are times when it is desirable to
2736 discover which types of services are described by an
2737 <acronym>SDP</acronym> server's service records without any
2738 prior information about the services. This process of
2739 looking for any offered services is called
2740 <emphasis>browsing</emphasis>.</para>
2741
2742 <para>The Bluetooth <acronym>SDP</acronym> server,
2743 &man.sdpd.8;, and command line client, &man.sdpcontrol.8;,
2744 are included in the standard &os; installation. The
2745 following example shows how to perform a
2746 <acronym>SDP</acronym> browse query.</para>
2747
2748 <screen>&prompt.user; <userinput>sdpcontrol -a 00:01:03:fc:6e:ec browse</userinput>
2749 Record Handle: 00000000
2750 Service Class ID List:
2751 Service Discovery Server (0x1000)
2752 Protocol Descriptor List:
2753 L2CAP (0x0100)
2754 Protocol specific parameter #1: u/int/uuid16 1
2755 Protocol specific parameter #2: u/int/uuid16 1
2756
2757 Record Handle: 0x00000001
2758 Service Class ID List:
2759 Browse Group Descriptor (0x1001)
2760
2761 Record Handle: 0x00000002
2762 Service Class ID List:
2763 LAN Access Using PPP (0x1102)
2764 Protocol Descriptor List:
2765 L2CAP (0x0100)
2766 RFCOMM (0x0003)
2767 Protocol specific parameter #1: u/int8/bool 1
2768 Bluetooth Profile Descriptor List:
2769 LAN Access Using PPP (0x1102) ver. 1.0</screen>
2770
2771 <para>Note that each service has a list of attributes, such
2772 as the <acronym>RFCOMM</acronym> channel. Depending on the
2773 service, the user might need to make note of some of the
2774 attributes. Some Bluetooth implementations do not support
2775 service browsing and may return an empty list. In this
2776 case, it is possible to search for the specific service.
2777 The example below shows how to search for the
2778 <acronym>OBEX</acronym> Object Push
2779 (<acronym>OPUSH</acronym>) service:</para>
2780
2781 <screen>&prompt.user; <userinput>sdpcontrol -a 00:01:03:fc:6e:ec search OPUSH</userinput></screen>
2782
2783 <para>Offering services on &os; to Bluetooth clients is done
2784 with the &man.sdpd.8; server. The following line can be
2785 added to <filename>/etc/rc.conf</filename>:</para>
2786
2787 <programlisting>sdpd_enable="YES"</programlisting>
2788
2789 <para>Then the &man.sdpd.8; daemon can be started with:</para>
2790
2791 <screen>&prompt.root; <userinput>service sdpd start</userinput></screen>
2792
2793 <para>The local server application that wants to provide a
2794 Bluetooth service to remote clients will register the
2795 service with the local <acronym>SDP</acronym> daemon. An
2796 example of such an application is &man.rfcomm.pppd.8;. Once
2797 started, it will register the Bluetooth LAN service with the
2798 local <acronym>SDP</acronym> daemon.</para>
2799
2800 <para>The list of services registered with the local
2801 <acronym>SDP</acronym> server can be obtained by issuing a
2802 <acronym>SDP</acronym> browse query via the local control
2803 channel:</para>
2804
2805 <screen>&prompt.root; <userinput>sdpcontrol -l browse</userinput></screen>
2806 </sect3>
2807
2808 <sect3>
2809 <title><acronym>OBEX</acronym> Object Push
2810 (<acronym>OPUSH</acronym>)</title>
2811
2812 <indexterm>
2813 <primary>OBEX</primary>
2814 </indexterm>
2815
2816 <para>Object Exchange (<acronym>OBEX</acronym>) is a widely
2817 used protocol for simple file transfers between mobile
2818 devices. Its main use is in infrared communication, where
2819 it is used for generic file transfers between notebooks or
2820 <acronym>PDA</acronym>s, and for sending business cards or
2821 calendar entries between cellular phones and other devices
2822 with Personal Information Manager (<acronym>PIM</acronym>)
2823 applications.</para>
2824
2825 <para>The <acronym>OBEX</acronym> server and client are
2826 implemented by <application>obexapp</application>, which can
2827 be installed using the <package>comms/obexapp</package>
2828 package or port.</para>
2829
2830 <para>The <acronym>OBEX</acronym> client is used to push
2831 and/or pull objects from the <acronym>OBEX</acronym> server.
2832 An example object is a business card or an appointment.
2833 The <acronym>OBEX</acronym> client can obtain the
2834 <acronym>RFCOMM</acronym> channel number from the remote
2835 device via <acronym>SDP</acronym>. This can be done by
2836 specifying the service name instead of the
2837 <acronym>RFCOMM</acronym> channel number. Supported service
2838 names are: <literal>IrMC</literal>, <literal>FTRN</literal>,
2839 and <literal>OPUSH</literal>. It is also possible to
2840 specify the <acronym>RFCOMM</acronym> channel as a number.
2841 Below is an example of an <acronym>OBEX</acronym> session
2842 where the device information object is pulled from the
2843 cellular phone, and a new object, the business card, is
2844 pushed into the phone's directory.</para>
2845
2846 <screen>&prompt.user; <userinput>obexapp -a 00:80:37:29:19:a4 -C IrMC</userinput>
2847 obex&gt; get telecom/devinfo.txt devinfo-t39.txt
2848 Success, response: OK, Success (0x20)
2849 obex&gt; put new.vcf
2850 Success, response: OK, Success (0x20)
2851 obex&gt; di
2852 Success, response: OK, Success (0x20)</screen>
2853
2854 <para>In order to provide the <acronym>OPUSH</acronym>
2855 service, &man.sdpd.8; must be running and a root folder,
2856 where all incoming objects will be stored, must be created.
2857 The default path to the root folder is
2858 <filename>/var/spool/obex</filename>. Finally, start the
2859 <acronym>OBEX</acronym> server on a valid
2860 <acronym>RFCOMM</acronym> channel number. The
2861 <acronym>OBEX</acronym> server will automatically register
2862 the <acronym>OPUSH</acronym> service with the local
2863 <acronym>SDP</acronym> daemon. The example below shows how
2864 to start the <acronym>OBEX</acronym> server.</para>
2865
2866 <screen>&prompt.root; <userinput>obexapp -s -C 10</userinput></screen>
2867 </sect3>
2868
2869 <sect3>
2870 <title>Serial Port Profile (<acronym>SPP</acronym>)</title>
2871
2872 <para>The Serial Port Profile (<acronym>SPP</acronym>) allows
2873 Bluetooth devices to perform serial cable emulation. This
2874 profile allows legacy applications to use Bluetooth as a
2875 cable replacement, through a virtual serial port
2876 abstraction.</para>
2877
2878 <para>In &os;, &man.rfcomm.sppd.1; implements
2879 <acronym>SPP</acronym> and a pseudo tty is used as a virtual
2880 serial port abstraction. The example below shows how to
2881 connect to a remote device's serial port service. A
2882 <acronym>RFCOMM</acronym> channel does not have to be
2883 specified as &man.rfcomm.sppd.1; can obtain it from the
2884 remote device via <acronym>SDP</acronym>. To override this,
2885 specify a <acronym>RFCOMM</acronym> channel on the command
2886 line.</para>
2887
2888 <screen>&prompt.root; <userinput>rfcomm_sppd -a 00:07:E0:00:0B:CA -t</userinput>
2889 rfcomm_sppd[94692]: Starting on /dev/pts/6...
2890 /dev/pts/6</screen>
2891
2892 <para>Once connected, the pseudo tty can be used as serial
2893 port:</para>
2894
2895 <screen>&prompt.root; <userinput>cu -l /dev/pts/6</userinput></screen>
2896
2897 <para>The pseudo tty is printed on stdout and can be read by
2898 wrapper scripts:</para>
2899
2900 <programlisting>PTS=`rfcomm_sppd -a 00:07:E0:00:0B:CA -t`
2901 cu -l $PTS</programlisting>
2902 </sect3>
2903 </sect2>
2904
2905 <sect2>
2906 <title>Troubleshooting</title>
2907
2908 <para>By default, when &os; is accepting a new connection, it
2909 tries to perform a role switch and become master. Some older
2910 Bluetooth devices which do not support role switching will not
2911 be able to connect. Since role switching is performed when a
2912 new connection is being established, it is not possible to ask
2913 the remote device if it supports role switching. However,
2914 there is a <acronym>HCI</acronym> option to disable role
2915 switching on the local side:</para>
2916
2917 <screen>&prompt.root; <userinput>hccontrol -n ubt0hci write_node_role_switch 0</userinput></screen>
2918
2919 <para>To display Bluetooth packets, use the third-party package
2920 <application>hcidump</application>, which can be installed
2921 using the <package>comms/hcidump</package> package or port.
2922 This utility is similar to &man.tcpdump.1; and can be used to
2923 display the contents of Bluetooth packets on the terminal and
2924 to dump the Bluetooth packets to a file.</para>
2925 </sect2>
2926 </sect1>
2927
2928 <sect1 xml:id="network-bridging">
2929 <info>
2930 <title>Bridging</title>
2931
2932 <authorgroup>
2933 <author>
2934 <personname>
2935 <firstname>Andrew</firstname>
2936 <surname>Thompson</surname>
2937 </personname>
2938 <contrib>Written by </contrib>
2939 </author>
2940 </authorgroup>
2941 </info>
2942
2943 <indexterm>
2944 <primary><acronym>IP</acronym> subnet</primary>
2945 </indexterm>
2946 <indexterm>
2947 <primary>bridge</primary>
2948 </indexterm>
2949
2950 <para>It is sometimes useful to divide a network, such as an
2951 Ethernet segment, into network segments without having to
2952 create <acronym>IP</acronym> subnets and use a router to connect
2953 the segments together. A device that connects two networks
2954 together in this fashion is called a
2955 <quote>bridge</quote>.</para>
2956
2957 <para>A bridge works by learning the <acronym>MAC</acronym>
2958 addresses of the devices on each of its network interfaces. It
2959 forwards traffic between networks only when the source and
2960 destination <acronym>MAC</acronym> addresses are on different
2961 networks. In many respects, a bridge is like an Ethernet switch
2962 with very few ports. A &os; system with multiple network
2963 interfaces can be configured to act as a bridge.</para>
2964
2965 <para>Bridging can be useful in the following situations:</para>
2966
2967 <variablelist>
2968 <varlistentry>
2969 <term>Connecting Networks</term>
2970 <listitem>
2971 <para>The basic operation of a bridge is to join two or more
2972 network segments. There are many reasons to use a
2973 host-based bridge instead of networking equipment, such as
2974 cabling constraints or firewalling. A bridge can also
2975 connect a wireless interface running in hostap mode to a
2976 wired network and act as an access point.</para>
2977 </listitem>
2978 </varlistentry>
2979
2980 <varlistentry>
2981 <term>Filtering/Traffic Shaping Firewall</term>
2982 <listitem>
2983 <para>A bridge can be used when firewall functionality is
2984 needed without routing or Network Address Translation
2985 (<acronym>NAT</acronym>).</para>
2986
2987 <para>An example is a small company that is connected via
2988 <acronym>DSL</acronym> or <acronym>ISDN</acronym> to an
2989 <acronym>ISP</acronym>. There are thirteen public
2990 <acronym>IP</acronym> addresses from the
2991 <acronym>ISP</acronym> and ten computers on the network.
2992 In this situation, using a router-based firewall is
2993 difficult because of subnetting issues. A bridge-based
2994 firewall can be configured without any
2995 <acronym>IP</acronym> addressing issues.</para>
2996 </listitem>
2997 </varlistentry>
2998
2999 <varlistentry>
3000 <term>Network Tap</term>
3001 <listitem>
3002 <para>A bridge can join two network segments in order to
3003 inspect all Ethernet frames that pass between them using
3004 &man.bpf.4; and &man.tcpdump.1; on the bridge interface or
3005 by sending a copy of all frames out an additional
3006 interface known as a span port.</para>
3007 </listitem>
3008 </varlistentry>
3009
3010 <varlistentry>
3011 <term>Layer 2 <acronym>VPN</acronym></term>
3012 <listitem>
3013 <para>Two Ethernet networks can be joined across an
3014 <acronym>IP</acronym> link by bridging the networks to an
3015 EtherIP tunnel or a &man.tap.4; based solution such as
3016 <application>OpenVPN</application>.</para>
3017 </listitem>
3018 </varlistentry>
3019
3020 <varlistentry>
3021 <term>Layer 2 Redundancy</term>
3022 <listitem>
3023 <para>A network can be connected together with multiple
3024 links and use the Spanning Tree Protocol
3025 (<acronym>STP</acronym>) to block redundant paths.</para>
3026 </listitem>
3027 </varlistentry>
3028 </variablelist>
3029
3030 <para>This section describes how to configure a &os; system as a
3031 bridge using &man.if.bridge.4;. A netgraph bridging driver is
3032 also available, and is described in &man.ng.bridge.4;.</para>
3033
3034 <note>
3035 <para>Packet filtering can be used with any firewall package
3036 that hooks into the &man.pfil.9; framework. The bridge can be
3037 used as a traffic shaper with &man.altq.4; or
3038 &man.dummynet.4;.</para>
3039 </note>
3040
3041 <sect2>
3042 <title>Enabling the Bridge</title>
3043
3044 <para>In &os;, &man.if.bridge.4; is a kernel module which is
3045 automatically loaded by &man.ifconfig.8; when creating a
3046 bridge interface. It is also possible to compile bridge
3047 support into a custom kernel by adding
3048 <literal>device if_bridge</literal> to the custom kernel
3049 configuration file.</para>
3050
3051 <para>The bridge is created using interface cloning. To create
3052 the bridge interface:</para>
3053
3054 <screen>&prompt.root; <userinput>ifconfig bridge create</userinput>
3055 bridge0
3056 &prompt.root; <userinput>ifconfig bridge0</userinput>
3057 bridge0: flags=8802&lt;BROADCAST,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3058 ether 96:3d:4b:f1:79:7a
3059 id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
3060 maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200
3061 root id 00:00:00:00:00:00 priority 0 ifcost 0 port 0</screen>
3062
3063 <para>When a bridge interface is created, it is automatically
3064 assigned a randomly generated Ethernet address. The
3065 <literal>maxaddr</literal> and <literal>timeout</literal>
3066 parameters control how many <acronym>MAC</acronym> addresses
3067 the bridge will keep in its forwarding table and how many
3068 seconds before each entry is removed after it is last seen.
3069 The other parameters control how <acronym>STP</acronym>
3070 operates.</para>
3071
3072 <para>Next, specify which network interfaces to add as members
3073 of the bridge. For the bridge to forward packets, all member
3074 interfaces and the bridge need to be up:</para>
3075
3076 <screen>&prompt.root; <userinput>ifconfig bridge0 addm fxp0 addm fxp1 up</userinput>
3077 &prompt.root; <userinput>ifconfig fxp0 up</userinput>
3078 &prompt.root; <userinput>ifconfig fxp1 up</userinput></screen>
3079
3080 <para>The bridge can now forward Ethernet frames between
3081 <filename>fxp0</filename> and <filename>fxp1</filename>. Add
3082 the following lines to <filename>/etc/rc.conf</filename> so
3083 the bridge is created at startup:</para>
3084
3085 <programlisting>cloned_interfaces="bridge0"
3086 ifconfig_bridge0="addm fxp0 addm fxp1 up"
3087 ifconfig_fxp0="up"
3088 ifconfig_fxp1="up"</programlisting>
3089
3090 <para>If the bridge host needs an <acronym>IP</acronym>
3091 address, set it on the bridge interface, not on the member
3092 interfaces. The address can be set statically or via
3093 <acronym>DHCP</acronym>. This example sets a static
3094 <acronym>IP</acronym> address:</para>
3095
3096 <screen>&prompt.root; <userinput>ifconfig bridge0 inet 192.168.0.1/24</userinput></screen>
3097
3098 <para>It is also possible to assign an <acronym>IPv6</acronym>
3099 address to a bridge interface. To make the changes permanent,
3100 add the addressing information to
3101 <filename>/etc/rc.conf</filename>.</para>
3102
3103 <note>
3104 <para>When packet filtering is enabled, bridged packets will
3105 pass through the filter inbound on the originating interface
3106 on the bridge interface, and outbound on the appropriate
3107 interfaces. Either stage can be disabled. When direction
3108 of the packet flow is important, it is best to firewall on
3109 the member interfaces rather than the bridge itself.</para>
3110
3111 <para>The bridge has several configurable settings for passing
3112 non-<acronym>IP</acronym> and <acronym>IP</acronym> packets,
3113 and layer2 firewalling with &man.ipfw.8;. See
3114 &man.if.bridge.4; for more information.</para>
3115 </note>
3116 </sect2>
3117
3118 <sect2>
3119 <title>Enabling Spanning Tree</title>
3120
3121 <para>For an Ethernet network to function properly, only one
3122 active path can exist between two devices. The
3123 <acronym>STP</acronym> protocol detects loops and puts
3124 redundant links into a blocked state. Should one of the
3125 active links fail, <acronym>STP</acronym> calculates a
3126 different tree and enables one of the blocked paths to restore
3127 connectivity to all points in the network.</para>
3128
3129 <para>The Rapid Spanning Tree Protocol (<acronym>RSTP</acronym>
3130 or 802.1w) provides backwards compatibility with legacy
3131 <acronym>STP</acronym>. <acronym>RSTP</acronym> provides
3132 faster convergence and exchanges information with neighboring
3133 switches to quickly transition to forwarding mode without
3134 creating loops. &os; supports <acronym>RSTP</acronym> and
3135 <acronym>STP</acronym> as operating modes, with
3136 <acronym>RSTP</acronym> being the default mode.</para>
3137
3138 <para><acronym>STP</acronym> can be enabled on member interfaces
3139 using &man.ifconfig.8;. For a bridge with
3140 <filename>fxp0</filename> and <filename>fxp1</filename> as the
3141 current interfaces, enable <acronym>STP</acronym> with:</para>
3142
3143 <screen>&prompt.root; <userinput>ifconfig bridge0 stp fxp0 stp fxp1</userinput>
3144 bridge0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3145 ether d6:cf:d5:a0:94:6d
3146 id 00:01:02:4b:d4:50 priority 32768 hellotime 2 fwddelay 15
3147 maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200
3148 root id 00:01:02:4b:d4:50 priority 32768 ifcost 0 port 0
3149 member: fxp0 flags=1c7&lt;LEARNING,DISCOVER,STP,AUTOEDGE,PTP,AUTOPTP&gt;
3150 port 3 priority 128 path cost 200000 proto rstp
3151 role designated state forwarding
3152 member: fxp1 flags=1c7&lt;LEARNING,DISCOVER,STP,AUTOEDGE,PTP,AUTOPTP&gt;
3153 port 4 priority 128 path cost 200000 proto rstp
3154 role designated state forwarding</screen>
3155
3156 <para>This bridge has a spanning tree ID of
3157 <literal>00:01:02:4b:d4:50</literal> and a priority of
3158 <literal>32768</literal>. As the <literal>root id</literal>
3159 is the same, it indicates that this is the root bridge for the
3160 tree.</para>
3161
3162 <para>Another bridge on the network also has
3163 <acronym>STP</acronym> enabled:</para>
3164
3165 <screen>bridge0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3166 ether 96:3d:4b:f1:79:7a
3167 id 00:13:d4:9a:06:7a priority 32768 hellotime 2 fwddelay 15
3168 maxage 20 holdcnt 6 proto rstp maxaddr 100 timeout 1200
3169 root id 00:01:02:4b:d4:50 priority 32768 ifcost 400000 port 4
3170 member: fxp0 flags=1c7&lt;LEARNING,DISCOVER,STP,AUTOEDGE,PTP,AUTOPTP&gt;
3171 port 4 priority 128 path cost 200000 proto rstp
3172 role root state forwarding
3173 member: fxp1 flags=1c7&lt;LEARNING,DISCOVER,STP,AUTOEDGE,PTP,AUTOPTP&gt;
3174 port 5 priority 128 path cost 200000 proto rstp
3175 role designated state forwarding</screen>
3176
3177 <para>The line <literal>root id 00:01:02:4b:d4:50 priority 32768
3178 ifcost 400000 port 4</literal> shows that the root bridge is
3179 <literal>00:01:02:4b:d4:50</literal> and has a path cost of
3180 <literal>400000</literal> from this bridge. The path to the
3181 root bridge is via <literal>port 4</literal> which is
3182 <filename>fxp0</filename>.</para>
3183 </sect2>
3184
3185 <sect2>
3186 <title>Bridge Interface Parameters</title>
3187
3188 <para>Several <command>ifconfig</command> parameters are unique
3189 to bridge interfaces. This section summarizes some common
3190 uses for these parameters. The complete list of available
3191 parameters is described in &man.ifconfig.8;.</para>
3192
3193 <variablelist>
3194 <varlistentry>
3195 <term>private</term>
3196 <listitem>
3197 <para>A private interface does not forward any traffic to
3198 any other port that is also designated as a private
3199 interface. The traffic is blocked unconditionally so no
3200 Ethernet frames will be forwarded, including
3201 <acronym>ARP</acronym> packets. If traffic needs to be
3202 selectively blocked, a firewall should be used
3203 instead.</para>
3204 </listitem>
3205 </varlistentry>
3206
3207 <varlistentry>
3208 <term>span</term>
3209 <listitem>
3210 <para>A span port transmits a copy of every Ethernet frame
3211 received by the bridge. The number of span ports
3212 configured on a bridge is unlimited, but if an
3213 interface is designated as a span port, it cannot also
3214 be used as a regular bridge port. This is most useful
3215 for snooping a bridged network passively on another host
3216 connected to one of the span ports of the bridge. For
3217 example, to send a copy of all frames out the interface
3218 named <filename>fxp4</filename>:</para>
3219
3220 <screen>&prompt.root; <userinput>ifconfig bridge0 span fxp4</userinput></screen>
3221 </listitem>
3222 </varlistentry>
3223
3224 <varlistentry>
3225 <term>sticky</term>
3226 <listitem>
3227 <para>If a bridge member interface is marked as sticky,
3228 dynamically learned address entries are treated as
3229 static entries in the forwarding cache. Sticky entries
3230 are never aged out of the cache or replaced, even if the
3231 address is seen on a different interface. This gives
3232 the benefit of static address entries without the need
3233 to pre-populate the forwarding table. Clients learned
3234 on a particular segment of the bridge cannot roam to
3235 another segment.</para>
3236
3237 <para>An example of using sticky addresses is to combine
3238 the bridge with <acronym>VLAN</acronym>s in order to
3239 isolate customer networks without wasting
3240 <acronym>IP</acronym> address space. Consider that
3241 <systemitem class="fqdomainname">CustomerA</systemitem>
3242 is on <literal>vlan100</literal>, <systemitem
3243 class="fqdomainname">CustomerB</systemitem> is on
3244 <literal>vlan101</literal>, and the bridge has the
3245 address <systemitem
3246 class="ipaddress">192.168.0.1</systemitem>:</para>
3247
3248 <screen>&prompt.root; <userinput>ifconfig bridge0 addm vlan100 sticky vlan100 addm vlan101 sticky vlan101</userinput>
3249 &prompt.root; <userinput>ifconfig bridge0 inet 192.168.0.1/24</userinput></screen>
3250
3251 <para>In this example, both clients see <systemitem
3252 class="ipaddress">192.168.0.1</systemitem> as their
3253 default gateway. Since the bridge cache is sticky, one
3254 host cannot spoof the <acronym>MAC</acronym> address of
3255 the other customer in order to intercept their
3256 traffic.</para>
3257
3258 <para>Any communication between the
3259 <acronym>VLAN</acronym>s can be blocked using a firewall
3260 or, as seen in this example, private interfaces:</para>
3261
3262 <screen>&prompt.root; <userinput>ifconfig bridge0 private vlan100 private vlan101</userinput></screen>
3263
3264 <para>The customers are completely isolated from each
3265 other and the full <systemitem
3266 class="netmask">/24</systemitem> address range can be
3267 allocated without subnetting.</para>
3268
3269 <para>The number of unique source <acronym>MAC</acronym>
3270 addresses behind an interface can be limited. Once the
3271 limit is reached, packets with unknown source addresses
3272 are dropped until an existing host cache entry expires
3273 or is removed.</para>
3274
3275 <para>The following example sets the maximum number of
3276 Ethernet devices for <systemitem
3277 class="fqdomainname">CustomerA</systemitem> on
3278 <literal>vlan100</literal> to 10:</para>
3279
3280 <screen>&prompt.root; <userinput>ifconfig bridge0 ifmaxaddr vlan100 10</userinput></screen>
3281 </listitem>
3282 </varlistentry>
3283 </variablelist>
3284
3285 <para>Bridge interfaces also support monitor mode, where the
3286 packets are discarded after &man.bpf.4; processing and are not
3287 processed or forwarded further. This can be used to
3288 multiplex the input of two or more interfaces into a single
3289 &man.bpf.4; stream. This is useful for reconstructing the
3290 traffic for network taps that transmit the RX/TX signals out
3291 through two separate interfaces. For example, to read the
3292 input from four network interfaces as one stream:</para>
3293
3294 <screen>&prompt.root; <userinput>ifconfig bridge0 addm fxp0 addm fxp1 addm fxp2 addm fxp3 monitor up</userinput>
3295 &prompt.root; <userinput>tcpdump -i bridge0</userinput></screen>
3296 </sect2>
3297
3298 <sect2>
3299 <title><acronym>SNMP</acronym> Monitoring</title>
3300
3301 <para>The bridge interface and <acronym>STP</acronym>
3302 parameters can be monitored via &man.bsnmpd.1; which is
3303 included in the &os; base system. The exported bridge
3304 <acronym>MIB</acronym>s conform to <acronym>IETF</acronym>
3305 standards so any <acronym>SNMP</acronym> client or monitoring
3306 package can be used to retrieve the data.</para>
3307
3308 <para>To enable monitoring on the bridge, uncomment this line in
3309 <filename>/etc/snmpd.config</filename> by removing the
3310 beginning <literal>#</literal> symbol:</para>
3311
3312 <programlisting>begemotSnmpdModulePath."bridge" = "/usr/lib/snmp_bridge.so"</programlisting>
3313
3314 <para>Other configuration settings, such as community names and
3315 access lists, may need to be modified in this file. See
3316 &man.bsnmpd.1; and &man.snmp.bridge.3; for more information.
3317 Once these edits are saved, add this line to
3318 <filename>/etc/rc.conf</filename>:</para>
3319
3320 <programlisting>bsnmpd_enable="YES"</programlisting>
3321
3322 <para>Then, start &man.bsnmpd.1;:</para>
3323
3324 <screen>&prompt.root; <userinput>service bsnmpd start</userinput></screen>
3325
3326 <para>The following examples use the
3327 <application>Net-SNMP</application> software
3328 (<package>net-mgmt/net-snmp</package>) to query a bridge
3329 from a client system. The
3330 <package>net-mgmt/bsnmptools</package> port can also be used.
3331 From the <acronym>SNMP</acronym> client which is running
3332 <application>Net-SNMP</application>, add the following lines
3333 to <filename>$HOME/.snmp/snmp.conf</filename> in order to
3334 import the bridge <acronym>MIB</acronym> definitions:</para>
3335
3336 <programlisting>mibdirs +/usr/share/snmp/mibs
3337 mibs +BRIDGE-MIB:RSTP-MIB:BEGEMOT-MIB:BEGEMOT-BRIDGE-MIB</programlisting>
3338
3339 <para>To monitor a single bridge using the IETF BRIDGE-MIB
3340 (RFC4188):</para>
3341
3342 <screen>&prompt.user; <userinput>snmpwalk -v 2c -c public bridge1.example.com mib-2.dot1dBridge</userinput>
3343 BRIDGE-MIB::dot1dBaseBridgeAddress.0 = STRING: 66:fb:9b:6e:5c:44
3344 BRIDGE-MIB::dot1dBaseNumPorts.0 = INTEGER: 1 ports
3345 BRIDGE-MIB::dot1dStpTimeSinceTopologyChange.0 = Timeticks: (189959) 0:31:39.59 centi-seconds
3346 BRIDGE-MIB::dot1dStpTopChanges.0 = Counter32: 2
3347 BRIDGE-MIB::dot1dStpDesignatedRoot.0 = Hex-STRING: 80 00 00 01 02 4B D4 50
3348 ...
3349 BRIDGE-MIB::dot1dStpPortState.3 = INTEGER: forwarding(5)
3350 BRIDGE-MIB::dot1dStpPortEnable.3 = INTEGER: enabled(1)
3351 BRIDGE-MIB::dot1dStpPortPathCost.3 = INTEGER: 200000
3352 BRIDGE-MIB::dot1dStpPortDesignatedRoot.3 = Hex-STRING: 80 00 00 01 02 4B D4 50
3353 BRIDGE-MIB::dot1dStpPortDesignatedCost.3 = INTEGER: 0
3354 BRIDGE-MIB::dot1dStpPortDesignatedBridge.3 = Hex-STRING: 80 00 00 01 02 4B D4 50
3355 BRIDGE-MIB::dot1dStpPortDesignatedPort.3 = Hex-STRING: 03 80
3356 BRIDGE-MIB::dot1dStpPortForwardTransitions.3 = Counter32: 1
3357 RSTP-MIB::dot1dStpVersion.0 = INTEGER: rstp(2)</screen>
3358
3359 <para>The <literal>dot1dStpTopChanges.0</literal> value is two,
3360 indicating that the <acronym>STP</acronym> bridge topology has
3361 changed twice. A topology change means that one or more links
3362 in the network have changed or failed and a new tree has been
3363 calculated. The
3364 <literal>dot1dStpTimeSinceTopologyChange.0</literal> value
3365 will show when this happened.</para>
3366
3367 <para>To monitor multiple bridge interfaces, the private
3368 BEGEMOT-BRIDGE-MIB can be used:</para>
3369
3370 <screen>&prompt.user; <userinput>snmpwalk -v 2c -c public bridge1.example.com</userinput>
3371 enterprises.fokus.begemot.begemotBridge
3372 BEGEMOT-BRIDGE-MIB::begemotBridgeBaseName."bridge0" = STRING: bridge0
3373 BEGEMOT-BRIDGE-MIB::begemotBridgeBaseName."bridge2" = STRING: bridge2
3374 BEGEMOT-BRIDGE-MIB::begemotBridgeBaseAddress."bridge0" = STRING: e:ce:3b:5a:9e:13
3375 BEGEMOT-BRIDGE-MIB::begemotBridgeBaseAddress."bridge2" = STRING: 12:5e:4d:74:d:fc
3376 BEGEMOT-BRIDGE-MIB::begemotBridgeBaseNumPorts."bridge0" = INTEGER: 1
3377 BEGEMOT-BRIDGE-MIB::begemotBridgeBaseNumPorts."bridge2" = INTEGER: 1
3378 ...
3379 BEGEMOT-BRIDGE-MIB::begemotBridgeStpTimeSinceTopologyChange."bridge0" = Timeticks: (116927) 0:19:29.27 centi-seconds
3380 BEGEMOT-BRIDGE-MIB::begemotBridgeStpTimeSinceTopologyChange."bridge2" = Timeticks: (82773) 0:13:47.73 centi-seconds
3381 BEGEMOT-BRIDGE-MIB::begemotBridgeStpTopChanges."bridge0" = Counter32: 1
3382 BEGEMOT-BRIDGE-MIB::begemotBridgeStpTopChanges."bridge2" = Counter32: 1
3383 BEGEMOT-BRIDGE-MIB::begemotBridgeStpDesignatedRoot."bridge0" = Hex-STRING: 80 00 00 40 95 30 5E 31
3384 BEGEMOT-BRIDGE-MIB::begemotBridgeStpDesignatedRoot."bridge2" = Hex-STRING: 80 00 00 50 8B B8 C6 A9</screen>
3385
3386 <para>To change the bridge interface being monitored via the
3387 <literal>mib-2.dot1dBridge</literal> subtree:</para>
3388
3389 <screen>&prompt.user; <userinput>snmpset -v 2c -c private bridge1.example.com</userinput>
3390 BEGEMOT-BRIDGE-MIB::begemotBridgeDefaultBridgeIf.0 s bridge2</screen>
3391 </sect2>
3392 </sect1>
3393
3394 <sect1 xml:id="network-aggregation">
3395 <info>
3396 <title>Link Aggregation and Failover</title>
3397
3398 <authorgroup>
3399 <author>
3400 <personname>
3401 <firstname>Andrew</firstname>
3402 <surname>Thompson</surname>
3403 </personname>
3404 <contrib>Written by </contrib>
3405 </author>
3406 </authorgroup>
3407 </info>
3408
3409 <indexterm>
3410 <primary>lagg</primary>
3411 </indexterm>
3412 <indexterm>
3413 <primary>failover</primary>
3414 </indexterm>
3415 <indexterm>
3416 <primary><acronym>FEC</acronym></primary>
3417 </indexterm>
3418 <indexterm>
3419 <primary><acronym>LACP</acronym></primary>
3420 </indexterm>
3421 <indexterm>
3422 <primary>loadbalance</primary>
3423 </indexterm>
3424 <indexterm>
3425 <primary>roundrobin</primary>
3426 </indexterm>
3427
3428 <para>&os; provides the &man.lagg.4; interface which can be used
3429 to aggregate multiple network interfaces into one virtual
3430 interface in order to provide failover and link aggregation.
3431 Failover allows traffic to continue to flow as long as at least
3432 one aggregated network interface has an established link. Link
3433 aggregation works best on switches which support
3434 <acronym>LACP</acronym>, as this protocol distributes traffic
3435 bi-directionally while responding to the failure of individual
3436 links.</para>
3437
3438 <para>The aggregation protocols supported by the lagg interface
3439 determine which ports are used for outgoing traffic and whether
3440 or not a specific port accepts incoming traffic. The following
3441 protocols are supported by &man.lagg.4;:</para>
3442
3443 <variablelist>
3444 <varlistentry>
3445 <term>failover</term>
3446 <listitem>
3447 <para>This mode sends and receives traffic only through
3448 the master port. If the master port becomes
3449 unavailable, the next active port is used. The first
3450 interface added to the virtual interface is the master
3451 port and all subsequently added interfaces are used as
3452 failover devices. If failover to a non-master port
3453 occurs, the original port becomes master once it
3454 becomes available again.</para>
3455 </listitem>
3456 </varlistentry>
3457
3458 <varlistentry>
3459 <term>fec / loadbalance</term>
3460 <listitem>
3461 <para>&cisco; Fast &etherchannel; (<acronym>FEC</acronym>)
3462 is found on older &cisco; switches. It provides a
3463 static setup and does not negotiate aggregation with the
3464 peer or exchange frames to monitor the link. If the
3465 switch supports <acronym>LACP</acronym>, that should be
3466 used instead.</para>
3467 </listitem>
3468 </varlistentry>
3469
3470 <varlistentry>
3471 <term><acronym>lacp</acronym></term>
3472 <listitem>
3473 <para>The &ieee; 802.3ad Link Aggregation Control Protocol
3474 (<acronym>LACP</acronym>) negotiates a set of
3475 aggregable links with the peer into one or more Link
3476 Aggregated Groups (<acronym>LAG</acronym>s). Each
3477 <acronym>LAG</acronym> is composed of ports of the same
3478 speed, set to full-duplex operation, and traffic is
3479 balanced across the ports in the
3480 <acronym>LAG</acronym> with the greatest total speed.
3481 Typically, there is only one <acronym>LAG</acronym>
3482 which contains all the ports. In the event of changes
3483 in physical connectivity,
3484 <acronym>LACP</acronym> will quickly converge to a new
3485 configuration.</para>
3486
3487 <para><acronym>LACP</acronym> balances outgoing traffic
3488 across the active ports based on hashed protocol header
3489 information and accepts incoming traffic from any active
3490 port. The hash includes the Ethernet source and
3491 destination address and, if available, the
3492 <acronym>VLAN</acronym> tag, and the
3493 <acronym>IPv4</acronym> or <acronym>IPv6</acronym>
3494 source and destination address.</para>
3495 </listitem>
3496 </varlistentry>
3497
3498 <varlistentry>
3499 <term>roundrobin</term>
3500 <listitem>
3501 <para>This mode distributes outgoing traffic using a
3502 round-robin scheduler through all active ports and
3503 accepts incoming traffic from any active port. Since
3504 this mode violates Ethernet frame ordering, it should be
3505 used with caution.</para>
3506 </listitem>
3507 </varlistentry>
3508 </variablelist>
3509
3510 <sect2>
3511 <title>Configuration Examples</title>
3512
3513 <para>This section demonstrates how to configure a &cisco;
3514 switch and a &os; system for <acronym>LACP</acronym> load
3515 balancing. It then shows how to configure two Ethernet
3516 interfaces in failover mode as well as how to configure
3517 failover mode between an Ethernet and a wireless
3518 interface.</para>
3519
3520 <example xml:id="networking-lacp-aggregation-cisco">
3521 <title><acronym>LACP</acronym> Aggregation with a &cisco;
3522 Switch</title>
3523
3524 <para>This example connects two &man.fxp.4; Ethernet
3525 interfaces on a &os; machine to the first two Ethernet ports
3526 on a &cisco; switch as a single load balanced and fault
3527 tolerant link. More interfaces can be added to increase
3528 throughput and fault tolerance. Replace the names of the
3529 &cisco; ports, Ethernet devices, channel group number, and
3530 <acronym>IP</acronym> address shown in the example to match
3531 the local configuration.</para>
3532
3533 <para>Frame ordering is mandatory on Ethernet links and any
3534 traffic between two stations always flows over the same
3535 physical link, limiting the maximum speed to that of one
3536 interface. The transmit algorithm attempts to use as much
3537 information as it can to distinguish different traffic flows
3538 and balance the flows across the available
3539 interfaces.</para>
3540
3541 <para>On the &cisco; switch, add the
3542 <replaceable>FastEthernet0/1</replaceable> and
3543 <replaceable>FastEthernet0/2</replaceable> interfaces to
3544 channel group <replaceable>1</replaceable>:</para>
3545
3546 <screen><userinput>interface <replaceable>FastEthernet0/1</replaceable>
3547 channel-group <replaceable>1</replaceable> mode active
3548 channel-protocol lacp</userinput>
3549 !
3550 <userinput>interface <replaceable>FastEthernet0/2</replaceable>
3551 channel-group <replaceable>1</replaceable> mode active
3552 channel-protocol lacp</userinput></screen>
3553
3554 <para>On the &os; system, create the &man.lagg.4; interface
3555 using the physical interfaces
3556 <replaceable>fxp0</replaceable> and
3557 <replaceable>fxp1</replaceable> and bring the interfaces up
3558 with an <acronym>IP</acronym> address of
3559 <replaceable>10.0.0.3/24</replaceable>:</para>
3560
3561 <screen>&prompt.root; <userinput>ifconfig <replaceable>fxp0</replaceable> up</userinput>
3562 &prompt.root; <userinput>ifconfig <replaceable>fxp1</replaceable> up</userinput>
3563 &prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal> create </userinput>
3564 &prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal> up laggproto lacp laggport <replaceable>fxp0</replaceable> laggport <replaceable>fxp1</replaceable> <replaceable>10.0.0.3/24</replaceable></userinput></screen>
3565
3566 <para>Next, verify the status of the virtual interface:</para>
3567
3568 <screen>&prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal></userinput>
3569 lagg0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3570 options=8&lt;VLAN_MTU&gt;
3571 ether 00:05:5d:71:8d:b8
3572 media: Ethernet autoselect
3573 status: active
3574 laggproto lacp
3575 laggport: fxp1 flags=1c&lt;ACTIVE,COLLECTING,DISTRIBUTING&gt;
3576 laggport: fxp0 flags=1c&lt;ACTIVE,COLLECTING,DISTRIBUTING&gt;</screen>
3577
3578 <para>Ports
3579 marked as <literal>ACTIVE</literal> are part of the
3580 <acronym>LAG</acronym> that has been negotiated with the
3581 remote switch. Traffic will be transmitted and received
3582 through these active ports. Add <option>-v</option> to the
3583 above command to view the <acronym>LAG</acronym>
3584 identifiers.</para>
3585
3586 <para>To see the port status on the &cisco; switch:</para>
3587
3588 <screen>switch# <userinput>show lacp neighbor</userinput>
3589 Flags: S - Device is requesting Slow LACPDUs
3590 F - Device is requesting Fast LACPDUs
3591 A - Device is in Active mode P - Device is in Passive mode
3592
3593 Channel group 1 neighbors
3594
3595 Partner's information:
3596
3597 LACP port Oper Port Port
3598 Port Flags Priority Dev ID Age Key Number State
3599 Fa0/1 SA 32768 0005.5d71.8db8 29s 0x146 0x3 0x3D
3600 Fa0/2 SA 32768 0005.5d71.8db8 29s 0x146 0x4 0x3D</screen>
3601
3602 <para>For more detail, type <userinput>show lacp neighbor
3603 detail</userinput>.</para>
3604
3605 <para>To retain this configuration across reboots, add the
3606 following entries to
3607 <filename>/etc/rc.conf</filename> on the &os; system:</para>
3608
3609 <programlisting>ifconfig_<replaceable>fxp0</replaceable>="up"
3610 ifconfig_<replaceable>fxp1</replaceable>="up"
3611 cloned_interfaces="<literal>lagg<replaceable>0</replaceable></literal>"
3612 ifconfig_<literal>lagg<replaceable>0</replaceable></literal>="laggproto lacp laggport <replaceable>fxp0</replaceable> laggport <replaceable>fxp1</replaceable> <replaceable>10.0.0.3/24</replaceable>"</programlisting>
3613 </example>
3614
3615 <example xml:id="networking-lagg-failover">
3616 <title>Failover Mode</title>
3617
3618 <para>Failover mode can be used to switch over to a secondary
3619 interface if the link is lost on the master interface. To
3620 configure failover, make sure that the underlying physical
3621 interfaces are up, then create the &man.lagg.4; interface.
3622 In this example, <replaceable>fxp0</replaceable> is the
3623 master interface, <replaceable>fxp1</replaceable> is the
3624 secondary interface, and the virtual interface is assigned
3625 an <acronym>IP</acronym> address of
3626 <replaceable>10.0.0.15/24</replaceable>:</para>
3627
3628 <screen>&prompt.root; <userinput>ifconfig <replaceable>fxp0</replaceable> up</userinput>
3629 &prompt.root; <userinput>ifconfig <replaceable>fxp1</replaceable> up</userinput>
3630 &prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal> create</userinput>
3631 &prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal> up laggproto failover laggport <replaceable>fxp0</replaceable> laggport <replaceable>fxp1</replaceable> <replaceable>10.0.0.15/24</replaceable></userinput></screen>
3632
3633 <para>The virtual interface should look something like
3634 this:</para>
3635
3636 <screen>&prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal></userinput>
3637 lagg0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3638 options=8&lt;VLAN_MTU&gt;
3639 ether 00:05:5d:71:8d:b8
3640 inet 10.0.0.15 netmask 0xffffff00 broadcast 10.0.0.255
3641 media: Ethernet autoselect
3642 status: active
3643 laggproto failover
3644 laggport: fxp1 flags=0&lt;&gt;
3645 laggport: fxp0 flags=5&lt;MASTER,ACTIVE&gt;</screen>
3646
3647 <para>Traffic will be transmitted and received on
3648 <replaceable>fxp0</replaceable>. If the link is lost on
3649 <replaceable>fxp0</replaceable>,
3650 <replaceable>fxp1</replaceable> will become the active link.
3651 If the link is restored on the master interface, it will
3652 once again become the active link.</para>
3653
3654 <para>To retain this configuration across reboots, add the
3655 following entries to
3656 <filename>/etc/rc.conf</filename>:</para>
3657
3658 <programlisting>ifconfig_<replaceable>fxp0</replaceable>="up"
3659 ifconfig_<replaceable>fxp1</replaceable>="up"
3660 cloned_interfaces="<literal>lagg<replaceable>0</replaceable></literal>"
3661 ifconfig_<literal>lagg<replaceable>0</replaceable></literal>="laggproto failover laggport <replaceable>fxp0</replaceable> laggport <replaceable>fxp1</replaceable> <replaceable>10.0.0.15/24</replaceable>"</programlisting>
3662 </example>
3663
3664 <example xml:id="networking-lagg-wired-and-wireless">
3665 <title>Failover Mode Between Ethernet and Wireless
3666 Interfaces</title>
3667
3668 <para>For laptop users, it is usually desirable to configure
3669 the wireless device as a secondary which is only used when
3670 the Ethernet connection is not available. With
3671 &man.lagg.4;, it is possible to configure a failover which
3672 prefers the Ethernet connection for both performance and
3673 security reasons, while maintaining the ability to transfer
3674 data over the wireless connection.</para>
3675
3676 <para>This is achieved by overriding the physical wireless
3677 interface's <acronym>MAC</acronym> address with that of the
3678 Ethernet interface.</para>
3679
3680 <para>In this example, the Ethernet interface,
3681 <replaceable>bge0</replaceable>, is the master and the
3682 wireless interface, <replaceable>wlan0</replaceable>, is
3683 the failover. The <replaceable>wlan0</replaceable> device
3684 was created from <replaceable>iwn0</replaceable> wireless
3685 interface, which will be configured with the
3686 <acronym>MAC</acronym> address of the Ethernet interface.
3687 First, determine the <acronym>MAC</acronym> address of the
3688 Ethernet interface:</para>
3689
3690 <screen>&prompt.root; <userinput>ifconfig <replaceable>bge0</replaceable></userinput>
3691 bge0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3692 options=19b&lt;RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4&gt;
3693 ether 00:21:70:da:ae:37
3694 inet6 fe80::221:70ff:feda:ae37%bge0 prefixlen 64 scopeid 0x2
3695 nd6 options=29&lt;PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL&gt;
3696 media: Ethernet autoselect (1000baseT &lt;full-duplex&gt;)
3697 status: active</screen>
3698
3699 <para>Replace <replaceable>bge0</replaceable> to match the
3700 system's Ethernet interface name. The
3701 <literal>ether</literal> line will contain the
3702 <acronym>MAC</acronym> address of the specified interface.
3703 Now, change the <acronym>MAC</acronym> address of the
3704 underlying wireless interface:</para>
3705
3706 <screen>&prompt.root; <userinput>ifconfig <replaceable>iwn0</replaceable> ether <replaceable>00:21:70:da:ae:37</replaceable></userinput></screen>
3707
3708 <para>Bring the wireless interface up, but do not set an
3709 <acronym>IP</acronym> address:</para>
3710
3711 <screen>&prompt.root; <userinput>ifconfig <replaceable>wlan0</replaceable> create wlandev <replaceable>iwn0</replaceable> ssid <replaceable>my_router</replaceable> up</userinput></screen>
3712
3713 <para>Make sure the <replaceable>bge0</replaceable> interface
3714 is up, then create the &man.lagg.4; interface with
3715 <replaceable>bge0</replaceable> as master with failover to
3716 <replaceable>wlan0</replaceable>:</para>
3717
3718 <screen>&prompt.root; <userinput>ifconfig <replaceable>bge0</replaceable> up</userinput>
3719 &prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal> create</userinput>
3720 &prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal> up laggproto failover laggport <replaceable>bge0</replaceable> laggport <replaceable>wlan0</replaceable></userinput></screen>
3721
3722 <para>The virtual interface should look something like
3723 this:</para>
3724
3725 <screen>&prompt.root; <userinput>ifconfig <literal>lagg<replaceable>0</replaceable></literal></userinput>
3726 lagg0: flags=8843&lt;UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST&gt; metric 0 mtu 1500
3727 options=8&lt;VLAN_MTU&gt;
3728 ether 00:21:70:da:ae:37
3729 media: Ethernet autoselect
3730 status: active
3731 laggproto failover
3732 laggport: wlan0 flags=0&lt;&gt;
3733 laggport: bge0 flags=5&lt;MASTER,ACTIVE&gt;</screen>
3734
3735 <para>Then, start the <acronym>DHCP</acronym> client to
3736 obtain an <acronym>IP</acronym> address:</para>
3737
3738 <screen>&prompt.root; <userinput>dhclient <literal>lagg<replaceable>0</replaceable></literal></userinput></screen>
3739
3740 <para>To retain this configuration across reboots, add the
3741 following entries to
3742 <filename>/etc/rc.conf</filename>:</para>
3743
3744 <programlisting>ifconfig_bge0="up"
3745 ifconfig_<replaceable>iwn0</replaceable>="<replaceable>ether 00:21:70:da:ae:37</replaceable>"
3746 wlans_<replaceable>iwn0</replaceable>="wlan0"
3747 ifconfig_wlan0="WPA"
3748 cloned_interfaces="<literal>lagg<replaceable>0</replaceable></literal>"
3749 ifconfig_<literal>lagg<replaceable>0</replaceable></literal>="laggproto failover laggport bge0 laggport wlan0 DHCP"</programlisting>
3750 </example>
3751 </sect2>
3752 </sect1>
3753
3754 <sect1 xml:id="network-diskless">
3755 <info>
3756 <title>Diskless Operation with <acronym>PXE</acronym></title>
3757
3758 <authorgroup>
3759 <author>
3760 <personname>
3761 <firstname>Jean-Fran&ccedil;ois</firstname>
3762 <surname>Dock&egrave;s</surname>
3763 </personname>
3764 <contrib>Updated by </contrib>
3765 </author>
3766 </authorgroup>
3767 <authorgroup>
3768 <author>
3769 <personname>
3770 <firstname>Alex</firstname>
3771 <surname>Dupre</surname>
3772 </personname>
3773 <contrib>Reorganized and enhanced by </contrib>
3774 </author>
3775 </authorgroup>
3776 </info>
3777
3778 <indexterm>
3779 <primary>diskless workstation</primary>
3780 </indexterm>
3781 <indexterm>
3782 <primary>diskless operation</primary>
3783 </indexterm>
3784
3785 <para>The &intel; Preboot eXecution Environment
3786 (<acronym>PXE</acronym>) allows an operating system to boot over
3787 the network. For example, a &os; system can boot over the
3788 network and operate without a local disk, using file systems
3789 mounted from an <acronym>NFS</acronym> server.
3790 <acronym>PXE</acronym> support is usually available in the
3791 <acronym>BIOS</acronym>. To use <acronym>PXE</acronym> when the
3792 machine starts, select the <literal>Boot from network</literal>
3793 option in the <acronym>BIOS</acronym> setup or type a function
3794 key during system initialization.</para>
3795
3796 <para>In order to provide the files needed for an operating system
3797 to boot over the network, a <acronym>PXE</acronym> setup also
3798 requires properly configured <acronym>DHCP</acronym>,
3799 <acronym>TFTP</acronym>, and <acronym>NFS</acronym> servers,
3800 where:</para>
3801
3802 <itemizedlist>
3803 <listitem>
3804 <para>Initial parameters, such as an <acronym>IP</acronym>
3805 address, executable boot filename and location, server name,
3806 and root path are obtained from the
3807 <acronym>DHCP</acronym> server.</para>
3808 </listitem>
3809
3810 <listitem>
3811 <para>The operating system loader file is booted using
3812 <acronym>TFTP</acronym>.</para>
3813 </listitem>
3814
3815 <listitem>
3816 <para>The file systems are loaded using
3817 <acronym>NFS</acronym>.</para>
3818 </listitem>
3819 </itemizedlist>
3820
3821 <para>When a computer <acronym>PXE</acronym> boots, it receives
3822 information over <acronym>DHCP</acronym> about where to obtain
3823 the initial boot loader file. After the host computer receives
3824 this information, it downloads the boot loader via
3825 <acronym>TFTP</acronym> and then executes the boot loader. In
3826 &os;, the boot loader file is
3827 <filename>/boot/pxeboot</filename>. After
3828 <filename>/boot/pxeboot</filename> executes, the &os; kernel is
3829 loaded and the rest of the &os; bootup sequence proceeds, as
3830 described in <xref linkend="boot"/>.</para>
3831
3832 <para>This section describes how to configure these services on a
3833 &os; system so that other systems can <acronym>PXE</acronym>
3834 boot into &os;. Refer to &man.diskless.8; for more
3835 information.</para>
3836
3837 <caution>
3838 <para>As described, the system providing these services is
3839 insecure. It should live in a protected area of a network and
3840 be untrusted by other hosts.</para>
3841 </caution>
3842
3843 <sect2 xml:id="network-pxe-nfs">
3844 <info>
3845 <title>Setting Up the <acronym>PXE</acronym>
3846 Environment</title>
3847
3848 <authorgroup>
3849 <author>
3850 <personname>
3851 <firstname>Craig</firstname>
3852 <surname>Rodrigues</surname>
3853 </personname>
3854 <affiliation>
3855 <address>rodrigc@FreeBSD.org</address>
3856 </affiliation>
3857 <contrib>Written by </contrib>
3858 </author>
3859 </authorgroup>
3860 </info>
3861
3862 <para>The steps shown in this section configure the built-in
3863 <acronym>NFS</acronym> and <acronym>TFTP</acronym> servers.
3864 The next section demonstrates how to install and configure the
3865 <acronym>DHCP</acronym> server. In this example, the
3866 directory which will contain the files used by
3867 <acronym>PXE</acronym> users is
3868 <filename>/b/tftpboot/FreeBSD/install</filename>. It is
3869 important that this directory exists and that the same
3870 directory name is set in both
3871 <filename>/etc/inetd.conf</filename> and
3872 <filename>/usr/local/etc/dhcpd.conf</filename>.</para>
3873
3874 <procedure>
3875 <step>
3876 <para>Create the root directory which will contain a &os;
3877 installation to be <acronym>NFS</acronym> mounted:</para>
3878
3879 <screen>&prompt.root; <userinput>export NFSROOTDIR=/b/tftpboot/FreeBSD/install</userinput>
3880 &prompt.root; <userinput>mkdir -p ${NFSROOTDIR}</userinput></screen>
3881 </step>
3882
3883 <step>
3884 <para>Enable the <acronym>NFS</acronym> server by adding
3885 this line to <filename>/etc/rc.conf</filename>:</para>
3886
3887 <programlisting>nfs_server_enable="YES"</programlisting>
3888 </step>
3889
3890 <step>
3891 <para>Export the diskless root directory via
3892 <acronym>NFS</acronym> by adding the following to
3893 <filename>/etc/exports</filename>:</para>
3894
3895 <programlisting>/b -ro -alldirs</programlisting>
3896 </step>
3897
3898 <step>
3899 <para>Start the <acronym>NFS</acronym> server:</para>
3900
3901 <screen>&prompt.root; <userinput>service nfsd start</userinput></screen>
3902 </step>
3903
3904 <step>
3905 <para>Enable &man.inetd.8; by adding the following line to
3906 <filename>/etc/rc.conf</filename>:</para>
3907
3908 <programlisting>inetd_enable="YES"</programlisting>
3909 </step>
3910
3911 <step>
3912 <para>Uncomment the following line in
3913 <filename>/etc/inetd.conf</filename> by making sure it
3914 does not start with a <literal>#</literal> symbol:</para>
3915
3916 <programlisting>tftp dgram udp wait root /usr/libexec/tftpd tftpd -l -s /b/tftpboot</programlisting>
3917
3918 <note>
3919 <para>Some <acronym>PXE</acronym> versions require the
3920 <acronym>TCP</acronym> version of
3921 <acronym>TFTP</acronym>. In this case, uncomment the
3922 second <literal>tftp</literal> line which contains
3923 <literal>stream tcp</literal>.</para>
3924 </note>
3925 </step>
3926
3927 <step>
3928 <para>Start &man.inetd.8;:</para>
3929
3930 <screen>&prompt.root; <userinput>service inetd start</userinput></screen>
3931 </step>
3932
3933 <step>
3934 <para>Rebuild the &os; kernel and userland (refer to <xref
3935 linkend="makeworld"/> for more detailed
3936 instructions):</para>
3937
3938 <screen>&prompt.root; <userinput>cd /usr/src</userinput>
3939 &prompt.root; <userinput>make buildworld</userinput>
3940 &prompt.root; <userinput>make buildkernel</userinput></screen>
3941 </step>
3942
3943 <step>
3944 <para>Install &os; into the directory mounted over
3945 <acronym>NFS</acronym>:</para>
3946
3947 <screen>&prompt.root; <userinput>make installworld DESTDIR=${NFSROOTDIR}</userinput>
3948 &prompt.root; <userinput>make installkernel DESTDIR=${NFSROOTDIR}</userinput>
3949 &prompt.root; <userinput>make distribution DESTDIR=${NFSROOTDIR}</userinput></screen>
3950 </step>
3951
3952 <step>
3953 <para>Test that the <acronym>TFTP</acronym> server works and
3954 can download the boot loader which will be obtained via
3955 <acronym>PXE</acronym>:</para>
3956
3957 <screen>&prompt.root; <userinput>tftp localhost</userinput>
3958 tftp&gt; <userinput>get FreeBSD/install/boot/pxeboot</userinput>
3959 Received 264951 bytes in 0.1 seconds</screen>
3960 </step>
3961
3962 <step>
3963 <para>Edit <filename>${NFSROOTDIR}/etc/fstab</filename> and
3964 create an entry to mount the root file system over
3965 <acronym>NFS</acronym>:</para>
3966
3967 <programlisting># Device Mountpoint FSType Options Dump Pass
3968 <replaceable>myhost.example.com</replaceable>:/b/tftpboot/FreeBSD/install / nfs ro 0 0</programlisting>
3969
3970 <para>Replace <replaceable>myhost.example.com</replaceable>
3971 with the hostname or <acronym>IP</acronym> address of the
3972 <acronym>NFS</acronym> server. In this example, the root
3973 file system is mounted read-only in order to prevent
3974 <acronym>NFS</acronym> clients from potentially deleting
3975 the contents of the root file system.</para>
3976 </step>
3977
3978 <step>
3979 <para>Set the root password in the <acronym>PXE</acronym>
3980 environment for client machines which are
3981 <acronym>PXE</acronym> booting :</para>
3982
3983 <screen>&prompt.root; <userinput>chroot ${NFSROOTDIR}</userinput>
3984 &prompt.root; <userinput>passwd</userinput></screen>
3985 </step>
3986
3987 <step>
3988 <para>If needed, enable &man.ssh.1; root logins for client
3989 machines which are <acronym>PXE</acronym> booting by
3990 editing
3991 <filename>${NFSROOTDIR}/etc/ssh/sshd_config</filename> and
3992 enabling <literal>PermitRootLogin</literal>. This option
3993 is documented in &man.sshd.config.5;.</para>
3994 </step>
3995
3996 <step>
3997 <para>Perform any other needed customizations of the
3998 <acronym>PXE</acronym> environment in
3999 <filename>${NFSROOTDIR}</filename>. These customizations
4000 could include things like installing packages or editing
4001 the password file with &man.vipw.8;.</para>
4002 </step>
4003 </procedure>
4004
4005 <para>When booting from an <acronym>NFS</acronym> root volume,
4006 <filename>/etc/rc</filename> detects the
4007 <acronym>NFS</acronym> boot and runs
4008 <filename>/etc/rc.initdiskless</filename>. In this case,
4009 <filename>/etc</filename> and <filename>/var</filename> need
4010 to be memory backed file systems so that these directories are
4011 writable but the <acronym>NFS</acronym> root directory is
4012 read-only:</para>
4013
4014 <screen>&prompt.root; <userinput>chroot ${NFSROOTDIR}</userinput>
4015 &prompt.root; <userinput>mkdir -p conf/base</userinput>
4016 &prompt.root; <userinput>tar -c -v -f conf/base/etc.cpio.gz --format cpio --gzip etc</userinput>
4017 &prompt.root; <userinput>tar -c -v -f conf/base/var.cpio.gz --format cpio --gzip var</userinput></screen>
4018
4019 <para>When the system boots, memory file systems for
4020 <filename>/etc</filename> and <filename>/var</filename> will
4021 be created and mounted and the contents of the
4022 <filename>cpio.gz</filename> files will be copied into
4023 them.</para>
4024 </sect2>
4025
4026 <sect2 xml:id="network-pxe-setting-up-dhcp">
4027 <title>Configuring the <acronym>DHCP</acronym> Server</title>
4028
4029 <indexterm>
4030 <primary>DHCP</primary>
4031 <secondary>diskless operation</secondary>
4032 </indexterm>
4033
4034 <para>The <acronym>DHCP</acronym> server does not need to be the
4035 same machine as the <acronym>TFTP</acronym> and
4036 <acronym>NFS</acronym> server, but it needs to be accessible
4037 in the network.</para>
4038
4039 <para><acronym>DHCP</acronym> is not part of the &os; base
4040 system but can be installed using the
4041 <package>net/isc-dhcp42-server</package> port or
4042 package.</para>
4043
4044 <para>Once installed, edit the configuration file,
4045 <filename>/usr/local/etc/dhcpd.conf</filename>. Configure
4046 the <literal>next-server</literal>,
4047 <literal>filename</literal>, and
4048 <literal>root-path</literal> settings as seen in this
4049 example:</para>
4050
4051 <programlisting>subnet 192.168.0.0 netmask 255.255.255.0 {
4052 range 192.168.0.2 192.168.0.3 ;
4053 option subnet-mask 255.255.255.0 ;
4054 option routers 192.168.0.1 ;
4055 option broadcast-address 192.168.0.255 ;
4056 option domain-name-servers 192.168.35.35, 192.168.35.36 ;
4057 option domain-name "example.com";
4058
4059 # IP address of TFTP server
4060 next-server <replaceable>192.168.0.1</replaceable> ;
4061
4062 # path of boot loader obtained via tftp
4063 filename "<replaceable>FreeBSD/install/boot/pxeboot</replaceable>" ;
4064
4065 # pxeboot boot loader will try to NFS mount this directory for root FS
4066 option root-path "<replaceable>192.168.0.1:/b/tftpboot/FreeBSD/install/</replaceable>" ;
4067
4068 }</programlisting>
4069
4070 <!--
4071 This option still needed?
4072 host corbieres {
4073 <para>This option tells <application>dhcpd</application>
4074 to send the value in the <literal>host</literal>
4075 declarations as the hostname for the diskless host.
4076 An alternate way would be to add an <literal>option
4077 host-name <replaceable>corbieres</replaceable></literal>
4078 inside the <literal>host</literal> declarations.</para>
4079 -->
4080
4081 <para>The <literal>next-server</literal> directive is used to
4082 specify the <acronym>IP</acronym> address of the
4083 <acronym>TFTP</acronym> server.</para>
4084
4085 <para>The <literal>filename</literal> directive defines the path
4086 to <filename>/boot/pxeboot</filename>. A relative filename is
4087 used, meaning that <filename>/b/tftpboot</filename> is not
4088 included in the path.</para>
4089
4090 <para>The <literal>root-path</literal> option defines the path
4091 to the <acronym>NFS</acronym> root file system.</para>
4092
4093 <para>Once the edits are saved, enable <acronym>DHCP</acronym>
4094 at boot time by adding the following line to
4095 <filename>/etc/rc.conf</filename>:</para>
4096
4097 <programlisting>dhcpd_enable="YES"</programlisting>
4098
4099 <para>Then start the <acronym>DHCP</acronym> service:</para>
4100
4101 <screen>&prompt.root; <userinput>service isc-dhcpd start</userinput></screen>
4102 </sect2>
4103 <!--
4104 Are these sections still needed?
4105 <sect2>
4106 <title>Preparing the Root File System</title>
4107
4108 <indexterm>
4109 <primary>diskless operation</primary>
4110 <secondary>kernel configuration</secondary>
4111 </indexterm>
4112
4113 <para>When using <acronym>PXE</acronym>, building a custom
4114 kernel with the following options is not strictly necessary.
4115 These options cause more <acronym>DHCP</acronym> requests
4116 to be issued during kernel startup, with a small risk of
4117 inconsistency between the new values and those retrieved
4118 by &man.pxeboot.8; in some special cases. The advantage
4119 is that the host name will be set. Otherwise, set the
4120 host name in a client-specific
4121 <filename>/etc/rc.conf</filename>.</para>
4122
4123 <programlisting>options BOOTP # Use BOOTP to obtain IP address/hostname
4124 options BOOTP_NFSROOT # NFS mount root file system using BOOTP info</programlisting>
4125
4126 <para>The custom kernel can also include
4127 <literal>BOOTP_NFSV3</literal>,
4128 <literal>BOOT_COMPAT</literal> and
4129 <literal>BOOTP_WIRED_TO</literal>. Refer to
4130 <filename>NOTES</filename> for descriptions of these
4131 options.</para>
4132
4133 <para>These option names are historical and slightly
4134 misleading as they actually enable indifferent use of
4135 <acronym>DHCP</acronym> and <acronym>BOOTP</acronym>
4136 inside the kernel.</para>
4137
4138 <para>Build the custom kernel, using the instructions in
4139 <xref linkend="kernelconfig"/>, and copy it to the place
4140 specified in
4141 <filename>/usr/local/etc/dhcpd.conf</filename>.</para>
4142
4143 <indexterm>
4144 <primary>root file system</primary>
4145 <secondary>diskless operation</secondary>
4146 </indexterm>
4147
4148 <para>Create a root file system for the diskless
4149 workstations in the location listed as
4150 <literal>root-path</literal> in
4151 <filename>/usr/local/etc/dhcpd.conf</filename>.</para>
4152
4153 <para>Using <command>make world</command> to populate root is
4154 quick and will install a complete virgin system, not just
4155 the root file system, into <envar>DESTDIR</envar>. Execute
4156 the following script:</para>
4157
4158 <programlisting>#!/bin/sh
4159 export DESTDIR=/data/misc/diskless
4160 mkdir -p ${DESTDIR}
4161 cd /usr/src; make buildworld &amp;&amp; make buildkernel
4162 make installworld &amp;&amp; make installkernel
4163 cd /usr/src/etc; make distribution</programlisting>
4164
4165 <para>Once done, customize
4166 <filename>/etc/rc.conf</filename> and
4167 <filename>/etc/fstab</filename> placed into
4168 <envar>DESTDIR</envar> according to the system's
4169 requirements.</para>
4170 </sect2>
4171
4172 <sect2>
4173 <title>Configuring Swap</title>
4174
4175 <para>If needed, a swap file located on the server can be
4176 accessed via <acronym>NFS</acronym>.</para>
4177
4178 <para>The kernel does not support enabling
4179 <acronym>NFS</acronym> swap at boot time. Swap must be
4180 enabled by the startup scripts, by mounting a writable
4181 file system and creating and enabling a swap file. To
4182 create a swap file:</para>
4183
4184 <screen>&prompt.root; <userinput>dd if=/dev/zero of=<replaceable>/path/to/swapfile</replaceable> bs=1k count=1 oseek=<replaceable>100000</replaceable></userinput></screen>
4185
4186 <para>To enable the swap file, add the following line to
4187 <filename>/etc/rc.conf</filename>:</para>
4188
4189 <programlisting>swapfile=<replaceable>/path/to/swapfile</replaceable></programlisting>
4190 </sect2>
4191
4192 <sect2>
4193 <title>Miscellaneous Issues</title>
4194
4195 <indexterm>
4196 <primary>diskless operation</primary>
4197 <secondary>/usr read-only</secondary>
4198 </indexterm>
4199
4200 <para>If the diskless workstation is configured to run
4201 <application>&xorg;</application> and is running with a
4202 read-only <filename>/usr</filename>, adjust the
4203 <application>XDM</application> configuration file as it puts
4204 the error log on <filename>/usr</filename> by
4205 default.</para>
4206
4207 <para>When the server for the root file system is not
4208 running &os;, create the root file system on a &os;
4209 machine, then copy it to its destination, using
4210 &man.tar.1; or &man.cpio.1;.</para>
4211
4212 <para>In this situation, there are sometimes problems with
4213 the special files in <filename>/dev</filename>, due to
4214 differing major/minor integer sizes. A solution to this
4215 problem is to export a directory from the non-&os; server,
4216 mount this directory onto a &os; machine, and use
4217 &man.devfs.5; to allocate device nodes transparently for
4218 the user.</para>
4219 </sect2>
4220 -->
4221
4222 <sect2>
4223 <title>Debugging <acronym>PXE</acronym> Problems</title>
4224
4225 <para>Once all of the services are configured and started,
4226 <acronym>PXE</acronym> clients should be able to
4227 automatically load &os; over the network. If a particular
4228 client is unable to connect, when that client machine boots
4229 up, enter the <acronym>BIOS</acronym> configuration menu and
4230 confirm that it is set to boot from the network.</para>
4231
4232 <para>This section describes some troubleshooting tips for
4233 isolating the source of the configuration problem should no
4234 clients be able to <acronym>PXE</acronym> boot.</para>
4235
4236 <procedure>
4237 <step>
4238 <para>Use the <package>net/wireshark</package> package or
4239 port to debug the network traffic involved during the
4240 <acronym>PXE</acronym> booting process, which is
4241 illustrated in the diagram below.</para>
4242
4243 <figure>
4244 <title><acronym>PXE</acronym> Booting Process with
4245 <acronym>NFS</acronym> Root Mount</title>
4246
4247 <mediaobject>
4248 <imageobjectco>
4249 <areaspec units="calspair">
4250 <area
4251 xml:id="co-pxenfs1" coords="2873,8133 3313,7266"/>
4252 <area
4253 xml:id="co-pxenfs2" coords="3519,6333 3885,5500"/>
4254 <area
4255 xml:id="co-pxenfs3" coords="4780,5866 5102,5200"/>
4256 <area
4257 xml:id="co-pxenfs4" coords="4794,4333 5102,3600"/>
4258 <area
4259 xml:id="co-pxenfs5" coords="3108,2666 3519,1800"/>
4260 </areaspec>
4261 <imageobject>
4262 <imagedata fileref="advanced-networking/pxe-nfs"/>
4263 </imageobject>
4264 <calloutlist>
4265 <callout arearefs="co-pxenfs1">
4266 <para>Client broadcasts a
4267 <literal>DHCPDISCOVER</literal> message.</para>
4268 </callout>
4269 <callout arearefs="co-pxenfs2">
4270 <para>The <acronym>DHCP</acronym> server responds
4271 with the <acronym>IP</acronym> address,
4272 <literal>next-server</literal>,
4273 <literal>filename</literal>, and
4274 <literal>root-path</literal> values.</para>
4275 </callout>
4276 <callout arearefs="co-pxenfs3">
4277 <para>The client sends a <acronym>TFTP</acronym>
4278 request to <literal>next-server</literal>,
4279 asking to retrieve
4280 <literal>filename</literal>.</para>
4281 </callout>
4282 <callout arearefs="co-pxenfs4">
4283 <para>The <acronym>TFTP</acronym> server responds
4284 and sends <literal>filename</literal> to
4285 client.</para>
4286 </callout>
4287 <callout arearefs="co-pxenfs5">
4288 <para>The client executes
4289 <literal>filename</literal>, which is
4290 &man.pxeboot.8;, which then loads the kernel.
4291 When the kernel executes, the root file system
4292 specified by <literal>root-path</literal> is
4293 mounted over <acronym>NFS</acronym>.</para>
4294 </callout>
4295 </calloutlist>
4296 </imageobjectco>
4297 </mediaobject>
4298 </figure>
4299 </step>
4300
4301 <step>
4302 <para>On the
4303 <acronym>TFTP</acronym> server, read
4304 <filename>/var/log/xferlog</filename> to ensure that
4305 <filename>pxeboot</filename> is being retrieved from
4306 the correct location. To test this example
4307 configuration:</para>
4308
4309 <screen>&prompt.root; <userinput>tftp 192.168.0.1</userinput>
4310 tftp&gt; <userinput>get FreeBSD/install/boot/pxeboot</userinput>
4311 Received 264951 bytes in 0.1 seconds</screen>
4312
4313 <para>The <literal>BUGS</literal> sections in &man.tftpd.8;
4314 and &man.tftp.1; document some limitations with
4315 <acronym>TFTP</acronym>.</para>
4316 </step>
4317
4318 <step>
4319 <para>Make sure that the root file system can be mounted
4320 via <acronym>NFS</acronym>. To test this example
4321 configuration:</para>
4322
4323 <screen>&prompt.root; <userinput>mount -t nfs 192.168.0.1:/b/tftpboot/FreeBSD/install /mnt</userinput></screen>
4324 </step>
4325 </procedure>
4326 </sect2>
4327 </sect1>
4328
4329 <sect1 xml:id="network-ipv6">
4330 <info>
4331 <title><acronym>IPv6</acronym></title>
4332
4333 <authorgroup>
4334 <author>
4335 <personname>
4336 <firstname>Aaron</firstname>
4337 <surname>Kaplan</surname>
4338 </personname>
4339 <contrib>Originally Written by </contrib>
4340 </author>
4341 </authorgroup>
4342 <authorgroup>
4343 <author>
4344 <personname>
4345 <firstname>Tom</firstname>
4346 <surname>Rhodes</surname>
4347 </personname>
4348 <contrib>Restructured and Added by </contrib>
4349 </author>
4350 </authorgroup>
4351 <authorgroup>
4352 <author>
4353 <personname>
4354 <firstname>Brad</firstname>
4355 <surname>Davis</surname>
4356 </personname>
4357 <contrib>Extended by </contrib>
4358 </author>
4359 </authorgroup>
4360 </info>
4361
4362 <para><acronym>IPv6</acronym> is the new version of the well known
4363 <acronym>IP</acronym> protocol, also known as
4364 <acronym>IPv4</acronym>. <acronym>IPv6</acronym> provides
4365 several advantages over <acronym>IPv4</acronym> as well as many
4366 new features:</para>
4367
4368 <itemizedlist>
4369 <listitem>
4370 <para>Its 128-bit address space allows for
4371 340,282,366,920,938,463,463,374,607,431,768,211,456
4372 addresses. This addresses the <acronym>IPv4</acronym>
4373 address shortage and eventual <acronym>IPv4</acronym>
4374 address exhaustion.</para>
4375 </listitem>
4376
4377 <listitem>
4378 <para>Routers only store network aggregation addresses in
4379 their routing tables, thus reducing the average space of a
4380 routing table to 8192 entries. This addresses the
4381 scalability issues associated with <acronym>IPv4</acronym>,
4382 which required every allocated block of
4383 <acronym>IPv4</acronym> addresses to be exchanged between
4384 Internet routers, causing their routing tables to become too
4385 large to allow efficient routing.</para>
4386 </listitem>
4387 </itemizedlist>
4388
4389 <itemizedlist>
4390 <listitem>
4391 <para>Address autoconfiguration (<link
4392 xlink:href="http://www.ietf.org/rfc/rfc2462.txt">RFC2462</link>).</para>
4393 </listitem>
4394
4395 <listitem>
4396 <para>Mandatory multicast addresses.</para>
4397 </listitem>
4398
4399 <listitem>
4400 <para>Built-in <acronym>IPsec</acronym> (<acronym>IP</acronym>
4401 security).</para>
4402 </listitem>
4403
4404 <listitem>
4405 <para>Simplified header structure.</para>
4406 </listitem>
4407
4408 <listitem>
4409 <para>Support for mobile <acronym>IP</acronym>.</para>
4410 </listitem>
4411
4412 <listitem>
4413 <para><acronym>IPv6</acronym>-to-<acronym>IPv4</acronym>
4414 transition mechanisms.</para>
4415 </listitem>
4416 </itemizedlist>
4417
4418 <para>&os; includes the <link
4419 xlink:href="http://www.kame.net/">http://www.kame.net/</link>
4420 <acronym>IPv6</acronym> reference implementation and comes
4421 with everything needed to use <acronym>IPv6</acronym>. This
4422 section focuses on getting <acronym>IPv6</acronym> configured
4423 and running.</para>
4424
4425 <sect2>
4426 <title>Background on <acronym>IPv6</acronym> Addresses</title>
4427
4428 <para>There are three different types of <acronym>IPv6</acronym>
4429 addresses:</para>
4430
4431 <variablelist>
4432 <varlistentry>
4433 <term>Unicast</term>
4434 <listitem>
4435 <para>A packet sent to a unicast address arrives at the
4436 interface belonging to the address.</para>
4437 </listitem>
4438 </varlistentry>
4439
4440 <varlistentry>
4441 <term>Anycast</term>
4442 <listitem>
4443 <para>These addresses are syntactically indistinguishable
4444 from unicast addresses but they address a group of
4445 interfaces. The packet destined for an anycast address
4446 will arrive at the nearest router interface. Anycast
4447 addresses are only used by routers.</para>
4448 </listitem>
4449 </varlistentry>
4450
4451 <varlistentry>
4452 <term>Multicast</term>
4453 <listitem>
4454 <para>These addresses identify a group of interfaces. A
4455 packet destined for a multicast address will arrive at
4456 all interfaces belonging to the multicast group. The
4457 <acronym>IPv4</acronym> broadcast address, usually
4458 <systemitem
4459 class="ipaddress">xxx.xxx.xxx.255</systemitem>, is
4460 expressed by multicast addresses in
4461 <acronym>IPv6</acronym>.</para>
4462 </listitem>
4463 </varlistentry>
4464 </variablelist>
4465
4466 <para>When reading an <acronym>IPv6</acronym> address, the
4467 canonical form is represented as
4468 <systemitem>x:x:x:x:x:x:x:x</systemitem>, where each
4469 <literal>x</literal> represents a 16 bit hex value. An
4470 example is
4471 <systemitem>FEBC:A574:382B:23C1:AA49:4592:4EFE:9982</systemitem>.</para>
4472
4473 <para>Often, an address will have long substrings of all zeros.
4474 A <literal>::</literal> (double colon) can be used to replace
4475 one substring per address. Also, up to three leading
4476 <literal>0</literal>s per hex value can be omitted. For
4477 example, <systemitem>fe80::1</systemitem> corresponds to the
4478 canonical form
4479 <systemitem>fe80:0000:0000:0000:0000:0000:0000:0001</systemitem>.</para>
4480
4481 <para>A third form is to write the last 32 bits using the well
4482 known <acronym>IPv4</acronym> notation. For example,
4483 <systemitem>2002::10.0.0.1</systemitem> corresponds to the
4484 hexadecimal canonical representation
4485 <systemitem>2002:0000:0000:0000:0000:0000:0a00:0001</systemitem>,
4486 which in turn is equivalent to
4487 <systemitem>2002::a00:1</systemitem>.</para>
4488
4489 <para>To view a &os; system's <acronym>IPv6 </acronym> address,
4490 use &man.ifconfig.8;:</para>
4491
4492 <screen>&prompt.root; <userinput>ifconfig</userinput></screen>
4493
4494 <programlisting>rl0: flags=8943&lt;UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST&gt; mtu 1500
4495 inet 10.0.0.10 netmask 0xffffff00 broadcast 10.0.0.255
4496 inet6 fe80::200:21ff:fe03:8e1%rl0 prefixlen 64 scopeid 0x1
4497 ether 00:00:21:03:08:e1
4498 media: Ethernet autoselect (100baseTX )
4499 status: active</programlisting>
4500
4501 <para>In this example, the <filename>rl0</filename> interface is
4502 using <systemitem>fe80::200:21ff:fe03:8e1%rl0</systemitem>, an
4503 auto-configured link-local address which was automatically
4504 generated from the <acronym>MAC</acronym> address.</para>
4505
4506 <para>Some <acronym>IPv6</acronym> addresses are reserved. A
4507 summary of these reserved addresses is seen in <xref
4508 linkend="reservedip6"/>:</para>
4509
4510 <table xml:id="reservedip6" frame="none">
4511 <title>Reserved <acronym>IPv6</acronym> Addresses</title>
4512
4513 <tgroup cols="4">
4514 <thead>
4515 <row>
4516 <entry><acronym>IPv6</acronym> address</entry>
4517 <entry>Prefixlength (Bits)</entry>
4518 <entry>Description</entry>
4519 <entry>Notes</entry>
4520 </row>
4521 </thead>
4522
4523 <tbody>
4524 <row>
4525 <entry><systemitem>::</systemitem></entry>
4526 <entry>128 bits</entry>
4527 <entry>unspecified</entry>
4528 <entry>Equivalent to <systemitem
4529 class="ipaddress">0.0.0.0</systemitem> in
4530 <acronym>IPv4</acronym>.</entry>
4531 </row>
4532
4533 <row>
4534 <entry><systemitem>::1</systemitem></entry>
4535 <entry>128 bits</entry>
4536 <entry>loopback address</entry>
4537 <entry>Equivalent to <systemitem
4538 class="ipaddress">127.0.0.1</systemitem> in
4539 <acronym>IPv4</acronym>.</entry>
4540 </row>
4541
4542 <row>
4543 <entry><systemitem>::00:xx:xx:xx:xx</systemitem></entry>
4544 <entry>96 bits</entry>
4545 <entry>embedded <acronym>IPv4</acronym></entry>
4546 <entry>The lower 32 bits are the compatible
4547 <acronym>IPv4</acronym> address.</entry>
4548 </row>
4549
4550 <row>
4551 <entry><systemitem>::ff:xx:xx:xx:xx</systemitem></entry>
4552 <entry>96 bits</entry>
4553 <entry><acronym>IPv4</acronym> mapped
4554 <acronym>IPv6</acronym> address</entry>
4555 <entry>The lower 32 bits are the <acronym>IPv4</acronym>
4556 address for hosts which do not support
4557 <acronym>IPv6</acronym>.</entry>
4558 </row>
4559
4560 <row>
4561 <entry><systemitem>fe80::/10</systemitem></entry>
4562 <entry>10 bits</entry>
4563 <entry>link-local</entry>
4564 <entry>Equivalent to 169.254.0.0/16 in
4565 <acronym>IPv4</acronym>.</entry>
4566 </row>
4567
4568 <row>
4569 <entry><systemitem>fc00::/7</systemitem></entry>
4570 <entry>7 bits</entry>
4571 <entry>unique-local</entry>
4572 <entry>Unique local addresses are intended for local
4573 communication and are only routable within a set of
4574 cooperating sites.</entry>
4575 </row>
4576
4577 <row>
4578 <entry><systemitem>ff00::</systemitem></entry>
4579 <entry>8 bits</entry>
4580 <entry>multicast</entry>
4581 <entry>&nbsp;</entry>
4582 </row>
4583
4584 <row>
4585 <entry><systemitem>2000::-3fff:: </systemitem></entry>
4586 <entry>3 bits</entry>
4587 <entry>global unicast</entry>
4588 <entry>All global unicast addresses are assigned from
4589 this pool. The first 3 bits are
4590 <literal>001</literal>.</entry>
4591 </row>
4592 </tbody>
4593 </tgroup>
4594 </table>
4595
4596 <para>For further information on the structure of
4597 <acronym>IPv6</acronym> addresses, refer to <link
4598 xlink:href="http://www.ietf.org/rfc/rfc3513.txt">RFC3513</link>.</para>
4599 </sect2>
4600
4601 <sect2>
4602 <title>Configuring <acronym>IPv6</acronym></title>
4603
4604 <para>To configure a &os; system as an <acronym>IPv6</acronym>
4605 client, add these two lines to
4606 <filename>rc.conf</filename>:</para>
4607
4608 <programlisting>ifconfig_<replaceable>rl0</replaceable>_ipv6="inet6 accept_rtadv"
4609 rtsold_enable="YES"</programlisting>
4610
4611 <para>The first line enables the specified interface to receive
4612 router solicitation messages. The second line enables the
4613 router solicitation daemon, &man.rtsol.8;.</para>
4614
4615 <para>If the interface needs a statically assigned
4616 <acronym>IPv6</acronym> address, add an entry to specify the
4617 static address and associated prefix length:</para>
4618
4619 <programlisting>ifconfig_<replaceable>rl0</replaceable>_ipv6="inet6 <replaceable>2001:db8:4672:6565:2026:5043:2d42:5344</replaceable> prefixlen <replaceable>64</replaceable>"</programlisting>
4620
4621 <para>To assign a default router, specify its address:</para>
4622
4623 <programlisting>ipv6_defaultrouter="<replaceable>2001:db8:4672:6565::1</replaceable>"</programlisting>
4624 </sect2>
4625
4626 <sect2>
4627 <title>Connecting to a Provider</title>
4628
4629 <para>In order to connect to other <acronym>IPv6</acronym>
4630 networks, one must have a provider or a tunnel that supports
4631 <acronym>IPv6</acronym>:</para>
4632
4633 <itemizedlist>
4634 <listitem>
4635 <para>Contact an Internet Service Provider to see if they
4636 offer <acronym>IPv6</acronym>.</para>
4637 </listitem>
4638
4639 <listitem>
4640 <para><link xlink:href="http://www.sixxs.net">SixXS</link>
4641 offers tunnels with end-points all around the
4642 globe.</para>
4643 </listitem>
4644
4645 <listitem>
4646 <para><link
4647 xlink:href="http://www.tunnelbroker.net">Hurricane
4648 Electric</link> offers tunnels with end-points all
4649 around the globe.</para>
4650 </listitem>
4651 </itemizedlist>
4652
4653 <note>
4654 <para>Install the <package>net/freenet6</package> package or
4655 port for a dial-up connection.</para>
4656 </note>
4657
4658 <para>This section demonstrates how to take the directions from
4659 a tunnel provider and convert them into
4660 <filename>/etc/rc.conf</filename> settings that will persist
4661 through reboots.</para>
4662
4663 <para>The first <filename>/etc/rc.conf</filename> entry creates
4664 the generic tunneling interface
4665 <filename><replaceable>gif0</replaceable></filename>:</para>
4666
4667 <programlisting>cloned_interfaces="gif<replaceable>0</replaceable>"</programlisting>
4668
4669 <para>Next, configure that interface with the
4670 <acronym>IPv4</acronym> addresses of the local and remote
4671 endpoints. Replace <replaceable>MY_IPv4_ADDR</replaceable>
4672 and <replaceable>REMOTE_IPv4_ADDR</replaceable> with the
4673 actual <acronym>IPv4</acronym> addresses:</para>
4674
4675 <programlisting>create_args_gif0="tunnel <replaceable>MY_IPv4_ADDR REMOTE_IPv4_ADDR</replaceable>"</programlisting>
4676
4677 <para>To apply the <acronym>IPv6</acronym> address that has been
4678 assigned for use as the <acronym>IPv6</acronym> tunnel
4679 endpoint, add this line, replacing
4680 <replaceable>MY_ASSIGNED_IPv6_TUNNEL_ENDPOINT_ADDR</replaceable>
4681 with the assigned address:</para>
4682
4683 <programlisting>ifconfig_gif0_ipv6="inet6 <replaceable>MY_ASSIGNED_IPv6_TUNNEL_ENDPOINT_ADDR</replaceable>"</programlisting>
4684
4685 <para>Then, set the default route for the other side of the
4686 <acronym>IPv6</acronym> tunnel. Replace
4687 <replaceable>MY_IPv6_REMOTE_TUNNEL_ENDPOINT_ADDR</replaceable>
4688 with the default gateway address assigned by the
4689 provider:</para>
4690
4691 <programlisting>ipv6_defaultrouter="<replaceable>MY_IPv6_REMOTE_TUNNEL_ENDPOINT_ADDR</replaceable>"</programlisting>
4692
4693 <para>If the &os; system will route <acronym>IPv6</acronym>
4694 packets between the rest of the network and the world, enable
4695 the gateway using this line:</para>
4696
4697 <programlisting>ipv6_gateway_enable="YES"</programlisting>
4698 </sect2>
4699
4700 <sect2>
4701 <title>Router Advertisement and Host Auto Configuration</title>
4702
4703 <para>This section demonstrates how to setup &man.rtadvd.8; to
4704 advertise the <acronym>IPv6</acronym> default route.</para>
4705
4706 <para>To enable &man.rtadvd.8;, add the following to
4707 <filename>/etc/rc.conf</filename>:</para>
4708
4709 <programlisting>rtadvd_enable="YES"</programlisting>
4710
4711 <para>It is important to specify the interface on which to
4712 do <acronym>IPv6</acronym> router solicitation. For example,
4713 to tell &man.rtadvd.8; to use
4714 <filename>rl0</filename>:</para>
4715
4716 <programlisting>rtadvd_interfaces="rl0"</programlisting>
4717
4718 <para>Next, create the configuration file,
4719 <filename>/etc/rtadvd.conf</filename> as seen in this
4720 example:</para>
4721
4722 <programlisting>rl0:\
4723 :addrs#1:addr="2001:db8:1f11:246::":prefixlen#64:tc=ether:</programlisting>
4724
4725 <para>Replace <filename>rl0</filename> with the interface
4726 to be used and <systemitem>2001:db8:1f11:246::</systemitem>
4727 with the prefix of the allocation.</para>
4728
4729 <para>For a dedicated <systemitem
4730 class="netmask">/64</systemitem> subnet, nothing else needs
4731 to be changed. Otherwise, change the
4732 <literal>prefixlen#</literal> to the correct value.</para>
4733 </sect2>
4734
4735 <sect2>
4736 <title><acronym>IPv6</acronym> and <acronym>IPv6</acronym>
4737 Address Mapping</title>
4738
4739 <para>When <acronym>IPv6</acronym> is enabled on a server, there
4740 may be a need to enable <acronym>IPv4</acronym> mapped
4741 <acronym>IPv6</acronym> address communication. This
4742 compatibility option allows for <acronym>IPv4</acronym>
4743 addresses to be represented as <acronym>IPv6</acronym>
4744 addresses. Permitting <acronym>IPv6</acronym> applications
4745 to communicate with <acronym>IPv4</acronym> and vice versa
4746 may be a security issue.</para>
4747
4748 <para>This option may not be required in most cases and is
4749 available only for compatibility. This option will allow
4750 <acronym>IPv6</acronym>-only applications to work with
4751 <acronym>IPv4</acronym> in a dual stack environment. This
4752 is most useful for third party applications which may not
4753 support an <acronym>IPv6</acronym>-only environment. To
4754 enable this feature,
4755 add the following to <filename>/etc/rc.conf</filename>:</para>
4756
4757 <programlisting>ipv6_ipv4mapping="YES"</programlisting>
4758
4759 <para>Reviewing the information in <acronym>RFC</acronym> 3493,
4760 section 3.6 and 3.7 as well as <acronym>RFC</acronym> 4038
4761 section 4.2 may be useful to some administrators.</para>
4762 </sect2>
4763 </sect1>
4764 <!--
4765 <sect1 xml:id="network-atm">
4766 <info><title>Asynchronous Transfer Mode (<acronym>ATM</acronym>)</title>
4767 <authorgroup>
4768 <author>
4769 <personname>
4770 <firstname>Harti</firstname>
4771 <surname>Brandt</surname>
4772 </personname>
4773 <contrib>Contributed by </contrib>
4774 </author>
4775 </authorgroup>
4776 </info>
4777 <sect2>
4778 <title>Configuring Classical <acronym>IP</acronym> over
4779 <acronym>ATM</acronym></title>
4780
4781 <para>Classical <acronym>IP</acronym> over
4782 <acronym>ATM</acronym> (<acronym>CLIP</acronym>) is the
4783 simplest method to use Asynchronous Transfer Mode
4784 (<acronym>ATM</acronym>) with <acronym>IP</acronym>. It can
4785 be used with Switched Virtual Circuits
4786 (<acronym>SVC</acronym>s) and with Permanent Virtual Circuits
4787 (<acronym>PVC</acronym>s). This section describes how to
4788 set up a network based on <acronym>PVC</acronym>s.</para>
4789
4790 <sect3>
4791 <title>Fully Meshed Configurations</title>
4792
4793 <para>The first method to set up a <acronym>CLIP</acronym>
4794 with <acronym>PVC</acronym>s is to connect each machine
4795 to each other machine in the network via a dedicated
4796 <acronym>PVC</acronym>. While this is simple to
4797 configure, it becomes impractical for a large number of
4798 machines. The following example supposes four machines in
4799 the network, each connected to the <acronym role="Asynchronous Transfer Mode">ATM</acronym> network
4800 with an <acronym role="Asynchronous Transfer Mode">ATM</acronym> adapter
4801 card. The first step is the planning of the
4802 <acronym>IP</acronym> addresses and the <acronym role="Asynchronous Transfer Mode">ATM</acronym>
4803 connections between the machines. This example uses the
4804 following:</para>
4805
4806 <informaltable frame="none" pgwide="1">
4807 <tgroup cols="2">
4808 <colspec colwidth="1*"/>
4809 <colspec colwidth="1*"/>
4810 <thead>
4811 <row>
4812 <entry>Host</entry>
4813 <entry><acronym>IP</acronym> Address</entry>
4814 </row>
4815 </thead>
4816
4817 <tbody>
4818 <row>
4819 <entry><systemitem>hostA</systemitem></entry>
4820 <entry><systemitem class="ipaddress">192.168.173.1</systemitem></entry>
4821 </row>
4822
4823 <row>
4824 <entry><systemitem>hostB</systemitem></entry>
4825 <entry><systemitem class="ipaddress">192.168.173.2</systemitem></entry>
4826 </row>
4827
4828 <row>
4829 <entry><systemitem>hostC</systemitem></entry>
4830 <entry><systemitem class="ipaddress">192.168.173.3</systemitem></entry>
4831 </row>
4832
4833 <row>
4834 <entry><systemitem>hostD</systemitem></entry>
4835 <entry><systemitem class="ipaddress">192.168.173.4</systemitem></entry>
4836 </row>
4837 </tbody>
4838 </tgroup>
4839 </informaltable>
4840
4841 <para>To build a fully meshed net, one <acronym>ATM</acronym>
4842 connection is needed between each pair of machines:</para>
4843
4844 <informaltable frame="none" pgwide="1">
4845 <tgroup cols="2">
4846 <colspec colwidth="1*"/>
4847 <colspec colwidth="1*"/>
4848 <thead>
4849 <row>
4850 <entry>Machines</entry>
4851 <entry>VPI.VCI couple</entry>
4852 </row>
4853 </thead>
4854
4855 <tbody>
4856 <row>
4857 <entry><systemitem>hostA</systemitem> -
4858 <systemitem>hostB</systemitem></entry>
4859 <entry>0.100</entry>
4860 </row>
4861
4862 <row>
4863 <entry><systemitem>hostA</systemitem> -
4864 <systemitem>hostC</systemitem></entry>
4865 <entry>0.101</entry>
4866 </row>
4867
4868 <row>
4869 <entry><systemitem>hostA</systemitem> -
4870 <systemitem>hostD</systemitem></entry>
4871 <entry>0.102</entry>
4872 </row>
4873
4874 <row>
4875 <entry><systemitem>hostB</systemitem> -
4876 <systemitem>hostC</systemitem></entry>
4877 <entry>0.103</entry>
4878 </row>
4879
4880 <row>
4881 <entry><systemitem>hostB</systemitem> -
4882 <systemitem>hostD</systemitem></entry>
4883 <entry>0.104</entry>
4884 </row>
4885
4886 <row>
4887 <entry><systemitem>hostC</systemitem> -
4888 <systemitem>hostD</systemitem></entry>
4889 <entry>0.105</entry>
4890 </row>
4891 </tbody>
4892 </tgroup>
4893 </informaltable>
4894
4895 <para>The Virtual Path Identifier <acronym>VPI</acronym> and
4896 Virtual Channel Identifier <acronym>VCI</acronym> values
4897 at each end of the connection may differ, but for
4898 simplicity, this example assumes they are the same. Next,
4899 configure the <acronym>ATM</acronym> interfaces on each
4900 host:</para>
4901
4902 <screen>hostA&prompt.root; <userinput>ifconfig hatm0 192.168.173.1 up</userinput>
4903 hostB&prompt.root; <userinput>ifconfig hatm0 192.168.173.2 up</userinput>
4904 hostC&prompt.root; <userinput>ifconfig hatm0 192.168.173.3 up</userinput>
4905 hostD&prompt.root; <userinput>ifconfig hatm0 192.168.173.4 up</userinput></screen>
4906
4907 <para>This example assumes that the <acronym>ATM</acronym>
4908 interface is <filename>hatm0</filename> on all hosts.
4909 Next, the <acronym>PVC</acronym>s need to be configured on
4910 <systemitem>hostA</systemitem>. This should already be
4911 configured on the <acronym>ATM</acronym> switch; consult the
4912 manual for the switch on how to do this.</para>
4913
4914 <screen>hostA&prompt.root; <userinput>atmconfig natm add 192.168.173.2 hatm0 0 100 llc/snap ubr</userinput>
4915 hostA&prompt.root; <userinput>atmconfig natm add 192.168.173.3 hatm0 0 101 llc/snap ubr</userinput>
4916 hostA&prompt.root; <userinput>atmconfig natm add 192.168.173.4 hatm0 0 102 llc/snap ubr</userinput>
4917
4918 hostB&prompt.root; <userinput>atmconfig natm add 192.168.173.1 hatm0 0 100 llc/snap ubr</userinput>
4919 hostB&prompt.root; <userinput>atmconfig natm add 192.168.173.3 hatm0 0 103 llc/snap ubr</userinput>
4920 hostB&prompt.root; <userinput>atmconfig natm add 192.168.173.4 hatm0 0 104 llc/snap ubr</userinput>
4921
4922 hostC&prompt.root; <userinput>atmconfig natm add 192.168.173.1 hatm0 0 101 llc/snap ubr</userinput>
4923 hostC&prompt.root; <userinput>atmconfig natm add 192.168.173.2 hatm0 0 103 llc/snap ubr</userinput>
4924 hostC&prompt.root; <userinput>atmconfig natm add 192.168.173.4 hatm0 0 105 llc/snap ubr</userinput>
4925
4926 hostD&prompt.root; <userinput>atmconfig natm add 192.168.173.1 hatm0 0 102 llc/snap ubr</userinput>
4927 hostD&prompt.root; <userinput>atmconfig natm add 192.168.173.2 hatm0 0 104 llc/snap ubr</userinput>
4928 hostD&prompt.root; <userinput>atmconfig natm add 192.168.173.3 hatm0 0 105 llc/snap ubr</userinput></screen>
4929
4930 <para>Other traffic contracts besides <literal>ubr</literal>
4931 can be used if the <acronym>ATM</acronym> adapter supports
4932 it. In this case, the name of the traffic contract is
4933 followed by the parameters of the traffic. Help for the
4934 &man.atmconfig.8; tool can be obtained with:</para>
4935
4936 <screen>&prompt.root; <userinput>atmconfig help natm add</userinput></screen>
4937
4938 <para>Refer to &man.atmconfig.8; for more information.</para>
4939
4940 <para>The same configuration can also be done via
4941 <filename>/etc/rc.conf</filename>. These lines configure
4942 <systemitem>hostA</systemitem>:</para>
4943
4944 <programlisting>network_interfaces="lo0 hatm0"
4945 ifconfig_hatm0="inet 192.168.173.1 up"
4946 natm_static_routes="hostB hostC hostD"
4947 route_hostB="192.168.173.2 hatm0 0 100 llc/snap ubr"
4948 route_hostC="192.168.173.3 hatm0 0 101 llc/snap ubr"
4949 route_hostD="192.168.173.4 hatm0 0 102 llc/snap ubr"</programlisting>
4950
4951 <para>The current state of all <acronym>CLIP</acronym> routes
4952 can be obtained with:</para>
4953
4954 <screen>hostA&prompt.root; <userinput>atmconfig natm show</userinput></screen>
4955 </sect3>
4956 </sect2>
4957 </sect1>
4958 -->
4959 <sect1 xml:id="carp">
4960 <info>
4961 <title>Common Address Redundancy Protocol
4962 (<acronym>CARP</acronym>)</title>
4963
4964 <authorgroup>
4965 <author>
4966 <personname>
4967 <firstname>Tom</firstname>
4968 <surname>Rhodes</surname>
4969 </personname>
4970 <contrib>Contributed by </contrib>
4971 </author>
4972 </authorgroup>
4973 <authorgroup>
4974 <author>
4975 <personname>
4976 <firstname>Allan</firstname>
4977 <surname>Jude</surname>
4978 </personname>
4979 <contrib>Updated by </contrib>
4980 </author>
4981 </authorgroup>
4982 </info>
4983
4984 <indexterm>
4985 <primary><acronym>CARP</acronym></primary>
4986 </indexterm>
4987 <indexterm>
4988 <primary>Common Address Redundancy Protocol</primary>
4989 </indexterm>
4990
4991 <para>The Common Address Redundancy Protocol
4992 (<acronym>CARP</acronym>) allows multiple hosts to share the
4993 same <acronym>IP</acronym> address and Virtual Host ID
4994 (<acronym>VHID</acronym>) in order to provide <firstterm>high
4995 availability</firstterm> for one or more services. This means
4996 that one or more hosts can fail, and the other hosts will
4997 transparently take over so that users do not see a service
4998 failure.</para>
4999
5000 <para>In addition to the shared <acronym>IP</acronym> address,
5001 each host has its own <acronym>IP</acronym> address for
5002 management and configuration. All of the machines that share an
5003 <acronym>IP</acronym> address have the same
5004 <acronym>VHID</acronym>. The <acronym>VHID</acronym> for each
5005 virtual <acronym>IP</acronym> address must be unique across the
5006 broadcast domain of the network interface.</para>
5007
5008 <para>High availability using <acronym>CARP</acronym> is built
5009 into &os;, though the steps to configure it vary slightly
5010 depending upon the &os; version. This section provides the same
5011 example configuration for versions before and equal to or after
5012 &os;&nbsp;10.</para>
5013
5014 <para>This example configures failover support with three hosts,
5015 all with unique <acronym>IP</acronym> addresses, but providing
5016 the same web content. It has two different masters named
5017 <systemitem>hosta.example.org</systemitem> and
5018 <systemitem>hostb.example.org</systemitem>, with a shared backup
5019 named <systemitem>hostc.example.org</systemitem>.</para>
5020
5021 <para>These machines are load balanced with a Round Robin
5022 <acronym>DNS</acronym> configuration. The master and backup
5023 machines are configured identically except for their hostnames
5024 and management <acronym>IP</acronym> addresses. These servers
5025 must have the same configuration and run the same services.
5026 When the failover occurs, requests to the service on the shared
5027 <acronym>IP</acronym> address can only be answered correctly if
5028 the backup server has access to the same content. The backup
5029 machine has two additional <acronym>CARP</acronym> interfaces,
5030 one for each of the master content server's
5031 <acronym>IP</acronym> addresses. When a failure occurs, the
5032 backup server will pick up the failed master machine's
5033 <acronym>IP</acronym> address.</para>
5034
5035 <sect2 xml:id="carp-10x">
5036 <title>Using <acronym>CARP</acronym> on &os;&nbsp;10 and
5037 Later</title>
5038
5039 <para>Enable boot-time support for <acronym>CARP</acronym> by
5040 adding an entry for the <filename>carp.ko</filename> kernel
5041 module in <filename>/boot/loader.conf</filename>:</para>
5042
5043 <programlisting>carp_load="YES"</programlisting>
5044
5045 <para>To load the module now without rebooting:</para>
5046
5047 <screen>&prompt.root; <userinput>kldload carp</userinput></screen>
5048
5049 <para>For users who prefer to use a custom kernel, include the
5050 following line in the custom kernel configuration file and
5051 compile the kernel as described in <xref
5052 linkend="kernelconfig"/>:</para>
5053
5054 <programlisting>device carp</programlisting>
5055
5056 <para>The hostname, management <acronym>IP</acronym> address and
5057 subnet mask, shared <acronym>IP</acronym> address, and
5058 <acronym>VHID</acronym> are all set by adding entries to
5059 <filename>/etc/rc.conf</filename>. This example is for
5060 <systemitem>hosta.example.org</systemitem>:</para>
5061
5062 <programlisting>hostname="<replaceable>hosta.example.org</replaceable>"
5063 ifconfig_<replaceable>em0</replaceable>="inet <replaceable>192.168.1.3</replaceable> netmask <replaceable>255.255.255.0</replaceable>"
5064 ifconfig_<replaceable>em0</replaceable>_alias0="inet vhid <replaceable>1</replaceable> pass <replaceable>testpass</replaceable> alias <replaceable>192.168.1.50</replaceable>/32"</programlisting>
5065
5066 <para>The next set of entries are for
5067 <systemitem>hostb.example.org</systemitem>. Since it
5068 represents a second master, it uses a different shared
5069 <acronym>IP</acronym> address and <acronym>VHID</acronym>.
5070 However, the passwords specified with <option>pass</option>
5071 must be identical as <acronym>CARP</acronym> will only listen
5072 to and accept advertisements from machines with the correct
5073 password.</para>
5074
5075 <programlisting>hostname="<replaceable>hostb.example.org</replaceable>"
5076 ifconfig_<replaceable>em0</replaceable>="inet <replaceable>192.168.1.4</replaceable> netmask <replaceable>255.255.255.0</replaceable>"
5077 ifconfig_<replaceable>em0</replaceable>_alias0="inet vhid <replaceable>2</replaceable> pass <replaceable>testpass</replaceable> alias <replaceable>192.168.1.51</replaceable>/32"</programlisting>
5078
5079 <para>The third machine,
5080 <systemitem>hostc.example.org</systemitem>, is configured to
5081 handle failover from either master. This machine is
5082 configured with two <acronym>CARP</acronym>
5083 <acronym>VHID</acronym>s, one to handle the virtual
5084 <acronym>IP</acronym> address for each of the master hosts.
5085 The <acronym>CARP</acronym> advertising skew,
5086 <option>advskew</option>, is set to ensure that the backup
5087 host advertises later than the master, since
5088 <option>advskew</option> controls the order of precedence when
5089 there are multiple backup servers.</para>
5090
5091 <programlisting>hostname="hostc.example.org"
5092 ifconfig_<replaceable>em0</replaceable>="inet <replaceable>192.168.1.5</replaceable> netmask <replaceable>255.255.255.0</replaceable>"
5093 ifconfig_<replaceable>em0</replaceable>_alias0="inet vhid <replaceable>1</replaceable> advskew <replaceable>100</replaceable> pass <replaceable>testpass</replaceable> alias <replaceable>192.168.1.50</replaceable>/32"
5094 ifconfig_<replaceable>em0</replaceable>_alias1="inet vhid <replaceable>2</replaceable> advskew <replaceable>100</replaceable> pass <replaceable>testpass</replaceable> alias <replaceable>192.168.1.51</replaceable>/32"</programlisting>
5095
5096 <para>Having two <acronym>CARP</acronym>
5097 <acronym>VHID</acronym>s configured means that
5098 <systemitem>hostc.example.org</systemitem> will notice if
5099 either of the master servers becomes unavailable. If a master
5100 fails to advertise before the backup server, the backup server
5101 will pick up the shared <acronym>IP</acronym> address until
5102 the master becomes available again.</para>
5103
5104 <note>
5105 <para>Preemption is disabled by default. If preemption has
5106 been enabled, <systemitem>hostc.example.org</systemitem>
5107 might not release the virtual <acronym>IP</acronym> address
5108 back to the original master server. The administrator
5109 can force the backup server to return the
5110 <acronym>IP</acronym> address to the master with the
5111 command:</para>
5112
5113 <screen>&prompt.root; <userinput>ifconfig em0 vhid 1 state backup</userinput></screen>
5114 </note>
5115
5116 <para>Once the configuration is complete, either restart
5117 networking or reboot each system. High availability is now
5118 enabled.</para>
5119
5120 <para><acronym>CARP</acronym> functionality can be controlled
5121 via several &man.sysctl.8; variables documented in the
5122 &man.carp.4; manual pages. Other actions can be triggered
5123 from <acronym>CARP</acronym> events by using
5124 &man.devd.8;.</para>
5125 </sect2>
5126
5127 <sect2 xml:id="carp-9x">
5128 <title>Using <acronym>CARP</acronym> on &os;&nbsp;9 and
5129 Earlier</title>
5130
5131 <para>The configuration for these versions of &os; is similar to
5132 the one described in the previous section, except that a
5133 <acronym>CARP</acronym> device must first be created and
5134 referred to in the configuration.</para>
5135
5136 <para>Enable boot-time support for <acronym>CARP</acronym> by
5137 loading the <filename>if_carp.ko</filename> kernel module in
5138 <filename>/boot/loader.conf</filename>:</para>
5139
5140 <programlisting>if_carp_load="YES"</programlisting>
5141
5142 <para>To load the module now without rebooting:</para>
5143
5144 <screen>&prompt.root; <userinput>kldload carp</userinput></screen>
5145
5146 <para>For users who prefer to use a custom kernel, include the
5147 following line in the custom kernel configuration file and
5148 compile the kernel as described in <xref
5149 linkend="kernelconfig"/>:</para>
5150
5151 <programlisting>device carp</programlisting>
5152
5153 <para>Next, on each host, create a <acronym>CARP</acronym>
5154 device:</para>
5155
5156 <screen>&prompt.root; <userinput>ifconfig carp0 create</userinput></screen>
5157
5158 <para>Set the hostname, management <acronym>IP</acronym>
5159 address, the shared <acronym>IP</acronym> address, and
5160 <acronym>VHID</acronym> by adding the required lines to
5161 <filename>/etc/rc.conf</filename>. Since a virtual
5162 <acronym>CARP</acronym> device is used instead of an alias,
5163 the actual subnet mask of <literal>/24</literal> is used
5164 instead of <literal>/32</literal>. Here are the entries for
5165 <systemitem>hosta.example.org</systemitem>:</para>
5166
5167 <programlisting>hostname="<replaceable>hosta.example.org</replaceable>"
5168 ifconfig_<replaceable>fxp0</replaceable>="inet <replaceable>192.168.1.3</replaceable> netmask <replaceable>255.255.255.0</replaceable>"
5169 cloned_interfaces="carp0"
5170 ifconfig_carp0="vhid <replaceable>1</replaceable> pass <replaceable>testpass</replaceable> <replaceable>192.168.1.50/24</replaceable>"</programlisting>
5171
5172 <para>On <systemitem>hostb.example.org</systemitem>:</para>
5173
5174 <programlisting>hostname="<replaceable>hostb.example.org</replaceable>"
5175 ifconfig_<replaceable>fxp0</replaceable>="inet <replaceable>192.168.1.4</replaceable> netmask <replaceable>255.255.255.0</replaceable>"
5176 cloned_interfaces="carp0"
5177 ifconfig_carp0="vhid <replaceable>2</replaceable> pass <replaceable>testpass</replaceable> <replaceable>192.168.1.51/24</replaceable>"</programlisting>
5178
5179 <para>The third machine,
5180 <systemitem>hostc.example.org</systemitem>, is configured to
5181 handle failover from either of the master hosts:</para>
5182
5183 <programlisting>hostname="<replaceable>hostc.example.org</replaceable>"
5184 ifconfig_<replaceable>fxp0</replaceable>="inet <replaceable>192.168.1.5</replaceable> netmask <replaceable>255.255.255.0</replaceable>"
5185 cloned_interfaces="carp0 carp1"
5186 ifconfig_carp0="vhid <replaceable>1</replaceable> advskew <replaceable>100</replaceable> pass <replaceable>testpass</replaceable> <replaceable>192.168.1.50/24</replaceable>"
5187 ifconfig_carp1="vhid <replaceable>2</replaceable> advskew <replaceable>100</replaceable> pass <replaceable>testpass</replaceable> <replaceable>192.168.1.51/24</replaceable>"</programlisting>
5188
5189 <note>
5190 <para>Preemption is disabled in the GENERIC &os; kernel. If
5191 preemption has been enabled with a custom kernel,
5192 <systemitem>hostc.example.org</systemitem> may not release
5193 the <acronym>IP</acronym> address back to the original
5194 content server. The administrator can force the backup
5195 server to return the <acronym>IP</acronym> address to the
5196 master with the command:</para>
5197
5198 <screen>&prompt.root; <userinput>ifconfig carp0 down &amp;&amp; ifconfig carp0 up</userinput></screen>
5199
5200 <para>This should be done on the <filename>carp</filename>
5201 interface which corresponds to the correct host.</para>
5202 </note>
5203
5204 <para>Once the configuration is complete, either restart
5205 networking or reboot each system. High availability is now
5206 enabled.</para>
5207 </sect2>
5208 </sect1>
5209 <sect1 xml:id="network-vlan">
5210 <info>
5211 <title>VLANs</title>
5212 </info>
5213
5214 <indexterm>
5215 <primary><acronym>VLANs</acronym></primary>
5216 </indexterm>
5217 <indexterm>
5218 <primary>Virtual LANs</primary>
5219 </indexterm>
5220
5221 <para><acronym>VLANs</acronym> are a way of virtually dividing up
5222 a network into many different subnetworks. Each will have its
5223 own broadcast domain and be isolated from the rest of the
5224 <acronym>VLANs</acronym>.</para>
5225
5226 <para>On &os;, <acronym>VLANs</acronym> must be supported by the
5227 network card driver. To see which drivers support vlans, refer
5228 to the &man.vlan.4; manual page.</para>
5229
5230 <para>When configuring a <acronym>VLAN</acronym>, a couple pieces
5231 of information must be known. First, which network interface?
5232 Second, what is the <acronym>VLAN</acronym> tag?</para>
5233
5234 <para>To configure <acronym>VLANs</acronym> at run time, with a
5235 <acronym>NIC</acronym> of <literal>em0</literal> and a
5236 <acronym>VLAN</acronym> tag of <systemitem>5</systemitem>. The
5237 command would look like this:</para>
5238
5239 <screen>&prompt.root; <userinput>ifconfig <replaceable>em0.5</replaceable> create vlan <replaceable>5</replaceable> vlandev <replaceable>em0</replaceable> inet 192.168.20.20/24</userinput></screen>
5240
5241 <note>
5242 <para>See how the interface name includes the
5243 <acronym>NIC</acronym> driver name and the
5244 <acronym>VLAN</acronym> tag, separated by a period? This is a
5245 best practice to make maintaining the <acronym>VLAN</acronym>
5246 configuration easy when many <acronym>VLANs</acronym> are
5247 present on a machine.</para>
5248 </note>
5249
5250 <para>To configure <acronym>VLANs</acronym> at boot time,
5251 <filename>/etc/rc.conf</filename> must be updated. To duplicate
5252 the configuration above, the following will need to be
5253 added:</para>
5254
5255 <programlisting>vlans_<replaceable>em0</replaceable>="<replaceable>5</replaceable>"
5256 ifconfig_<replaceable>em0</replaceable>_<replaceable>5</replaceable>="inet 192.168.20.20/24"</programlisting>
5257
5258 <para>Additional <acronym>VLANs</acronym> may be added, by simply
5259 adding the tag to the
5260 <literal>vlans_<replaceable>em0</replaceable></literal>
5261 field and adding an additional line configuring the network on
5262 that <acronym>VLAN</acronym> tag's interface.</para>
5263 </sect1>
5264 </chapter>

Properties

Name Value
svn:keywords FreeBSD=%H
svn:mime-type text/sgml

  ViewVC Help
Powered by ViewVC 1.1.27