?? network-routing.html
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta name="generator" content="HTML Tidy, see www.w3.org" /><title>Gateways and Routes</title><meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" /><link rel="HOME" title="FreeBSD 使用手冊" href="index.html" /><link rel="UP" title="Advanced Networking" href="advanced-networking.html" /><link rel="PREVIOUS" title="Advanced Networking" href="advanced-networking.html" /><link rel="NEXT" title="Wireless Networking" href="network-wireless.html" /><link rel="STYLESHEET" type="text/css" href="docbook.css" /><meta http-equiv="Content-Type" content="text/html; charset=GB2312" /></head><body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"alink="#0000FF"><div class="NAVHEADER"><table summary="Header navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><th colspan="3" align="center">FreeBSD 使用手冊</th></tr><tr><td width="10%" align="left" valign="bottom"><a href="advanced-networking.html"accesskey="P">Prev</a></td><td width="80%" align="center" valign="bottom">Chapter 19. Advanced Networking</td><td width="10%" align="right" valign="bottom"><a href="network-wireless.html"accesskey="N">Next</a></td></tr></table><hr align="LEFT" width="100%" /></div><div class="SECT1"><h1 class="SECT1"><a id="NETWORK-ROUTING" name="NETWORK-ROUTING">19.2. Gateways andRoutes</a></h1><i class="AUTHORGROUP"><span class="CONTRIB">Contributed by</span> Coranth Gryphon.</i> <p>For one machine to be able to find another over a network, there must be a mechanismin place to describe how to get from one to the other. This is called <iclass="FIRSTTERM">routing</i>. A ``route'' is a defined pair of addresses: a``destination'' and a ``gateway''. The pair indicates that if you are trying to get tothis <span class="emphasis"><i class="EMPHASIS">destination</i></span>, communicatethrough this <span class="emphasis"><i class="EMPHASIS">gateway</i></span>. There arethree types of destinations: individual hosts, subnets, and ``default''. The ``defaultroute'' is used if none of the other routes apply. We will talk a little bit more aboutdefault routes later on. There are also three types of gateways: individual hosts,interfaces (also called ``links''), and Ethernet hardware addresses (MAC addresses).</p><div class="SECT2"><h2 class="SECT2"><a id="AEN25235" name="AEN25235">19.2.1. An Example</a></h2><p>To illustrate different aspects of routing, we will use the following example from <ttclass="COMMAND">netstat</tt>:</p><pre class="SCREEN"><samp class="PROMPT">%</samp> <kbd class="USERINPUT">netstat -r</kbd>Routing tablesDestination Gateway Flags Refs Use Netif Expiredefault outside-gw UGSc 37 418 ppp0localhost localhost UH 0 181 lo0test0 0:e0:b5:36:cf:4f UHLW 5 63288 ed0 7710.20.30.255 link#1 UHLW 1 2421example.com link#1 UC 0 0host1 0:e0:a8:37:8:1e UHLW 3 4601 lo0host2 0:e0:a8:37:8:1e UHLW 0 5 lo0 =>host2.example.com link#1 UC 0 0224 link#1 UC 0 0</pre><p>The first two lines specify the default route (which we will cover in the <ahref="network-routing.html#NETWORK-ROUTING-DEFAULT">next section</a>) and the <ttclass="HOSTID">localhost</tt> route.</p><p>The interface (<var class="LITERAL">Netif</var> column) that this routing tablespecifies to use for <var class="LITERAL">localhost</var> is <ttclass="DEVICENAME">lo0</tt>, also known as the loopback device. This says to keep alltraffic for this destination internal, rather than sending it out over the LAN, since itwill only end up back where it started.</p><p>The next thing that stands out are the addresses beginning with <ttclass="HOSTID">0:e0:</tt>. These are Ethernet hardware addresses, which are also known asMAC addresses. FreeBSD will automatically identify any hosts (<ttclass="HOSTID">test0</tt> in the example) on the local Ethernet and add a route for thathost, directly to it over the Ethernet interface, <tt class="DEVICENAME">ed0</tt>. Thereis also a timeout (<var class="LITERAL">Expire</var> column) associated with this type ofroute, which is used if we fail to hear from the host in a specific amount of time. Whenthis happens, the route to this host will be automatically deleted. These hosts areidentified using a mechanism known as RIP (Routing Information Protocol), which figuresout routes to local hosts based upon a shortest path determination.</p><p>FreeBSD will also add subnet routes for the local subnet (<ttclass="HOSTID">10.20.30.255</tt> is the broadcast address for the subnet <ttclass="HOSTID">10.20.30</tt>, and <tt class="HOSTID">example.com</tt> is the domain nameassociated with that subnet). The designation <var class="LITERAL">link#1</var> refers tothe first Ethernet card in the machine. You will notice no additional interface isspecified for those.</p><p>Both of these groups (local network hosts and local subnets) have their routesautomatically configured by a daemon called <b class="APPLICATION">routed</b>. If this isnot run, then only routes which are statically defined (i.e. entered explicitly) willexist.</p><p>The <var class="LITERAL">host1</var> line refers to our host, which it knows byEthernet address. Since we are the sending host, FreeBSD knows to use the loopbackinterface (<tt class="DEVICENAME">lo0</tt>) rather than sending it out over the Ethernetinterface.</p><p>The two <var class="LITERAL">host2</var> lines are an example of what happens when weuse an <span class="CITEREFENTRY"><span class="REFENTRYTITLE">ifconfig</span>(8)</span>alias (see the section on Ethernet for reasons why we would do this). The <varclass="LITERAL">=></var> symbol after the <tt class="DEVICENAME">lo0</tt> interfacesays that not only are we using the loopback (since this address also refers to the localhost), but specifically it is an alias. Such routes only show up on the host thatsupports the alias; all other hosts on the local network will simply have a <varclass="LITERAL">link#1</var> line for such routes.</p><p>The final line (destination subnet <var class="LITERAL">224</var>) deals withmulticasting, which will be covered in another section.</p><p>Finally, various attributes of each route can be seen in the <varclass="LITERAL">Flags</var> column. Below is a short table of some of these flags andtheir meanings:</p><div class="INFORMALTABLE"><a id="AEN25285" name="AEN25285"></a><table border="0" frame="void" class="CALSTABLE"><col /><col /><tbody><tr><td>U</td><td>Up: The route is active.</td></tr><tr><td>H</td><td>Host: The route destination is a single host.</td></tr><tr><td>G</td><td>Gateway: Send anything for this destination on to this remote system, which willfigure out from there where to send it.</td></tr><tr><td>S</td><td>Static: This route was configured manually, not automatically generated by thesystem.</td></tr><tr><td>C</td><td>Clone: Generates a new route based upon this route for machines we connect to. Thistype of route is normally used for local networks.</td></tr><tr><td>W</td><td>WasCloned: Indicated a route that was auto-configured based upon a local area network(Clone) route.</td></tr><tr><td>L</td><td>Link: Route involves references to Ethernet hardware.</td></tr></tbody></table></div></div><div class="SECT2"><h2 class="SECT2"><a id="NETWORK-ROUTING-DEFAULT" name="NETWORK-ROUTING-DEFAULT">19.2.2.Default Routes</a></h2><p>When the local system needs to make a connection to a remote host, it checks therouting table to determine if a known path exists. If the remote host falls into a subnetthat we know how to reach (Cloned routes), then the system checks to see if it canconnect along that interface.</p><p>If all known paths fail, the system has one last option: the ``default'' route. Thisroute is a special type of gateway route (usually the only one present in the system),and is always marked with a <var class="LITERAL">c</var> in the flags field. For hosts ona local area network, this gateway is set to whatever machine has a direct connection tothe outside world (whether via PPP link, DSL, cable modem, T1, or another networkinterface).</p><p>If you are configuring the default route for a machine which itself is functioning asthe gateway to the outside world, then the default route will be the gateway machine atyour Internet Service Provider's (ISP) site.</p><p>Let us look at an example of default routes. This is a common configuration:</p><p class="LITERALLAYOUT">[Local2] <--ether--> [Local1] <--PPP--> [ISP-Serv] <--ether--> [T1-GW]<br /> </p><p>The hosts <tt class="HOSTID">Local1</tt> and <tt class="HOSTID">Local2</tt> are atyour site. <tt class="HOSTID">Local1</tt> is connected to an ISP via a dial up PPPconnection. This PPP server computer is connected through a local area network to anothergateway computer through an external interface to the ISPs Internet feed.</p><p>The default routes for each of your machines will be:</p><div class="INFORMALTABLE"><a id="AEN25325" name="AEN25325"></a><table border="0" frame="void" class="CALSTABLE"><col />
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -