<?xml version="1.0" encoding="GBK"?>
<?xml-stylesheet href="/style/rss.css" type="text/css"?>
<rss version="2.0" xmlns:eb="http://blog.tom.com/">
<channel>
  <title>ccna之家</title>
  <link>http://blog.tom.com/ccna</link>
  <description><![CDATA[我在考CCNA，觉的有很多的东西要交流，所以要大家一起分享一下 ]]></description>
  <language>zh</language>
  <generator>newblog.tom.com RSS</generator>
  <pubDate></pubDate>    <item>
		<title><![CDATA[ ping  and Traceroute ]]></title>
		<link>http://blog.tom.com/ccna/article/2146.html</link>
		<description><![CDATA[ <h2>Ping 和 Traceroute 命令详解</h2>
<div id="postmessage_290713"><font color="#000000">Introduction</font> This document illustrates the use of the <strong>ping</strong> and <strong>traceroute</strong> commands. With the aid of some <strong>debug</strong> commands, this document captures a more detailed view of how these commands work.<br>
<strong>Note:</strong> Enabling any <strong>debug</strong> commands on a production router may cause serious problems. We recommend that you carefully read the <font color="#800080">Use the Debug Command</font> section before you issue <strong>debug</strong> commands.<br>
<font color="#000000">Prerequisites</font> <font color="#000000">Requirements</font> There are no specific requirements for this document.<br>
<font color="#000000">Components Used</font> This document is not restricted to specific software and hardware versions.<br>
The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your <span href="tag.php?name=network">network</span> is live, make sure that you understand the potential impact of any command.<br>
<font color="#000000">Conventions</font> For more information on document conventions, refer to the <font color="#0000FF">Cisco Technical Tips Conventions</font>.<br>
<font color="#000000">Background Information</font> In this document, we use the basic configuration shown below as a basis for our ex<span href="tag.php?name=amp">amp</span>les:<br>
<img style="CURSOR: pointer" alt="" src="http://www.cisco.com/warp/public/63/ping_traceroute1.gif" width="540" border="0" resized="true"><br>
<font color="#000000">The Ping Command</font> The <strong>ping</strong> command is a very common method for troubleshooting the accessibility of devices. It uses a series of Internet Control Message Protocol (ICMP) Echo messages to determine:<br>
<ul>
<li>Whether a remote host is active or inactive.<br></li>
<li>The round-trip delay in communicating with the host.<br></li>
<li>Packet loss.<br></li>
</ul>
The <strong>ping</strong> command first sends an echo request packet to an address, then waits for a reply. The ping is successful only if:<br>
<ul>
<li>the echo request gets to the destination, and<br></li>
<li>the destination is able to get an echo reply back to the source within a predetermined time called a timeout. The default value of this timeout is two seconds on Cisco routers.<br></li>
</ul>
For all the options about this command, see "Ping" under <font color="#0000FF">Troubleshooting Commands</font>.<br>
Here is an output example showing the <strong>ping</strong> command after enabling the <strong>debug ip packet detail</strong> command:<br>
<img alt="" src="http://www.cisco.com/images/warning.gif" border="0"> <strong>Warning:</strong> Using the <strong>debug ip packet detail</strong> command on a production router can cause high CPU utilization. This may result in a severe performance degradation or a network outage. We recommend that you carefully read <font color="#800080">Use the Debug Command</font> before issuing <strong>debug</strong> commands.<br>
<span href="tag.php?name=Router">Router</span>1#<strong>debug ip packet detail</strong> IP packet debugging is on (detailed)Router1#<strong>ping 12.0.0.2</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 4/6/8 ms Router1# Jan 20 15:54:47.487: IP: s=12.0.0.1 (local), d=12.0.0.2 (Serial0), len 100,&nbsp; &nbsp;sendingJan 20 15:54:47.491: <strong>ICMP type=8</strong>, code=0<i><font color="#0000FF">!--- This is the ICMP packet 12.0.0.1 sent to 12.0.0.2.&nbsp;&nbsp;!--- ICMP type=8 corresponds to the echo message.</font></i> Jan 20 15:54:47.523: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 100,&nbsp; &nbsp;rcvd 3Jan 20 15:54:47.527: <strong>ICMP type=0</strong>, code=0<i><font color="#0000FF">!--- This is the answer we get from 12.0.0.2. !--- ICMP type=0 corresponds to the echo reply message.&nbsp;&nbsp;!--- By default, the repeat count is five times, so there will be five !--- echo requests, and five echo replies.</font></i> The table below lists possible ICMP-type values.<br>
<table style="WIDTH: 60%" cellspacing="0" bgcolor="#FFFFFF">
<tbody>
<tr>
<td>ICMP Type<br></td>
<td>Literal<br></td>
</tr>
<tr>
<td>0<br></td>
<td>echo-reply<br></td>
</tr>
<tr>
<td>3<br></td>
<td>destination unreachable<br>
code 0 = net unreachable<br>
1 = host unreachable<br>
2 = protocol unreachable<br>
3 = port unreachable<br>
4 = fragmentation needed and DF set<br>
5 = source route failed<br></td>
</tr>
<tr>
<td>4<br></td>
<td>source-quench<br></td>
</tr>
<tr>
<td>5<br></td>
<td>redirect<br>
code 0 = redirect datagrams for the network<br>
1 = redirect datagrams for the host<br>
2 = redirect datagrams for the type of service and network<br>
3 = redirect datagrams for the type of service and host<br></td>
</tr>
<tr>
<td>6<br></td>
<td>alternate-address<br></td>
</tr>
<tr>
<td>8<br></td>
<td>echo<br></td>
</tr>
<tr>
<td>9<br></td>
<td>router-advertisement<br></td>
</tr>
<tr>
<td>10<br></td>
<td>router-solicitation<br></td>
</tr>
<tr>
<td>11<br></td>
<td>time-exceeded<br>
code 0 = time to live exceeded in transit 1 = fragment reassembly time exceeded<br></td>
</tr>
<tr>
<td>12<br></td>
<td>parameter-problem<br></td>
</tr>
<tr>
<td>13<br></td>
<td>timestamp-request<br></td>
</tr>
<tr>
<td>14<br></td>
<td>timestamp-reply<br></td>
</tr>
<tr>
<td>15<br></td>
<td>information-request<br></td>
</tr>
<tr>
<td>16<br></td>
<td>information-reply<br></td>
</tr>
<tr>
<td>17<br></td>
<td>mask-request<br></td>
</tr>
<tr>
<td>18<br></td>
<td>mask-reply<br></td>
</tr>
<tr>
<td>31<br></td>
<td>conversion-error<br></td>
</tr>
<tr>
<td>32<br></td>
<td>mobile-redirect<br></td>
</tr>
</tbody>
</table>
The table below lists the possible output characters from the ping facility:<br>
<table style="WIDTH: 60%" cellspacing="0" bgcolor="#FFFFFF">
<tbody>
<tr>
<td>Character<br></td>
<td width="492">Description<br></td>
</tr>
<tr>
<td>!<br></td>
<td width="492">Each exclamation point indicates receipt of a reply.<br></td>
</tr>
<tr>
<td>.<br></td>
<td width="492">Each period indicates the network server timed out while waiting for a reply.<br></td>
</tr>
<tr>
<td>U<br></td>
<td width="492">A destination unreachable error PDU was received.<br></td>
</tr>
<tr>
<td>Q<br></td>
<td width="492">Source quench (destination too busy).<br></td>
</tr>
<tr>
<td>M<br></td>
<td width="492">Could not fragment.<br></td>
</tr>
<tr>
<td>?<br></td>
<td width="492">Unknown packet type.<br></td>
</tr>
<tr>
<td>&amp;<br></td>
<td width="492">Packet lifetime exceeded.<br></td>
</tr>
</tbody>
</table>
<font color="#000000">Why Can't I Ping?</font> If you are not able to successfully ping to an address, consider these causes:<br>
<font color="#000000">Routing Issue</font> Here are examples of unsuccessful ping attempts, determining the problem, and what to do to resolve the problem.<br>
This scenario is explained using the network topology diagram below:<br>
<img style="CURSOR: pointer" alt="" src="http://www.cisco.com/warp/public/63/ping_traceroute1.gif" width="540" border="0" resized="true"><br>
<strong>Router1#</strong> ! ! interface Serial0 ip address 12.0.0.1 255.255.255.0 no fair-queue clockrate 64000 ! ! <strong>Router2#</strong> ! ! interface Serial0 ip address 23.0.0.2 255.255.255.0 no fair-queue clockrate 64000 ! interface Serial1 ip address 12.0.0.2 255.255.255.0 ! !&nbsp; &nbsp;<strong>Router3#</strong> ! ! interface Serial0 ip address 34.0.0.3 255.255.255.0 no fair-queue ! interface Serial1 ip address 23.0.0.3 255.255.255.0 ! ! <strong>Router4#</strong> ! ! interface Serial0 ip address 34.0.0.4 255.255.255.0 no fair-queue clockrate 64000 ! ! Let us try to ping Router4 from Router1:<br>
Router1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: ..... Success rate is 0 percent (0/5)Let us have a closer look at what has happened:<br>
Router1#<strong>debug ip packet</strong>IP packet debugging is on<img alt="" src="http://www.cisco.com/images/warning.gif" border="0"> <strong>Warning:</strong> Using the <strong>debug ip packet</strong> command on a production router can cause high cpu utilization. This may result in a severe performance degradation or a network outage. We recommend that you carefully read <font color="#800080">Use the Debug Command</font> before issuing <strong>debug</strong> commands.<br>
Router1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: Jan 20 16:00:25.603: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable.Jan 20 16:00:27.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable.Jan 20 16:00:29.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable.Jan 20 16:00:31.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable.Jan 20 16:00:33.599: IP: s=12.0.0.1 (local), d=34.0.0.4, len 100, unroutable.Success rate is 0 percent (0/5)Since no routing protocols are running on Router1, it does not know where to send its packet and we get an "unroutable" message.<br>
Now let us add a static route to Router1:<br>
Router1#<strong>configure terminal</strong>Enter configuration commands, one per line.&nbsp;&nbsp;End with CNTL/Z. Router1(config)#<strong>ip route 0.0.0.0 0.0.0.0 Serial0</strong>We now have:<br>
Router1#<strong>debug ip packet detail</strong>IP packet debugging is on (detailed)Router1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: U.U.U Success rate is 0 percent (0/5) Jan 20 16:05:30.659: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;sendingJan 20 16:05:30.663:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:05:30.691: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56,&nbsp; &nbsp;rcvd 3Jan 20 16:05:30.695:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=3, code=1Jan 20 16:05:30.699: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;sendingJan 20 16:05:30.703:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:05:32.699: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;sendingJan 20 16:05:32.703:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:05:32.731: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56,&nbsp; &nbsp;rcvd 3Jan 20 16:05:32.735:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=3, code=1Jan 20 16:05:32.739: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;sendingJan 20 16:05:32.743:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Now let us examine what is wrong on Router2:<br>
Router2#<strong>debug ip packet detail</strong>IP packet debugging is on (detailed)Router2# Jan 20 16:10:41.907: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutableJan 20 16:10:41.911:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:10:41.915: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), len 56, sendingJan 20 16:10:41.919:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=3, code=1Jan 20 16:10:41.947: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutableJan 20 16:10:41.951:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:10:43.943: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutableJan 20 16:10:43.947:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:10:43.951: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), len 56, sendingJan 20 16:10:43.955:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=3, code=1Jan 20 16:10:43.983: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutableJan 20 16:10:43.987:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:10:45.979: IP: s=12.0.0.1 (Serial1), d=34.0.0.4, len 100, unroutableJan 20 16:10:45.983:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=8, code=0Jan 20 16:10:45.987: IP: s=12.0.0.2 (local), d=12.0.0.1 (Serial1), len 56, sendingJan 20 16:10:45.991:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=3, code=1 Router1 is correctly sending its packets to Router2, but Router2 doesn't know how to access address 34.0.0.4. Router2 sends back an "unreachable ICMP" message to Router1.<br>
Now let's enable Routing Information Protocol (RIP) on Router2 and Router3:<br>
Router2# router rip&nbsp;&nbsp;network 12.0.0.0&nbsp;&nbsp;network 23.0.0.0 Router3# router rip&nbsp;&nbsp;network 23.0.0.0&nbsp;&nbsp;network 34.0.0.0 Now we have:<br>
Router1#<strong>debug ip packet</strong>IP packet debugging is onRouter1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: Jan 20 16:16:13.367: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending.Jan 20 16:16:15.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending.Jan 20 16:16:17.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending.Jan 20 16:16:19.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending.Jan 20 16:16:21.363: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sending.Success rate is 0 percent (0/5) This is slightly better. Router1 is sending packets to Router4, but is not getting any answer from Router4.<br>
Let us see what the problem could be on Router4:<br>
Router4#<strong>debug ip packet</strong>IP packet debugging is onRouter4# Jan 20 16:18:45.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;rcvd 3Jan 20 16:18:45.911: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutableJan 20 16:18:47.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;rcvd 3Jan 20 16:18:47.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutableJan 20 16:18:49.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;rcvd 3Jan 20 16:18:49.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutableJan 20 16:18:51.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;rcvd 3Jan 20 16:18:51.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutableJan 20 16:18:53.903: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100,&nbsp; &nbsp;rcvd 3Jan 20 16:18:53.907: IP: s=34.0.0.4 (local), d=12.0.0.1, len 100, unroutableRouter4 receives the ICMP packets, and tries to answer to 12.0.0.1, but because it does not have a route to this network, it simply fails.<br>
Let us add a static route to Router4:<br>
Router4(config)#<strong>ip route 0.0.0.0 0.0.0.0 Serial0</strong>Now it works perfectly, and both sides can access each other:<br>
Router1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 32/35/36 ms <font color="#000000">Interface Down</font> This is a situation where the interface stops working. In the example below, we try to ping Router4 from Router1:<br>
Router1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: U.U.U Success rate is 0 percent (0/5) Since the routing is fine, we will do the troubleshooting step-by-step. First, let us try to ping Router2:<br>
Router1#<strong>ping 12.0.0.2</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms From the above, we see that the problem lies between Router2 and Router3. One possibility is that the serial interface on Router3 has been shut down:<br>
Router3#<strong>show ip interface brief</strong> Serial0&nbsp; &nbsp;34.0.0.3&nbsp; &nbsp; YES manual up&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; upSerial1&nbsp; &nbsp;23.0.0.3&nbsp; &nbsp; YES manual administratively down&nbsp; &nbsp;down&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; This is quite simple to fix:<br>
Router3#<strong>configure terminal</strong> Enter configuration commands, one per line.&nbsp;&nbsp;End with CNTL/Z. Router3(config)#<strong>interface s1</strong> Router3(config-if)#<strong>no shutdown</strong>Router3(config-if)# Jan 20 16:20:53.900: %LINK-3-UPDOWN: Interface Serial1, changed state to up Jan 20 16:20:53.910: %LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1,&nbsp; &nbsp;changed state to up <font color="#000000">Access-list Command</font> In this scenario, we want to allow only telnet traffic to enter Router4 through interface Serial0 .<br>
Router4(config)# <strong>access-list 100 permit <span href="tag.php?name=tcp">tcp</span> any any eq telnet</strong> Router4(config)#<strong>interface s0</strong>Router4(config-if)#<strong>ip access-group 100 in</strong>Router1#<strong>configure terminal</strong>Enter configuration commands, one per line.&nbsp;&nbsp;End with CNTL/Z.Router1(config)#<strong>access-list 100 permit ip host 12.0.0.1 host 34.0.0.4</strong>Router1(config)#<strong>access-list 100 permit ip host 34.0.0.4 host 12.0.0.1</strong>Router1(config)#<strong>end</strong>Router1#<strong>debug ip packet 100</strong> IP packet debugging is onRouter1#<strong>debug ip icmp</strong>ICMP packet debugging is onRefer to the <font color="#800080">Use the Debug Command</font> section for using access lists with <strong>debug</strong> commands.<br>
When we now try to ping Router4, we have the following:<br>
Router1#<strong>ping 34.0.0.4</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 34.0.0.4, timeout is 2 seconds: U.U.U Success rate is 0 percent (0/5) Jan 20 16:34:49.207: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sendingJan 20 16:34:49.287: IP: s=34.0.0.4 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:34:49.291: ICMP: dst (12.0.0.1) <strong>administratively prohibited unreachable</strong> rcv from 34.0.0.4Jan 20 16:34:49.295: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sendingJan 20 16:34:51.295: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sendingJan 20 16:34:51.367: IP: s=34.0.0.4 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:34:51.371: ICMP: dst (12.0.0.1) administratively prohibited unreachable rcv from 34.0.0.4Jan 20 16:34:51.379: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 100, sendingAt the end of an <strong>access-list</strong> command, we always have an implicit "deny all". This means that the ICMP packets that are entering the Serial 0 interface on Router4 are denied, and Router 4 sends an ICMP "administratively prohibited unreachable" message to the source of the original packet as shown in the <strong>debug</strong> message. The solution is to add the following line in the <strong>access-list</strong> command:<br>
Router4(config)#<strong>access-list 100 permit icmp any any</strong><font color="#000000">Address Resolution Protocol (<span href="tag.php?name=ARP">ARP</span>) Issue</font> Here is a scenario with an Ethernet connection:<br>
<img alt="" src="http://www.cisco.com/warp/public/63/ping_traceroute2.gif" border="0"><br>
Router4#<strong>ping 100.0.0.5</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 100.0.0.5, timeout is 2 seconds: Jan 20 17:04:05.167: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;sendingJan 20 17:04:05.171: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;encapsulation failed.Jan 20 17:04:07.167: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;sendingJan 20 17:04:07.171: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;encapsulation failed.Jan 20 17:04:09.175: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;sendingJan 20 17:04:09.183: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;encapsulation failed.Jan 20 17:04:11.175: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;sendingJan 20 17:04:11.179: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;encapsulation failed.Jan 20 17:04:13.175: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;sendingJan 20 17:04:13.179: IP: s=100.0.0.4 (local), d=100.0.0.5 (Ethernet0), len 100,&nbsp; &nbsp;encapsulation failed.Success rate is 0 percent (0/5)Router4# In this example, the ping is not working due to "encapsulation failed". This means that the router knows on which interface it has to send the packet, but does not know how to do it. In this case, you need to understand how Address Resolution Protocol (ARP) works. See <font color="#0000FF">Configuring Address Resolution Methods</font> for a detailed explanation.<br>
Basically, ARP is a protocol used to map the Layer 2 address (MAC address) to a Layer 3 address (IP address). You can check this mapping using the <strong>show arp</strong> command:<br>
Router4#<strong>show arp</strong> Protocol&nbsp;&nbsp;Address&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Age (min)&nbsp;&nbsp;Hardware Addr&nbsp; &nbsp;Type&nbsp; &nbsp;InterfaceInternet&nbsp;&nbsp;100.0.0.4&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;-&nbsp; &nbsp;0000.0c5d.7a0d&nbsp;&nbsp;ARPA&nbsp; &nbsp;Ethernet0Internet&nbsp;&nbsp;100.0.0.1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;10&nbsp; &nbsp;0060.5cf4.a955&nbsp;&nbsp;ARPA&nbsp; &nbsp;Ethernet0Return to the "encapsulation failed" problem. We get a better idea of the problem using this <strong>debug</strong> command:<br>
Router4#<strong>debug arp</strong> ARP packet debugging is on Router4#<strong>ping 100.0.0.5</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 100.0.0.5, timeout is 2 seconds: Jan 20 17:19:43.843: IP ARP: creating incomplete entry for IP address: 100.0.0.5&nbsp; &nbsp;interface Ethernet0Jan 20 17:19:43.847: IP ARP: sent req src 100.0.0.4 0000.0c5d.7a0d,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;<strong>dst 100.0.0.5 0000.0000.0000 Ethernet0.</strong>Jan 20 17:19:45.843: IP ARP: sent req src 100.0.0.4 0000.0c5d.7a0d,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dst 100.0.0.5 0000.0000.0000 Ethernet0.Jan 20 17:19:47.843: IP ARP: sent req src 100.0.0.4 0000.0c5d.7a0d,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dst 100.0.0.5 0000.0000.0000 Ethernet0.Jan 20 17:19:49.843: IP ARP: sent req src 100.0.0.4 0000.0c5d.7a0d,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dst 100.0.0.5 0000.0000.0000 Ethernet0.Jan 20 17:19:51.843: IP ARP: sent req src 100.0.0.4 0000.0c5d.7a0d,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;dst 100.0.0.5 0000.0000.0000 Ethernet0.Success rate is 0 percent (0/5)The above output shows that Router4 is broadcasting packets by sending them to the Ethernet broadcast address FFFF.FFFF.FFFF. Here, the 0000.0000.0000 means that Router4 is looking for the MAC address of the destination 100.0.0.5. Since it does not know the MAC address during the ARP request in this example, it uses 0000.0000.000 as a placeholder in the broadcast frames sent out of interface Ethernet 0, asking which MAC address corresponds to 100.0.0.5. If we do not get an answer, the corresponding address in the <strong>show arp</strong> output is marked as incomplete:<br>
Router4#<strong>show arp</strong> Protocol&nbsp;&nbsp;Address&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Age (min)&nbsp;&nbsp;Hardware Addr&nbsp; &nbsp;Type&nbsp; &nbsp;InterfaceInternet&nbsp;&nbsp;100.0.0.4&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;-&nbsp; &nbsp;0000.0c5d.7a0d&nbsp;&nbsp;ARPA&nbsp; &nbsp;Ethernet0<strong>Internet&nbsp;&nbsp;100.0.0.5&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;Incomplete&nbsp; &nbsp;&nbsp; &nbsp;ARPA</strong>Internet&nbsp;&nbsp;100.0.0.1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;2&nbsp; &nbsp;0060.5cf4.a955&nbsp;&nbsp;ARPA&nbsp; &nbsp;Ethernet0After a predetermined period, this incomplete entry is purged from the ARP table. As long as the corresponding MAC address is not in the ARP table, the ping fails as a result of "encapsulation failed".<br>
<font color="#000000">Delay</font> By default, if you do not receive an answer from the remote end within two seconds, the ping fails:<br>
Router1#<strong>ping 12.0.0.2</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, <strong>timeout is 2 seconds:</strong> ..... Success rate is 0 percent (0/5) On networks with a slow link or a long delay, two seconds are not enough. You can change this default using an extended ping:<br>
Router1#<strong>ping</strong> Protocol [ip]: Target IP address:&nbsp;&nbsp;12.0.0.2 Repeat count [5]: Datagram size [100]: Timeout in seconds [2]: <strong>30</strong> Extended commands [n]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 30 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1458/2390/6066 ms In the example above, increasing the timeout has led to a successful ping.<br>
<strong>Note:</strong> The average round-trip time is more than two seconds.<br>
<font color="#000000">Correct Source Address</font> Here is an example of a typical situation:<br>
<img style="CURSOR: pointer" alt="" src="http://www.cisco.com/warp/public/63/ping_traceroute3.gif" width="540" border="0" resized="true"><br>
We add a LAN interface on Router1:<br>
Router1(config)#<strong>interface e0</strong>Router1(config-if)#<strong>ip address</strong>Router1(config-if)#<strong>ip address 20.0.0.1 255.255.255.0</strong> From a station on the LAN, you can ping Router1. From Router1 you can ping Router2. But from a station on the LAN, you cannot ping Router2.<br>
From Router1, you can ping Router2 because, by default, you use the IP address of the outgoing interface as the source address in your ICMP packet. Router2 has not information about this new LAN. If it has to reply to a packet coming from this network, it does not know how to handle it.<br>
Router1#<strong>debug ip packet</strong>IP packet debugging is on<strong>Warning:</strong> Using the <strong>debug ip packet</strong> command on a production router can cause high cpu utilization. This may result in a severe performance degradation or a network outage. We recommend that you carefully read <font color="#800080">Use the Debug Command</font> before issuing <strong>debug</strong> commands.<br>
Router1#<strong>ping 12.0.0.2</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 4/7/9 ms Router1# Jan 20 16:35:54.227: IP: s=12.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sendingJan 20 16:35:54.259: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 100, rcvd 3The output example above works because the source address of the packet we are sending is s=12.0.0.1. If we want to simulate a packet coming from the LAN, we have to use an extended ping:<br>
Router1#<strong>ping</strong> Protocol [ip]: Target IP address: 12.0.0.2 Repeat count [5]: Datagram size [100]: Timeout in seconds [2]: Extended commands [n]: y Source address or interface: <strong>20.0.0.1</strong> Type of service [0]: Set DF bit in IP header? [no]: Validate reply data? [no]: Data pattern [0xABCD]: Loose, Strict, Record, Timestamp, Verbose[none]: Sweep range of sizes [n]: Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds: Jan 20 16:40:18.303: IP: s=20.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sending.Jan 20 16:40:20.303: IP: s=20.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sending.Jan 20 16:40:22.303: IP: s=20.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sending.Jan 20 16:40:24.303: IP: s=20.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sendingJan 20 16:40:26.303: IP: s=20.0.0.1 (local), d=12.0.0.2 (Serial0), len 100, sending.Success rate is 0 percent (0/5) This time, the source address is 20.0.0.1, and it is not working! We are sending our packets, but we are not receiving anything. To fix this issue, we simply have to add a route to 20.0.0.0 in Router2.<br>
The basic rule is that the pinged device should also know how to send the reply to the source of the ping.<br>
<font color="#000000">The Traceroute Command</font> The <strong>traceroute</strong> command is used to discover the routes that packets actually take when traveling to their destination. The device (for example, a router or a PC) sends out a sequence of User Datagram Protocol (UDP) datagrams to an invalid port address at the remote host.<br>
Three datagrams are sent, each with a Time-To-Live (TTL) field value set to one. The TTL value of 1 causes the datagram to "timeout" as soon as it hits the first router in the path; this router then responds with an ICMP Time Exceeded Message (TEM) indicating that the datagram has expired.<br>
Another three UDP messages are now sent, each with the TTL value set to 2, which causes the second router to return ICMP TEMs. This process continues until the packets actually reach the other destination. Since these datagrams are trying to access an invalid port at the destination host, ICMP Port Unreachable Messages are returned, indicating an unreachable port; this event signals the Traceroute program that it is finished.<br>
The purpose behind this is to record the source of each ICMP Time Exceeded Message to provide a trace of the path the packet took to reach the destination. For all the options about this command, see <strong><font color="#0000FF">Trace (privileged)</font>.</strong><br>
Router1#<strong>traceroute 34.0.0.4</strong> Type escape sequence to abort. Tracing the route to 34.0.0.4&nbsp; &nbsp;1 12.0.0.2 4 msec 4 msec 4 msec&nbsp; &nbsp;2 23.0.0.3 20 msec 16 msec 16 msec&nbsp; &nbsp;3 34.0.0.4 16 msec *&nbsp;&nbsp;16 msec&nbsp; &nbsp;Jan 20 16:42:48.611: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.615:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=39911, dst=<strong>33434</strong>Jan 20 16:42:48.635: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:48.639:&nbsp; &nbsp;&nbsp;&nbsp;<strong>ICMP type=11, code=0</strong>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<i><font color="#0000FF">!--- ICMP Time Exceeded Message from Router2.</font></i>Jan 20 16:42:48.643: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.647:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=34237, dst=33435Jan 20 16:42:48.667: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:48.671:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=11, code=0Jan 20 16:42:48.675: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.679:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=33420, dst=33436Jan 20 16:42:48.699: IP: s=12.0.0.2 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:48.703:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=11, code=0This is the first sequence of packets we send with a TTL=1. The first router, in this case Router2 (12.0.0.2), drops the packet, and sends back to the source (12.0.0.1) a type=11 ICMP message. This corresponds to the Time Exceeded Message.<br>
Jan 20 16:42:48.707: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.711:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=35734, dst=33437Jan 20 16:42:48.743: IP: s=<strong>23.0.0.3</strong> (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3&nbsp; &nbsp;Jan 20 16:42:48.747:&nbsp; &nbsp;&nbsp;&nbsp;<strong>ICMP type=11, code=0</strong>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<i><font color="#0000FF">!--- ICMP Time Exceeded Message from Router3.</font></i>Jan 20 16:42:48.751: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.755:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=36753, dst=33438Jan 20 16:42:48.787: IP: s=23.0.0.3 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:48.791:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=11, code=0Jan 20 16:42:48.795: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.799:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=36561, dst=33439Jan 20 16:42:48.827: IP: s=23.0.0.3 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:48.831:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=11, code=0The same process occurs for Router3 (23.0.0.3) with a TTL=2:<br>
Jan 20 16:42:48.839: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.843:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=34327, dst=33440Jan 20 16:42:48.887: IP: s=<strong>34.0.0.4</strong> (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:48.891:&nbsp; &nbsp;&nbsp;&nbsp;<strong>ICMP type=3, code=3</strong><i><font color="#0000FF">!--- Port Unreachable message from Router4.</font></i>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Jan 20 16:42:48.895: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:48.899:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=37534, dst=33441Jan 20 16:42:51.895: IP: s=12.0.0.1 (local), d=34.0.0.4 (Serial0), len 28, sendingJan 20 16:42:51.899:&nbsp; &nbsp;&nbsp;&nbsp;UDP src=37181, dst=33442Jan 20 16:42:51.943: IP: s=34.0.0.4 (Serial0), d=12.0.0.1 (Serial0), len 56, rcvd 3Jan 20 16:42:51.947:&nbsp; &nbsp;&nbsp;&nbsp;ICMP type=3, code=3With a TTL=3, we finally reach Router4. This time, since the port is not valid, Router4 sends back to Router1 an ICMP message with type=3, a Destination Unreachable Message, and code=3 meaning port unreachable.<br>
The table below lists the characters that can appear in the <strong>traceroute</strong> command output.<br>
<strong>IP Traceroute Text Characters</strong><br>
Character<br>
Description<br>
nn msec<br>
For each node, the round-trip time in milliseconds for the specified number of probes<br>
*<br>
The probe timed out<br>
A<br>
Administratively prohibited (example, access-list)<br>
Q<br>
Source quench (destination too busy)<br>
I<br>
User interrupted test<br>
U<br>
Port unreachable<br>
H<br>
Host unreachable<br>
N<br>
Network unreachable<br>
P<br>
Protocol Unreachable<br>
T<br>
Timeout<br>
?<br>
Unknown packet type<br>
<font color="#000000">Performance</font> Using the <strong>ping</strong> and <strong>traceroute</strong> commands, we obtain the round-trip time (RTT). This is the time required to send an echo packet, and get an answer back. This can be useful to have a rough idea of the delay on the link. However, these figures are not precise enough to be used for performance evaluation.<br>
When a packet destination is the router itself, this packet has to be process-switched. The processor has to handle the information from this packet, and send an answer back. This is not the main goal of a router. By definition, a router is built to route packets. Answering a ping is offered as a best-effort service.<br>
To illustrate this, here is an example of a ping from Router1 to Router2:<br>
Router1#<strong>ping 12.0.0.2</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 4/4/4 ms&nbsp;&nbsp;The RTT is approximately four milliseconds. After you enable some process-intensive features on Router2, try to ping Router2 from Router1.<br>
Router1#<strong>ping 12.0.0.2</strong> Type <strong>escape sequence</strong> to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 24/25/28 msThe RTT has dramatically increased here. Router2 is quite busy, and answering the ping is not its main priority.<br>
A better way to test router performance is with traffic going <strong>through</strong> the router:<br>
<img style="CURSOR: pointer" alt="" src="http://www.cisco.com/warp/public/63/ping_traceroute4.gif" width="540" border="0" resized="true"><br>
The traffic is then fast-switched, and is handled by the router with the highest priority. To illustrate this, let us go back to our basic network:<br>
<img alt="" src="http://www.cisco.com/warp/public/63/ping_traceroute5.gif" border="0"><br>
Let us ping Router3 from Router1:<br>
Router1#<strong>ping 23.0.0.3</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 23.0.0.3, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 32/32/32 ms The traffic is going through Router2, and is now fast-switched.<br>
Now let us enable the process-intensive feature on Router2:<br>
Router1#<strong>ping 23.0.0.3</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 23.0.0.3, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 32/32/36 msThere is almost no difference. This is because, on Router2, the packets are now handled at interrupt level.<br>
<font color="#000000">Use the Debug Command</font> Before issuing <strong>debug</strong> commands, please see <font color="#0000FF">Important Information on Debug Commands</font>.<br>
The different <strong>debug</strong> commands we have used so far gives us an insight into what happens when we use a <strong>ping</strong> or <strong>traceroute</strong> command. They can also be useful for troubleshooting. However, in a production environment, debugs should be used with caution. If your CPU is not powerful, or if you have a lot of process-switched packets, they can easily stall your device. There are a couple of ways to minimize the impact of the <strong>debug</strong> command on the router. One way is to use access lists to narrow down the specific traffic that you want to monitor. Here is an example:<br>
Router4#<strong>debug ip packet ?</strong> &nbsp;&nbsp;&lt;1-199&gt;&nbsp; &nbsp;&nbsp; &nbsp;Access list&nbsp; &nbsp;&lt;1300-2699&gt;&nbsp;&nbsp;Access list (expanded range)&nbsp; &nbsp;detail&nbsp; &nbsp;&nbsp; &nbsp; Print more debugging detail&nbsp; &nbsp; Router4#<strong>configure terminal</strong>Router4(config)#<strong>access-list 150 permit ip host 12.0.0.1 host 34.0.0.4</strong> Router4(config)#^<strong>Z</strong> Router4#<strong>debug ip packet 150</strong> IP packet debugging is on for access list 150 Router4#<strong>show debug</strong> Generic IP:&nbsp; &nbsp;IP packet debugging is on for access list 150 Router4#<strong>show access-list</strong> Extended IP access list 150&nbsp; &nbsp;&nbsp;&nbsp;permit ip host 12.0.0.1 host 34.0.0.4 (5 matches) With this configuration, Router4 only prints the debug message that matches the access-list 150. A ping coming from Router1 causes the following message to be displayed:<br>
Router4# Jan 20 16:51:16.911: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:51:17.003: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:51:17.095: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:51:17.187: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:51:17.279: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3We no longer see the answer from Router4 because, these packets do not match the access-list. To see them, we should add the following:<br>
Router4(config)#<strong>access-list 150 permit ip host 12.0.0.1 host 34.0.0.4</strong> Router4(config)#<strong>access-list 150 permit ip host 34.0.0.4 host 12.0.0.1</strong> We then have:<br>
Jan 20 16:53:16.527: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:53:16.531: IP: s=34.0.0.4 (local), d=12.0.0.1 (Serial0), len 100, sendingJan 20 16:53:16.627: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:53:16.635: IP: s=34.0.0.4 (local), d=12.0.0.1 (Serial0), len 100, sendingJan 20 16:53:16.727: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:53:16.731: IP: s=34.0.0.4 (local), d=12.0.0.1 (Serial0), len 100, sendingJan 20 16:53:16.823: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:53:16.827: IP: s=34.0.0.4 (local), d=12.0.0.1 (Serial0), len 100, sendingJan 20 16:53:16.919: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3Jan 20 16:53:16.923: IP: s=34.0.0.4 (local), d=12.0.0.1 (Serial0), len 100, sendingAnother way of minimizing the impact of the <strong>debug</strong> command is to buffer the debug messages and show them using the <strong>show log</strong> command once the debug has been turned off:<br>
Router4#<strong>configure terminal</strong>Router4(config)#<strong>no logging console</strong> Router4(config)#<strong>logging buffered 5000</strong> Router4(config)#^<strong>Z</strong>&nbsp; &nbsp;Router4#<strong>debug ip packet</strong> IP packet debugging is on Router4#<strong>ping 12.0.0.1</strong> Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 12.0.0.1, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 36/36/37 ms&nbsp; &nbsp;Router4#<strong>undebug all</strong> All possible debugging has been turned off&nbsp; &nbsp;Router4#<strong>show log</strong> Syslog logging: enabled (0 messages dropped, 0 flushes, 0 overruns)&nbsp; &nbsp;&nbsp;&nbsp;Console logging: disabled&nbsp; &nbsp;&nbsp;&nbsp;Monitor logging: level debugging, 0 messages logged&nbsp; &nbsp;&nbsp;&nbsp;Buffer logging: level debugging, 61 messages logged&nbsp; &nbsp;&nbsp;&nbsp;Trap logging: level informational, 59 message lines logged Log Buffer (5000 bytes):&nbsp;&nbsp;Jan 20 16:55:46.587: IP: s=34.0.0.4 (local), d=12.0.0.1 (Serial0), len 100, sendingJan 20 16:55:46.679: IP: s=12.0.0.1 (Serial0), d=34.0.0.4 (Serial0), len 100, rcvd 3As you can see, the <strong>ping</strong> and <strong>traceroute</strong> commands are very helpful utilities that you can use to troubleshoot network access problems. They are also very easy to use. As these two commands are the most widely used commands by network engineers, understanding them is very crucial for troubleshooting network connectivity.<br>
<font color="#000000">NetPro Discussion Forums - Featured Conversations</font> Networking Professionals Connection is a forum for networking professionals to share questions, suggestions, and information about networking solutions, products, and technologies. The featured links are some of the most recent conversations available in this technology.</div> ]]></description>
		<eb:creationDate>2009-03-03 12:05:17</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(14)-TCP连接的未来和性能 ]]></title>
		<link>http://blog.tom.com/ccna/article/1849.html</link>
		<description><![CDATA[ 在TCP刚出世的时候，其主要工作环境是以太网和SLIP之类的低速网络。随着高速网络的出现，让TCP协议的吞吐量更大，效率更高的要求就愈来愈迫切。为此，TCP增加了三个重要机制来对应现在的变化，他们是<br>
<ul>
<li>路径MTU发现。</li>
<li>窗口扩大选项和时间戳。</li>
<li>T/TCP(增加了事务功能的TCP协议)。<br>
1.路径MTU发现<br>
顾名思义路径MTU指的是源主机到墓地主机之间的路径的可传送最大单元的大小。其原理同样是使用设置了不许分片的IP数据报，并等待ICMP错误，来估算MTU的大小。书中的P257介绍了TCP如何根据ICMP的报文来修改自己的MTU。具体如下：<br></li>
<li>当源主机接收到较新的ICMP差错报文时，就直接修改自己的最大发送报文段大小为发送ICMP差错报文的发送端的MTU与IP头和TCP头的差值。</li>
<li>当源主机接收到较新的ICMP差错报文时，则必须尝试下一个MTU（各种不同的网络设备都有一个MTU，各个MTU从大到小为"65535,17914,4464,4352,1500,1492,576,296"）。</li>
<li>因为路由可以动态变化，所以每隔10分钟，发送端就可以用比较大的报文来侦测一下路径MTU。<br>
2.长肥管道<br>
所谓的<b>长肥管道</b>，说的就是发送时延长，带宽宽的管道，衡量这一概念的标准是时延面积。如果碰上了网络“又长又肥”，那么网络的利用率就会大幅度的降低，普通的计时方法和窗口面积就不够用了。就需要更多的措施来弥补这个缺陷。这就是时间戳和窗口扩大选项。这些都是在经典TCP协议头之外定义的扩展选项，格式如下:<br>
<img alt="" src="http://p.blog.csdn.net/images/p_blog_csdn_net/goodboy1881/193693/o_win_option.JPG" border="0"><br>
2.1.时间戳选项<br>
用户在发送每一个TCP报文的时候都放置一个时间戳，接受方在确认中返回这个时间戳值。发送方就可以根据这个时间戳来计算RTT。从而使得RTT更加精确，减少不必要的重传。减低网络的负载。<br>
2.2.窗口扩大选项<br>
很奇怪的是为什么窗口最大的扩展量只有14而不是64。因为毕竟窗口扩大选项有一个字节那么长的数据可以用，不过，不管怎么样，还是记住为好。窗口扩大选项可以让窗口扩大到2的30次方。这就几乎完美的解决了肥管道的问题。<br></li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:35:00</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(13)-TCP坚持定时器，TCP保活定时器 ]]></title>
		<link>http://blog.tom.com/ccna/article/1848.html</link>
		<description><![CDATA[ TCP一共有四个主要的定时器，前面已经讲到了一个－－超时定时器－－是TCP里面最复杂的一个，另外的三个是：<br>
<ul>
<li>坚持定时器</li>
<li>保活定时器</li>
<li>2MSL定时器<br>
其中坚持定时器用于防止通告窗口为0以后双方互相等待死锁的情况；而保活定时器则用于处理半开放连接<br>
1.坚持定时器<br>
坚持定时器的原理是简单的，当TCP服务器收到了客户端的0滑动窗口报文的时候，就启动一个定时器来计时，并在定时器溢出的时候向向客户端查询窗口<br>
是否已经增大，如果得到非零的窗口就重新开始发送数据，如果得到0窗口就再开一个新的定时器准备下一次查询。通过观察可以得知，TCP的坚持定时器使用<br>
1，2，4，8，16……64秒这样的普通指数退避序列来作为每一次的溢出时间。<br>
<b>糊涂窗口综合症</b><br>
TCP的窗口协议，会引起一种通常叫做糊涂窗口综合症的问题，具体表现为，当客户端通告一个小的非零窗口时，服务器立刻发送小数据给客户端并充满其<br>
缓冲区，一来二去就会让网络中充满小TCP数据报，从而影响网络利用率。对于发送方和接收端的这种糊涂行为。TCP给出了一些建议（或者是规定）。<br></li>
<li>接收方不通告小窗口。通常的算法是接收方不通告一个比当前窗口大的窗口（可以为0），<br>
除非窗口可以增加一个报文段大小（也就是将要接收的MSS）或者可以增加接收方缓存空间<br>
的一半，不论实际有多少。</li>
<li>发送方避免出现糊涂窗口综合症的措施是只有以下条件之一满足时才发送数据： ( a )可<br>
以发送一个满长度的报文段； ( b )可以发送至少是接收方通告窗口大小一半的报文段； ( c )可以<br>
发送任何数据并且不希望接收ACK（也就是说，我们没有还未被确认的数据）或者该连接上<br>
不能使用Nagle算法。<br>
ok，现在我们回忆一下，可以发现TCP的很多规定都是为了在一次传送中发送尽量多的数据，例如捎带ACK数据报文的策略，Nagle算法，重传时发送包含原数据报文的策略，等等。<br>
2.保活定时器<br>
保活定时器更加的简单，还记得FTP或者Http服务器都有Sesstion<br>
Time机制么？因为TCP是面向连接的，所以就会出现只连接不传送数据的“半开放连接”，服务器当然要检测到这种连接并且在某些情况下释放这种连接，这<br>
就是保活定时器的作用。其时限根据服务器的实现不同而不通。另外要提到的是，当其中一端如果崩溃并重新启动的情况下，如果收到该端“前生”的保活探察，则<br>
要发送一个RST数据报文帮助另一端结束连接</li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:34:07</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(12)-TCP的超时与重传 ]]></title>
		<link>http://blog.tom.com/ccna/article/1847.html</link>
		<description><![CDATA[ 超时重传是TCP协议保证数据可靠性的另一个重要机制，其原理是在发送某一个数据以后就开启一个计时器，在一定时间内如果没有得到发送的数据报的ACK报文，那么就重新发送数据，直到发送成功为止。<br>
1.超时<br>
超时时间的计算是超时的核心部分，TCP要求这个算法能大致估计出当前的网络状况，虽然这确实很困难。要求精确的原因有两个：(1)定时长久会造成网络利用率不高。(2)定时太短会造成多次重传，使得网络阻塞。所以，书中给出了一套<b>经验</b>公式，和其他的保证计时器准确的措施。<br>
1.1.递推公式概说<br>
最早的TCP曾经用了一个非常简单的公式来估计当前网络的状况，如下<br>
R RTP=Rb<br>
其中a是一个经验系数为0.1，b通常为2。注意，这是经验，没有推导过程，这个数值是可以被修改的。这个公式是说用旧的RTT(R)和新的<br>
RTT(M)综合到一起来考虑新的RTT(R)的大小。但是，我们又看到，这种估计在网络变化很大的情况下完全不能做出“灵敏的反应<br>
”（Jacoboson说的，不是偶说的，呵呵），于是就有下面的修正公式：<br>
Err=M-A A D RTO=A+4D<br>
具体的解释请看书的228页，这个递推公式甚至把方差这种统计概念也使用了进来，使得偏差更加的小。而且，必须要指出的是，这两组公式更新，都是在<br>
数据成功传输的情况下才进行，在发生数据重新传输的情况下，并不使用上面的公式进行网络估计，理由很简单，因为程序已经不在正常状态下了，估计出来的数据<br>
也是没有意义的。<br>
1.2.RTO的初始化<br>
RTO的初始化是由公式决定的，例如最初的公式，初始的值应该是1。而修正公式，初始RTO应该是A+4D。<br>
1.3.RTO的更新<br>
当数据正常传输的情况下，我们就会用上面的公式来更新各个数据，并重开定时器，来保证下一个数据被顺利传输。要注意的是：<b>重传的情况下，RTO不用上面的公式计算，而采用一种叫做“指数退避”的方式。</b>例如：当RTO为1S的情况下，发生了数据重传，我们就用RTO=2S的定时器来重新传输数据，下一次用4S。一直增加到64S为止。<br>
1.4.估计器的初始化<br>
在这里，SYN用的估计器初始化似乎和传输用的估计器不一样（我也没有把握）造我的理解，在修正公式中，SYN的情况下，A初始化为0,D初始化为3S。<br>
而在得到传输第一个数据的ACK的时候，应该按照下面的公式进行初始化：<br>
A=M+0.5 D=A/2<br>
1.5.估计器的更新<br>
和上面的讨论差不多，就是在正常情况下，用上面的公式计算，在重传的情况下，<b>不更新估计器的各种参数。</b>原因还是因为估计不准确。<br>
1.6.Karn算法<br>
这不算是一个算法，这应该是一个策略，说的就是更新RTO和估计器的值的时机选择问题，1.3.和1.5.所说得更新时机就是Karn算法。<br>
1.7.计时器的使用<br>
两句话:<br>
<ul>
<li>一个连接中，有且仅有一个测量定时器被使用。也就是说，如果TCP连续发出3组数据，只有一组数据会被测量。</li>
<li>ACK数据报不会被测量，原因很简单，没有ACK的ACK回应可以供结束定时器测量。<br>
2.重传<br>
有了超时就要有重传，但是就算是重传也是有策略的，而不是将数据简单的发送。<br>
2.1.重传时发送数据的大小<br>
前面曾经提到过，数据在传输的时候不能只使用一个窗口协议，我们还需要有一个拥塞窗口来控制数据的流量，使得数据不会一下子都跑到网路中引起“拥塞<br>
”。也曾经提到过，拥塞窗口最初使用指数增长的速度来增加自身的窗口，直到发生超时重传，再进行一次微调。但是没有提到，如何进行微调，拥塞避免算法和慢<br>
启动门限就是为此而生。<br>
所谓的慢启动门限就是说，当拥塞窗口超过这个门限的时候，就使用拥塞避免算法，而在门限以内就采用慢启动算法。所以这个标准才叫做<b>门限</b>，通常，拥塞窗口记做cwnd，慢启动门限记做ssthresh。下面我们来看看拥塞避免和慢启动是怎么一起工作的<br>
算法概要(直接从书中拷贝)<br></li>
<li>对一个给定的连接，初始化cwnd为1个报文段，ssthresh为65535个字节。</li>
<li>TCP输出例程的输出不能超过cwnd和接收方通告窗口的大小。拥塞避免是发送方使用 的流量控制，而通告窗口则是接收方进行的流量控制。前者是发送方感受到的网络拥塞的估 计，而后者则与接收方在该连接上的可用缓存大小有关。</li>
<li>当拥塞发生时（超时或收到重复确认），ssthresh被设置为当前窗口大小的一半（cwnd 和接收方通告窗口大小的最小值，但最少为2个报文段）。此外，如果是超时引起了拥塞，则 cwnd被设置为1个报文段（这就是慢启动）。</li>
<li>当<br>
新的数据被对方确认时，就增加cwnd，但增加的方法依赖于我们是否正在进行慢启<br>
动或拥塞避免。如果cwnd小于或等于ssthresh，则正在进行慢启动，否则正在进行拥塞避免。<br>
慢启动一直持续到我们回到当拥塞发生时所处位置的半时候才停止（因为我们记录了在步骤2 中给我们制造麻烦的窗口大小的一半），然后转为执行拥塞避免。<br>
补充上面的拥塞避免公式在P238页。这整个的流程让我联想到开车换档的过程。<br>
2.2.快速重传和快速恢复算法<br>
这是数据丢包的情况下给出的一种修补机制。一般来说，重传发生在超时之后，但是如果发送端接受到3个以上的重复ACK的情况下，就应该意识到，数据丢了，需要重新传递。这个机制是不需要等到重传定时器溢出的，所以叫做<b>快速重传</b>，而重新传递以后，因为走的不是<b>慢启动</b>而是<b>拥塞避免算法</b>，所以这又叫做<b>快速恢复算法</b>。流程如下：<br></li>
<li>当收到第3个重复的ACK时，将ssthresh设置为当前拥塞窗口cwnd的一半。重传丢失的 报文段。设置cwnd为ssthresh加上3倍的报文段大小。</li>
<li>每次收到另一个重复的ACK时， cwnd增加1个报文段大小并发送1个分组（如果新的 cwnd允许发送）。</li>
<li>当<br>
下一个确认新数据的ACK到达时，设置cwnd为ssthresh（在第1步中设置的值）。这个<br>
ACK应该是在进行重传后的一个往返时间内对步骤1中重传的确认。另外，这个ACK也应该<br>
是对丢失的分组和收到的第1个重复的ACK之间的所有中间报文段的确认。这一步采用的是拥 塞避免，因为当分组丢失时我们将当前的速率减半。<br>
2.3.ICMP会引起重新传递么？<br>
答案是：<b>不会</b>，TCP会坚持用自己的定时器，但是TCP会保留下ICMP的错误并且通知用户。<br>
2.4.重新分组<br>
TCP为了提高自己的效率，允许再重新传输的时候，只要传输包含重传数据报文的报文就可以，而不用只重传需要传输的报文。<br></li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:33:25</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(10)-TCP连接的建立与中止 ]]></title>
		<link>http://blog.tom.com/ccna/article/1846.html</link>
		<description><![CDATA[ TCP是一个面向连接的协议，所以在连接双方发送数据之前，都需要首先建立一条连接。这和前面讲到的协议完全不同。前面讲的所有协议都只是发送数据<br>
而已，大多数都不关心发送的数据是不是送到，UDP尤其明显，从编程的角度来说，UDP编程也要简单的多----UDP都不用考虑数据分片。<br>
书中用telnet登陆退出来解释TCP协议连接的建立和中止的过程，可以看到，TCP连接的建立可以简单的称为<b>三次握手</b>，而连接的中止则可以叫做<b>四次握手</b>。<br>
1.连接的建立<br>
在建立连接的时候，客户端首先向服务器申请打开某一个端口(用SYN段等于1的TCP报文)，然后服务器端发回一个ACK报文通知客户端请求报文收<br>
到，客户端收到确认报文以后再次发出确认报文确认刚才服务器端发出的确认报文（绕口么），至此，连接的建立完成。这就叫做三次握手。如果打算让双方都做好<br>
准备的话，一定要发送三次报文，而且只需要三次报文就可以了。<br>
可以想见，如果再加上TCP的超时重传机制，那么TCP就完全可以保证一个数据包被送到目的地。<br>
2.结束连接<br>
TCP有一个特别的概念叫做half-close，这个概念是说，TCP的连接是全双工（可以同时发送和接收）连接，因此在关闭<br>
连接的时候，必须关闭传和送两个方向上的连接。客户机给服务器一个FIN为1的TCP报文，然后服务器返回给客户端一个确认ACK报文，并且发送一个<br>
FIN报文，当客户机回复ACK报文后（四次握手），连接就结束了。<br>
3.最大报文长度<br>
在建立连接的时候，通信的双方要互相确认对方的最大报文长度(MSS)，以便通信。一般这个SYN长度是MTU减去固定IP首部和TCP首部长度。<br>
对于一个以太网，一般可以达到1460字节。当然如果对于非本地的IP，这个MSS可能就只有536字节，而且，如果中间的传输网络的MSS更佳的小的<br>
话，这个值还会变得更小。<br>
4.TCP的状态迁移图<br>
书P182页给出了TCP的状态图，这是一个看起来比较复杂的状态迁移图，因为它包含了两个部分---服务器的状态迁移和客户端的状态迁移，如果从<br>
某一个角度出发来看这个图，就会清晰许多，这里面的服务器和客户端都不是绝对的，发送数据的就是客户端，接受数据的就是服务器。<br>
4.1.客户端应用程序的状态迁移图<br>
客户端的状态可以用如下的流程来表示：<br>
CLOSED-&gt;SYN_SENT-&gt;ESTABLISHED-&gt;FIN_WAIT_1-&gt;FIN_WAIT_2-&gt;TIME_WAIT-&gt;CLOSED<br>
以上流程是在程序正常的情况下应该有的流程，从书中的图中可以看到，在建立连接时，当客户端收到SYN报文的ACK以后，客户端就打开了数据交互地<br>
连接。而结束连接则通常是客户端主动结束的，客户端结束应用程序以后，需要经历FIN_WAIT_1，FIN_WAIT_2等状态，这些状态的迁移就是前<br>
面提到的结束连接的四次握手。<br>
4.2.服务器的状态迁移图<br>
服务器的状态可以用如下的流程来表示：<br>
CLOSED-&gt;LISTEN-&gt;SYN收到-&gt;ESTABLISHED-&gt;CLOSE_WAIT-&gt;LAST_ACK-&gt;CLOSED<br>
在建立连接的时候，服务器端是在第三次握手之后才进入数据交互状态，而关闭连接则是在关闭连接的第二次握手以后（注意不是第四次）。而关闭以后还要等待客户端给出最后的ACK包才能进入初始的状态。<br>
4.3.其他状态迁移<br>
书中的图还有一些其他的状态迁移，这些状态迁移针对服务器和客户端两方面的总结如下<br>
<br>
<ul>
<li>LISTEN-&gt;SYN_SENT，对于这个解释就很简单了，服务器有时候也要打开连接的嘛。</li>
<li>SYN_SENT-&gt;SYN收到，服务器和客户端在SYN_SENT状态下如果收到SYN数据报，则都需要发送SYN的ACK数据报并把自己的状态调整到SYN收到状态，准备进入ESTABLISHED</li>
<li>SYN_SENT-&gt;CLOSED，在发送超时的情况下，会返回到CLOSED状态。</li>
<li>SYN_收到-&gt;LISTEN，如果受到RST包，会返回到LISTEN状态。</li>
<li>SYN_收到-&gt;FIN_WAIT_1，这个迁移是说，可以不用到ESTABLISHED状态，而可以直接跳转到FIN_WAIT_1状态并等待关闭。<br>
4.4.2MSL等待状态<br>
书中给的图里面，有一个TIME_WAIT等待状态，这个状态又叫做2MSL状态，说的是在TIME_WAIT2发送了最后一个ACK数据报以后，<br>
要进入TIME_WAIT状态，这个状态是防止最后一次握手的数据报没有传送到对方那里而准备的（注意这不是四次握手，这是第四次握手的保险状态）。这个<br>
状态在很大程度上保证了双方都可以正常结束，但是，问题也来了。<br>
由于插口的2MSL状态（插口是IP和端口对的意思，socket），使得应用程序在2MSL时间内是无法再次使用同一个插口的，对于客户程序还好<br>
一些，但是对于服务程序，例如httpd，它总是要使用同一个端口来进行服务，而在2MSL时间内，启动httpd就会出现错误（插口被使用）。为了避免<br>
这个错误，服务器给出了一个平静时间的概念，这是说在2MSL时间内，虽然可以重新启动服务器，但是这个服务器还是要<b>平静</b>的等待2MSL时间的过去才能进行下一次连接。<br>
4.5.FIN_WAIT_2状态<br>
这就是著名的半关闭的状态了，这是在关闭连接时，客户端和服务器两次握手之后的状态。在这个状态下，应用程序还有接受数据的能力，但是已经无法发送<br>
数据，但是也有一种可能是，客户端一直处于FIN_WAIT_2状态，而服务器则一直处于WAIT_CLOSE状态，而直到应用层来决定关闭这个状态。<br>
5.RST，同时打开和同时关闭<br>
RST是另一种关闭连接的方式，应用程序应该可以判断RST包的真实性，即是否为异常中止。而同时打开和同时关闭则是两种特殊的TCP状态，发生的概率很小。<br>
6.TCP服务器设计<br>
前面曾经讲述过UDP的服务器设计，可以发现UDP的服务器完全不需要所谓的并发机制，它只要建立一个数据输入队列就可以。但是TCP不同，TCP<br>
服务器对于每一个连接都需要建立一个独立的进程（或者是轻量级的，线程），来保证对话的独立性。所以TCP服务器是并发的。而且TCP还需要配备一个呼入<br>
连接请求队列（UDP服务器也同样不需要），来为每一个连接请求建立对话进程，这也就是为什么各种TCP服务器都有一个最大连接数的原因。而根据源主机的<br>
IP和端口号码，服务器可以很轻松的区别出不同的会话，来进行数据的分发。<br>
掌握本章的状态迁移图才是学习本章的关键。<br></li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:32:40</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(9)-TCP协议概述 ]]></title>
		<link>http://blog.tom.com/ccna/article/1845.html</link>
		<description><![CDATA[ 终于看到了TCP协议，这是TCP/IP详解里面最重要也是最精彩的部分，要花大力气来读。前面的TFTP和BOOTP都是一些简单的协议，就不写笔记了，写起来也没啥东西。<br>
TCP和UDP处在同一层---运输层，但是TCP和UDP最不同的地方是，TCP提供了一种可靠的数据传输服务，TCP是面向连接的，也就是说，<br>
利用TCP通信的两台主机首先要经历一个“拨打电话”的过程，等到通信准备结束才开始传输数据，最后结束通话。所以TCP要比UDP可靠的多，UDP是把<br>
数据直接发出去，而不管对方是不是在收信，就算是UDP无法送达，也不会产生ICMP差错报文，这一经时重申了很多遍了。<br>
把TCP保证可靠性的简单工作原理摘抄如下<br>
<ul>
<li>应用数据被分割成TCP认为最适合发送的数据块。这和UDP完全不同，应用程序产生的 数据报长度将保持不变。由TCP传递给IP的信息单位称为报文段或段（ segment）（参见图1 - 7）。在1 8.4节我们将看到TCP如何确定报文段的长度。</li>
<li>当TCP发出一个段后，它启动一个定时器，等待目的端确认收到这个报文段。如果不能 及时收到一个确认，将重发这个报文段。在第21章我们将了解TCP协议中自适应的超时 及重传策略。</li>
<li>当TCP收到发自TCP连接另一端的数据，它将发送一个确认。这个确认不是立即发送，通常将推迟几分之一秒，这将在1 9.3节讨论。</li>
<li>TCP将保持它首部和数据的检验和。这是一个端到端的检验和，目的是检测数据在传输 过程中的任何变化。如果收到段的检验和有差错， T P将丢弃这个报文段和不确认收到此报文段（希望发端超时并重发）。</li>
<li>既然TCP报文段作为IP数据报来传输，而IP数据报的到达可能会失序，因此TCP报文段 的到达也可能会失序。如果必要， TCP将对收到的数据进行重新排序，将收到的数据以正确的顺序交给应用层。</li>
<li>TCP还能提供流量控制。TCP连接的每一方都有固定大小的缓冲空间。TCP的接收端只允许另一端发送接收端缓冲区所能接纳的数据。这将防止较快主机致使较慢主机的缓冲区溢出。</li>
</ul>
<br>
从这段话中可以看到，TCP中保持可靠性的方式就是超时重发，这是有道理的，虽然TCP也可以用各种各样的ICMP报文来处理这些，但是这也不是可靠的，<b>最可靠的方式就是只要不得到确认，就重新发送数据报，直到得到对方的确认为止。</b><br>
TCP的首部和UDP首部一样，都有发送端口号和接收端口号。但是显然，TCP的首部信息要比UDP的多，可以看到，TCP协议提供了发送和确认所需要的所有必要的信息。这在P171-173有详细地介绍。可以想象一个TCP数据的发送应该是如下的一个过程。<br>
<ul>
<li>双方建立连接</li>
<li>发送方给接受方TCP数据报，然后等待对方的确认TCP数据报，如果没有，就重新发，如果有，就发送下一个数据报。</li>
<li>接受方等待发送方的数据报，如果得到数据报并检验无误，就发送ACK(确认)数据报，并等待下一个TCP数据报的到来。直到接收到FIN(发送完成数据报)</li>
<li>中止连接</li>
</ul>
<br>
可以想见，为了建立一个TCP连接，系统可能会建立一个新的进程（最差也是一个线程），来进行数据的传送 ]]></description>
		<eb:creationDate>2008-10-20 19:31:22</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(8)-DNS域名系统 ]]></title>
		<link>http://blog.tom.com/ccna/article/1844.html</link>
		<description><![CDATA[ 前面已经提到了访问一台机器要靠IP地址和MAC地址，其中，MAC地址可以通过ARP协议得到，所以这对用户是透明的，但是IP地址就不行，无论如何用户都需要用一个指定的IP来访问一台计算机，而IP地址又非常不好记，于是就出现了DNS系统<br>
1.DNS系统介绍<br>
DNS的全称是Domain Name<br>
System。它负责把FQDN(就是以"."分隔结尾的名字)翻译成一个IP。最初的DNS系统使用的是一个巨大的hosts.txt文件（很吃惊，用<br>
这个就好使了？），可是一段时间以后，开发这就不得不用数据库来代替hosts.txt文件，最终发展到了现在的分布式数据库。<br>
从书中的143页可以看到，DNS系统是一个巨大的树，最上方有一个无名树根，下一层是arpa,com,edu,gov,int,mil，us,<br>
cn。等等，其中arpa，是域名反解析树的顶端；而com，edu，等域名本来只用在美国（这就是技术特权啊），但是现在几乎全世界通用；而us，<br>
cn，等叫做国家域。这个树里面的域名并不是统一管理的，网络信息中心（NIS）负责分配顶级域合委派其他制定地区域的授权机构。<br>
一个独立管理的DNS子树叫做<b>zone</b>，最常见的区域就是二级域名，比如说.com.cn。我们还可以把这个二级域名给划分成更小的区域，比如说sina.com.cn。<br>
DNS系统是一个分布式的数据库，当一个数据库发现自己并没有某查询所需要的数据的时候，它将把查询转发出去，而转发的目的地通常是根服务器，根服<br>
务器从上至下层层转发查询，直到找到目标为止。DNS还有一个特点就是使用高速缓存，DNS把查询过的数据缓存在某处，以便于下次查询时使用。<br>
2.DNS协议<br>
DNS报文定义了一个既可以查询也可以响应的报文格式。具体格式可以看P145页。对各个字段简单解释如下<br>
<ul>
<li>最前面的16个bit唯一的标示了问题号码，用于查询端区别自己的查询。</li>
<li>紧接着的16个bit又可以做进一步的细分，标示了报文的性质和一些细节，比如说是查询报文还是响应报文，需要递归查询与否（一般服务器都支持递归查询，而且不需要任何设置，BIND就是这样）</li>
<li>查询问题后面有查询类型，包括A，NS，CNAME，PTR，HINFO，MX，如果熟悉BIND的话，就知道在zong的配置文件里面，每一条记录都记载了各自的类型，比如A就是IP地址，NS就是名字服务器。</li>
<li>响应报文可以回复多个IP，也就是说，域名可以和多个IP地址对应，并且有很多CNAME。<br>
3.反向查询<br>
正向查询指的是通过域名得到IP的查询，而反向查询就是通过IP得到域名。例如用<b>host</b>命令，<b>host ip</b>就可以得到服务器的域名，<b>host domainName</b> 就得到IP。<br>
稍微知道一点数据结构的人都能意识到，在正向查询的域里面做反向查询，其做法只有遍历整个数据集合----对于DNS来说，那就是遍历整个数据库，<br>
这将带来巨大的负担，所以DNS采取了另一种方法，使用另一棵子树来维护IP-〉域名的对应表。这个子树的根节点是in-addr.arpa,而一个IP<br>
例如192.168.11.2)所具有的DNS地址就是<br>
2.11.168.192.in-addr.arpa（ip倒置）。在DNS系统里面，一个反向地址对应一个PTR纪录（对应A纪录），所以反向查询又叫<br>
做指针(PTR)查询。<br>
4.其他问题的讨论<br>
4.1.DNS服务器高速缓存<br>
BIND9默认是作为一个高速缓存服务器，其将所有的查询都转交到根服务器去，然后得到结果并放在本地的缓冲区，以加快查询速度。如果有兴趣可以安装一个BIND9来尝试一下。而自己定义的zone则可以规定其在缓存中的时间，一般是1天（就是配置文件中的1D）。<br>
4.2.用UDP还是TCP<br>
DNS服务器支持TCP和UDP两种协议的查询方式，而且端口都是53。而大多数的查询都是UDP查询的，一般需要TCP查询的有两种情况：<br></li>
<li>当查询数据多大以至于产生了数据截断(TC标志为1)，这时，需要利用TCP的分片能力来进行数据传输（看TCP的相关章节）。</li>
<li>当主（master）服务器和辅（slave）服务器之间通信，辅服务器要拿到主服务器的zone信息的时候。<br>
完</li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:30:40</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(7)-广播和多播，IGMP协议 ]]></title>
		<link>http://blog.tom.com/ccna/article/1843.html</link>
		<description><![CDATA[ 1.单播，多播，广播的介绍<br>
1.1.单播(unicast)<br>
单播是说，对特定的主机进行数据传送。例如给某一个主机发送IP数据包。这时候，数据链路层给出的数据头里面是非常具体的目的地址，对于以太网来<br>
说，就是网卡的MAC地址（不是FF-FF-FF-FF-FF-FF这样的地址）。现在的具有路由功能的主机应该可以将单播数据定向转发，而目的主机的网<br>
络接口则可以过滤掉和自己MAC地址不一致的数据。<br>
1.2.广播(unicast)<br>
广播是主机针对某一个网络上的所有主机发送数据包。这个网络可能是网络，可能是子网，还可能是所有的子网。如果是网络，例如A类网址的广播就是<br>
netid.255.255.255，如果是子网，则是netid.netid.subnetid.255；如果是所有的子网（B类IP）则是则是<br>
netid.netid.255.255。广播所用的MAC地址FF-FF-FF-FF-FF-FF。网络内所有的主机都会收到这个广播数据，网卡只要把<br>
MAC地址为FF-FF-FF-FF-FF-FF的数据交给内核就可以了。一般说来ARP，或者路由协议RIP应该是以广播的形式播发的。<br>
1.3.多播(multicast)<br>
可以说广播是多播的特例，多播就是给一组特定的主机（多播组）发送数据，这样，数据的播发范围会小一些(实际上播发的范围一点也没有变小)，多播的<br>
MAC地址是最高字节的低位为一，例<br>
如01-00-00-00-00-00。多播组的地址是D类IP，规定是224.0.0.0-239.255.255.255。<br>
虽然多播比较特殊，但是究其原理，多播的数据还是要通过数据链路层进行MAC地址绑定然后进行发送。所以一个以太网卡在绑定了一个多播IP地址之<br>
后，必<br>
定还要绑定一个多播的MAC地址，才能使得其可以像单播那样工作。这个多播的IP和多播MAC地址有一个对应的算法，在书的p133到p134之间。可以<br>
看到 这个对应不是一一对应的，主机还是要对多播数据进行过滤。<br>
个人的看法：广播和多播的性质是一样的，路由器会把数据放到局域网里面，然后网卡对这些数据进行过滤，只拿到自己打算要的数据，比如自己感兴趣的多<br>
播数据，自己感兴趣的组播数据。当一个主机运行了一个处理某一个多播IP的进程的时候，这个进程会给网卡绑定一个虚拟的多播mac地址，并做出来一个多播<br>
ip。这样，网卡就会让带有这个多播mac地址的数据进来，从而实现通信，而那些没有监听这些数据的主机就会把这些数据过滤掉，换句话说，多播，是让主机<br>
的内核轻松了，而网卡，对不起，您就累点吧。<br>
一些文章也印证了这种想法，最明显的就是<br>
<a href="http://news.softhouse.com.cn/news/show/440.html" target="_blank">局域网监听的原理、实现与防范</a><br>
2.一些验证性实验<br>
这些实验并不是很复杂，我们只是要ping一下一般的ip和一个广播地址。首先我ping一下自己所在的子网的某一台主机:<br>
Reply from 192.168.11.1: bytes=32 time<br>
可以看到，机器返回的是一台主机的回应结果，进而推测，如果我ping一个广播地址呢？结果如下<br>
Reply from 192.168.11.9: bytes=32 time=1ms TTL=255<br>
Reply from 192.168.11.174: bytes=32 time<br>
可以看到，ping返回了一些随机的ip的结果，这些ip都是与主机在同一子网内的ip。我们可以看到，广播实际上是给处于子网内的所有ip发信。<br>
再来一个多播的例子，但是要实现这个多播并不容易，因为我不知道网络内有多少个多播组，就只好利用几个特殊的多播地址来验证了。<br>
对于多播地址，有几个特殊的多播地址被占用，他们是<br>
<ul>
<li>224.0.0.1--该子网内所有的系统组。</li>
<li>224.0.0.2--该子网内所有的路由器。</li>
<li>224.0.1.1--网络实现协议NTP专用IP。</li>
<li>224.0.0.9--RIPv2专用IP<br>
所以只要ping这几个IP，就应该能得到一些结果，比如说我ping 224.0.0.2。<br>
&nbsp;&nbsp;Reply from 192.168.11.1: bytes=32 time<br>
我们可以看到，这回ping只返回了一个ip的回应。而这个就是我的网关的地址，这也验证了224.0.0.2是所有路由器的多播(组播)地址<br>
3.IGMP协议<br>
IGMP的作用在于，让其他所有需要知道自己处于哪个多播组的主机和路由器知道自己的状态。一般多播路由器根本不需要知道某一个多播组里面有多少个<br>
主机，而只要知道自己的子网内还有没有处于某个多播组的主机就可以了。只要某一个多播组还有一台主机，多播路由器就会把数据传输出去，这样，接受方就会通<br>
过网卡过滤功能来得到自己想要的数据。为了知道多播组的信息，多播路由器需要定时的发送IGMP查询，IGMP的格式可以看书，各个多播组里面的主机要根<br>
据查询来回复自己的状态。路由器来决定有几个多播组，自己要对某一个多播组发送什么样的数据。<br>
这种查询回应数据报的TTL一般是1，而且就算是出错也不产生ICMP差错（没必要）。</li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:29:59</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(6)-UDP协议 ]]></title>
		<link>http://blog.tom.com/ccna/article/1842.html</link>
		<description><![CDATA[ <table cellspacing="0" cellpadding="0" width="660" align="center" border="0">
<tbody>
<tr>
<td height="8">&nbsp;</td>
</tr>
<tr>
<td height="30"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td align="middle" height="40"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td><br>
2.UDP协议头<br>
2.1.UDP端口号<br>
由于很多软件需要用到UDP协议，所以UDP协议必须通过某个标志用以区分不同的程序所需要的数据包。端口号的功能就在于此，例如某一个UDP程序<br>
A在系统中注册了3000端口，那么，以后从外面传进来的目的端口号为3000的UDP包都会交给该程序。端口号理论上可以有2^16这么多。因为它的长<br>
度是16个bit<br>
2.2.UDP检验和<br>
这是一个可选的选项，并不是所有的系统都对UDP数据包加以检验和数据(相对TCP协议的必须来说)，但是RFC中标准要求，发送端应该计算检验和。<br>
UDP检验和覆盖UDP协议头和数据，这和IP的检验和是不同的，IP协议的检验和只是覆盖IP数据头，并不覆盖所有的数据。UDP和TCP都包含<br>
一个伪首部，这是为了计算检验和而摄制的。伪首部甚至还包含IP地址这样的IP协议里面都有的信息，目的是让UDP两次检查数据是否已经正确到达目的地。<br>
如果发送端没有打开检验和选项，而接收端计算检验和有差错，那么UDP数据将会被悄悄的丢掉（不保证送达），而不产生任何差错报文。<br>
2.3.UDP长度<br>
UDP可以很长很长，可以有65535字节那么长。但是一般网络在传送的时候，一次一般传送不了那么长的协议（涉及到MTU的问题），就只好对数据<br>
分片，当然，这些是对UDP等上级协议透明的，UDP不需要关心IP协议层对数据如何分片，下一个章节将会稍微讨论一些分片的策略。<br>
3.IP分片<br>
IP在从上层接到数据以后，要根据IP地址来判断从那个接口发送数据（通过选路），并进行MTU的查询，如果数据大小超过MTU就进行数据分片。数<br>
据的分片是对上层和下层透明，而数据也只是到达目的地还会被重新组装，不过不用担心，IP层提供了足够的信息进行数据的再组装。<br>
在IP头里面，16bit识别号唯一记录了一个IP包的ID,具有同一个ID的IP片将会被重新组装；而13位片偏移则记录了某IP片相对整个包的<br>
位置；而这两个表示中间的3bit标志则标示着该分片后面是否还有新的分片。这三个标示就组成了IP分片的所有信息，接受方就可以利用这些信息对IP数据<br>
进行重新组织（就算是后面的分片比前面的分片先到，这些信息也是足够了）。<br>
因为分片技术在网络上被经常的使用，所以伪造IP分片包进行流氓攻击的软件和人也就层出不穷。<br>
可以用Trancdroute程序来进行简单的MTU侦测。请参看教材。<br>
3.UDP和ARP之间的交互式用<br>
这是不常被人注意到的一个细节，这是针对一些系统地实现来说的。当ARP缓存还是空的时候。UDP在被发送之前一定要发送一个ARP请求来获得目的<br>
主机的MAC地址，如果这个UDP的数据包足够大，大到IP层一定要对其进行分片的时候，想象中，该UDP数据包的第一个分片会发出一个ARP查询请求，<br>
所有的分片都辉等到这个查询完成以后再发送。事实上是这样吗？<br>
结果是，某些系统会让每一个分片都发送一个ARP查询，所有的分片都在等待，但是接受到第一个回应的时候，主机却只发送了最后一个数据片而抛弃了其<br>
他，这实在是让人匪夷所思。这样，因为分片的数据不能被及时组装，接受主机将会在一段时间内将永远无法组装的IP数据包抛弃，并且发送组装超时的ICMP<br>
报文（其实很多系统不产生这个差错），以保证接受主机自己的接收端缓存不被那些永远得不到组装的分片充满。<br>
4.ICMP源站抑制差错<br>
当目标主机的处理速度赶不上数据接收的速度，因为接受主机的IP层缓存会被占满，所以主机就会发出一个“我受不了”的一个ICMP报文。<br>
5.UDP服务器设计<br>
UDP协议的某些特性将会影响我们的服务器程序设计，大致总结如下：<br>
<ul>
<li>关于客户IP和地址：服务器必须有根据客户IP地址和端口号判断数据包是否合法的能力（这似乎要求每一个服务器都要具备）</li>
<li>关于目的地址：服务器必须要有过滤广播地址的能力。</li>
<li>关于数据输入：通常服务器系统的每一个端口号都会和一块输入缓冲区对应，进来的输入根据先来后到的原则等待服务器的处理，所以难免会出现缓冲区溢出的问题，这种情况下，UDP数据包可能会被丢弃，而应用服务器程序本身并不知道这个问题。</li>
<li>服务器应该限制本地IP地址，就是说它应该可以把自己绑定到某一个网络接口的某一个端口上。</li>
</ul>
</td>
</tr>
</tbody>
</table> ]]></description>
		<eb:creationDate>2008-10-20 19:28:59</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(5)-IP选路，动态选路，和一些细节 ]]></title>
		<link>http://blog.tom.com/ccna/article/1841.html</link>
		<description><![CDATA[ <table cellspacing="0" cellpadding="0" width="660" align="center" border="0">
<tbody>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td metric="" use="" iface=""><br>
192.168.11.0&nbsp; &nbsp; *&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;255.255.255.0&nbsp; &nbsp;U&nbsp; &nbsp;&nbsp;&nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;0 eth0<br>
169.254.0.0&nbsp; &nbsp;&nbsp;&nbsp;*&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;255.255.0.0&nbsp; &nbsp;&nbsp;&nbsp;U&nbsp; &nbsp;&nbsp;&nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;0 eth0<br>
default&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;192.168.11.1&nbsp; &nbsp; 0.0.0.0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;UG&nbsp; &nbsp; 0&nbsp; &nbsp;&nbsp; &nbsp;0&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;0 eth0<br>
<br>
对于一个给定的路由器，可以打印出五种不同的flag。<br>
<ul>
<li>U表明该路由可用。</li>
<li>G表明该路由是到一个网关。如果没有这个标志，说明和Destination是直连的，而相应的Gateway应该直接给出Destination的地址。</li>
<li>H表明该路由是到一个主机，如果没有该标志，说明Destination是一个网络，换句话说Destination就应该写成一个网络号和子网号的组合，而不包括主机号(主机号码处为0)，例如 192.168.11.0</li>
<li>D表明该路由是为重定向报文创建的</li>
<li>M该路由已经被重定向报文修改<br>
U没啥可说的，G说明这是一个网关，如果你要发数据给Destination，IP头应该写Destination的IP地址，而数据链路层的<br>
MAC地址就应该是GateWay的Mac地址了；反之，如果没有G标志，那么数据链路层和IP层的地址应该是对应的。H说明了Destination的<br>
性质，如果是H的，则说明该地址是一个完整的地址，既有网络号又有主机号，那么再匹配的时候就既要匹配网络号，又要匹配主机号；反<br>
之，Destination就代表一个网络，在匹配的时候只要匹配一下网络号就可以了。<br>
这样，IP选路的方式就可以更加具体化了。如下<br></li>
<li>首先用IP地址来匹配那些带H标志的DestinationIP地址。</li>
<li>如果1失败就匹配那些网络地址。</li>
<li>如果2失败就发送到Default网关<br>
顺便提一下那个GenMask（还记得子网掩码么），它指定了目的地址的子网号，例如第一条的子网就是11。<br>
1.2.其他有关路由表的知识<br>
一般，我们在配置好一个网络接口的时候，一个路由就被直接创建好了。当然我们也可以手动添加路由。用route add命令就可以了。<br>
而当一个IP包在某一个路由器的时候发现没有路由可走，那么该路由器就会给源主机发送“主机不可达”或者“网络不可达”的ICMP包来报错。<br>
注意，一般的操作系统默认是没有路由功能的，这需要自己配置。这些历史原因就不细说了，<br>
1.3.ICMP的IP重定向报文和路由发现报文<br>
当IP包在某一个地方转向的时候，都回给发送IP报的源主机一个ICMP重定向报文，而源主机就可以利用这个信息来更新自己的路由表，这样，随着网络通信的逐渐增多，路由表也就越来越完备，数据转发的速度也会越来越快。我们需要注意的是：<br></li>
<li>重定向报文只能由路由器发出。</li>
<li>重定向报文为主机所用，而不是为路由器所用。&nbsp;&nbsp;<br>
在主机引导的时候，一般会发送在网内广播一个路由请求的ICMP报文，而多个路由器则会回应一个路由通告报文。而且，路由其本身不定期的在网络内发<br>
布路由通告报文，这样，根据这些报文，每一个主机都会有机会建立自己的路由表而实现网络通信。路由器在一份通告报文中可以通告多个地址，并且给出每一个地<br>
址的优先等级，这个优先等级是该IP作为默认路由的等级，至于怎么算的就不深究了。<br>
路由器一般会在450-600秒的时间间隔内发布一次通告，而一个给定的通告报文的寿命是30分钟。而主机在引导的时候会每三秒发送一次请求报文，一旦接受到一个有效的通告报文，就停止发送请求报文。<br>
在TCP/IP详解编写的时候，只有Solaris2.x支持这两种报文，大多数系统还不支持这两种报文。（后面还会讲到一些有用的路由报文）<br>
动态选路协议<br>
前面的选路方法叫做静态选路，简要地说就是在配置接口的时候，以默认的方式生成路由表项。并通过route来增加表项，或者通过ICMP报文来更新表项（通常在默认方式出错的情况下）。 而如果上诉三种方法都不能满足，那么我们就使用动态选路。<br>
动态选路协议是用于动态选路的重要组成部分，但是他们只是使用在路由器之间，相邻路由器之间互相通信。系统（路有选择程序）选择比较合适的路有放到<br>
核心路由表中，然后系统就可以根据这个核心路有表找到最合适的网路。也就是说，动态选路是在系统核心网络外部进行的，它只是用一些选路的策略影响路由表，<br>
而不会影响到最后通过路由表选择路由的那一部分。选路协议有一大类常用的叫做内部网关协议(IGP)，而在IGP中，RIP就是其中最重要的协议。一种新<br>
的IGP协议叫做<b>开放最短路经优先(OSPF)协议</b>，其意在取代RIP。另一种最早用在网路骨干网上的IGP协议--HELLO，现在已经不用了。<br>
如今，任何支持动态选路的路由器都必须同时支持OSPF和RIP，还可以选择性的支持其他的IGP协议。<br>
2.1.Unix选路程序<br>
Unix系统上面通常都有路由守护程序－－routed。还有一个叫做<b>gate</b>。gate所支持的协议要比routed多，routed只是支持RIPv1版本。而gate则支持RIPv1、v2，BGPv1 等等。<br>
2.1.RIP：选路信息协议<br>
它的定义可以在RFC1058内找到，这种协议使用UDP作为载体（也就是UDP的上层协议）。我们最关心的就是RIP其中的一个段，叫做度量的<br>
段，这是一个以hop作为计数器（就是以走过多少路由为计数器）的段（IP协议里面也有一个TTL不是么）。这个度量段将最终影响到路由表的建立。参考<br>
图:<br>
<img alt="" src="http://blog.csdn.net/images/blog_csdn_net/goodboy1881/193693/r_rip_protocol.JPG" border="0"><br>
一般说来routed要承担如下的工作：<br></li>
<li>给每一个已知的路由器发送rip请求报文，要求其他路由器给出完整的路由表。这种报文的命令字段为1，地址字段为0，度量地段为16（相当于无穷大）。</li>
<li>接受请求，如果接收到刚才的那个请求，就把自己的完整的路由表交给请求者。如果没有，就处理IP请求表项，把表项中自己有的部分添上跳数，没有的部分添上16。然后发给请求者。</li>
<li>接受回应。更新自己的路由表。使用hop数小的规则。</li>
<li>定期更新路由表，一般是30s(真频繁)给相邻的路有启发一次自己的路由表。这种形式可以使广播形式的。<br>
这个协议看起来会工作的很好，但是，这里面其实有很多隐藏的忧患，比如说RIP没有子网的概念，比如说环路的危险。而且hop数的上限也限制了网络的大小。<br>
因此，出现了很多RIPv1的替代品，比如说RIPv2,比如说OSPF。他们都是通过某种策略来影响路由表，所以就不说了。</li>
</ul>
</td>
</tr>
</tbody>
</table> ]]></description>
		<eb:creationDate>2008-10-20 19:26:54</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(4)-ICMP协议，ping和Traceroute ]]></title>
		<link>http://blog.tom.com/ccna/article/1840.html</link>
		<description><![CDATA[ <table cellspacing="0" cellpadding="0" width="660" align="center" border="0">
<tbody>
<tr>
<td></td>
</tr>
<tr>
<td>
<ul>
<li>目的地址是广播地址或多播地址的IP数据报。</li>
<li>作为链路层广播的数据报。</li>
<li>不是IP分片的第一片。</li>
<li>源地址不是单个主机的数据报。这就是说，源地址不能为零地址、环回地址、广播地 址或多播地址。<br>
虽然里面的一些规定现在还不是很明白，但是所有的这一切规定，都是为了防止产生ICMP报文的无限传播而定义的。<br>
ICMP协议大致分为两类，一种是查询报文，一种是差错报文。其中查询报文有以下几种用途:<br></li>
<li>ping查询（不要告诉我你不知道ping程序）</li>
<li>子网掩码查询（用于无盘工作站在初始化自身的时候初始化子网掩码）</li>
<li>时间戳查询（可以用来同步时间）<br>
而差错报文则产生在数据传送发生错误的时候。就不赘述了。<br>
2.ICMP的应用--ping<br>
ping可以说是ICMP的最著名的应用，当我们某一个网站上不去的时候。通常会ping一下这个网站。ping会回显出一些有用的信息。一般的信息如下:<br>
<br>
Reply from 10.4.24.1: bytes=32 time<br>
ping这个单词源自声纳定位，而这个程序的作用也确实如此，它利用ICMP协议包来侦测另一个主机是否可达。原理是用类型码为0的ICMP发请<br>
求，受到请求的主机则用类型码为8的ICMP回应。ping程序来计算间隔时间，并计算有多少个包被送达。用户就可以判断网络大致的情况。我们可以看到，<br>
ping给出来了传送的时间和TTL的数据。我给的例子不太好，因为走的路由少，有兴趣地可以ping一下国外的网站比如sf.net，就可以观察到一些<br>
丢包的现象，而程序运行的时间也会更加的长。<br>
ping还给我们一个看主机到目的主机的路由的机会。这是因为，ICMP的ping请求数据报在每经过一个路由器的时候，路由器都会把自己的ip放到该数<br>
据报中。而目的主机则会把这个ip列表复制到回应icmp数据包中发回给主机。但是，无论如何，ip头所能纪录的路由列表是非常的有限。如果要观察路由，<br>
我们还是需要使用更好的工具，就是要讲到的Traceroute(windows下面的名字叫做tracert)。<br>
3.ICMP的应用--Traceroute<br>
Traceroute是用来侦测主机到目的主机之间所经路由情况的重要工具，也是最便利的工具。前面说到，尽管ping工具也可以进行侦测，但是，因为ip头的限制，ping不能完全的记录下所经过的路由器。所以Traceroute正好就填补了这个缺憾。<br>
Traceroute的原理是非常非常的有意思，它受到目的主机的IP后，首先给目的主机发送一个TTL=1（还记得TTL是什么吗？）的UDP(后面就<br>
知道UDP是什么了)数据包，而经过的第一个路由器收到这个数据包以后，就自动把TTL减1，而TTL变为0以后，路由器就把这个包给抛弃了，并同时产生<br>
一个主机不可达的ICMP数据报给主机。主机收到这个数据报以后再发一个TTL=2的UDP数据报给目的主机，然后刺激第二个路由器给主机发ICMP数据<br>
报。如此往复直到到达目的主机。这样，traceroute就拿到了所有的路由器ip。从而避开了ip头只能记录有限路由IP的问题。<br>
有人要问，我怎么知道UDP到没到达目的主机呢？这就涉及一个技巧的问题，TCP和UDP协议有一个端口号定义，而普通的网络程序只监控少数的几个号码较<br>
小的端口，比如说80,比如说23,等等。而traceroute发送的是端口号&gt;30000(真变态)的UDP报，所以到达目的主机的时候，目的<br>
主机只能发送一个端口不可达的ICMP数据报给主机。主机接到这个报告以后就知道，主机到了，所以，说Traceroute是一个骗子一点也不为过:)<br>
Traceroute程序里面提供了一些很有用的选项，甚至包含了IP选路的选项，请察看man文档来了解这些，这里就不赘述了。<br></li>
</ul>
</td>
</tr>
</tbody>
</table> ]]></description>
		<eb:creationDate>2008-10-20 19:26:01</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ TCP/IP详解学习笔记(3)-IP协议，ARP协议，RARP协议 ]]></title>
		<link>http://blog.tom.com/ccna/article/1839.html</link>
		<description><![CDATA[ 把这三个协议放到一起学习是因为这三个协议处于同一层，ARP协议用来找到目标主机的Ethernet网卡Mac地址，IP则承载要发送的消息。数据链路层可以从ARP得到数据的传送信息，而从IP得到要传输的数据信息。<br>
1.IP协议<br>
IP协议是TCP/IP协议的核心，所有的TCP，UDP，IMCP，IGCP的数据都以IP数据格式传输。要注意的是，IP不是可靠的协议，这是<br>
说，IP协议没有提供一种数据未传达以后的处理机制－－这被认为是上层协议－－TCP或UDP要做的事情。所以这也就出现了TCP是一个可靠的协议，而<br>
UDP就没有那么可靠的区别。这是后话，暂且不提<br>
1.1.IP协议头<br>
如图所示<br>
<img alt="" src="http://blog.csdn.net/images/blog_csdn_net/goodboy1881/193693/r_ip-protocol.JPG" border="0"><br>
<br>
挨个解释它是教科书的活计，我感兴趣的只是那八位的TTL字段，还记得这个字段是做什么的么？这个字段规定该数据包在穿过多少个路由之后才会被抛弃<br>
(这里就体现出来IP协议包的不可靠性，它不保证数据被送达)，某个ip数据包每穿过一个路由器，该数据包的TTL数值就会减少1，当该数据包的TTL成<br>
为零，它就会被自动抛弃。这个字段的最大值也就是255，也就是说一个协议包也就在路由器里面穿行255次就会被抛弃了，根据系统的不同，这个数字也不一<br>
样，一般是32或者是64，Tracerouter这个工具就是用这个原理工作的，tranceroute的-m选项要求最大值是255，也就是因为这个<br>
TTL在IP协议里面只有8bit。<br>
现在的ip版本号是4，所以也称作IPv4。现在还有IPv6，而且运用也越来越广泛了。<br>
1.2.IP路由选择<br>
当一个IP数据包准备好了的时候，IP数据包（或者说是路由器）是如何将数据包送到目的地的呢？它是怎么选择一个合适的路径来"送货"的呢？<br>
最特殊的情况是目的主机和主机直连，那么主机根本不用寻找路由，直接把数据传递过去就可以了。至于是怎么直接传递的，这就要靠ARP协议了，后面会讲到。<br>
稍微一般一点的情况是，主机通过若干个路由器(router)和目的主机连接。那么路由器就要通过ip包的信息来为ip包寻找到一个合适的目标来进行传递，比如合适的主机，或者合适的路由。路由器或者主机将会用如下的方式来处理某一个IP数据包<br>
<ul>
<li>如果IP数据包的TTL（生命周期）以到，则该IP数据包就被抛弃。</li>
<li>搜索路由表，优先搜索匹配主机，如果能找到和IP地址完全一致的目标主机，则将该包发向目标主机</li>
<li>搜索路由表，如果匹配主机失败，则匹配同子网的路由器，这需要“子网掩码(1.3.)”的协助。如果找到路由器，则将该包发向路由器。</li>
<li>搜索路由表，如果匹配同子网路由器失败，则匹配同网号（第一章有讲解）路由器，如果找到路由器，则将该包发向路由器。</li>
<li>搜索陆游表，如果以上都失败了，就搜索默认路由，如果默认路由存在，则发包</li>
<li>如果都失败了，就丢掉这个包。<br>
这再一次证明了，ip包是不可靠的。因为它不保证送达。<br>
1.3.子网寻址<br>
IP地址的定义是网络号+主机号。但是现在所有的主机都要求子网编址，也就是说，把主机号在细分成子网号+主机号。最终一个IP地址就成为 网络号码+子网号+主机号。例如一个B类地址：<font color="#00F000">210</font>.<font color="#00F000">30</font>.<font color="#0000FF">109</font>.<font color="#008000">134</font>。一般情况下，这个IP地址的红色部分就是网络号，而蓝色部分就是子网号，绿色部分就是主机号。至于有多少位代表子网号这个问题上，这没有一个硬性的规定，取而代之的则是<b>子网掩码</b>，<br>
校园网相信大多数人都用过，在校园网的设定里面有一个255.255.255.0的东西，这就是子网掩码。子网掩码是由32bit的二进制数字序列,形式<br>
为是一连串的1和一连串的0，例如：255.255.255.0(二进制就是11111111.11111111.11111111.00000000)<br>
对于刚才的那个B类地址，因为210.30是网络号，那么后面的109.134就是子网号和主机号的组合，又因为子网掩码只有后八bit为0，所以主机号<br>
就是IP地址的后八个bit，就是134，而剩下的就是子网号码－－109。<br>
2. ARP协议<br>
还记得数据链路层的以太网的协议中，每一个数据包都有一个MAC地址头么？我们知道每一块以太网卡都有一个MAC地址，这个地址是唯一的，那么IP包是如何知道这个MAC地址的？这就是ARP协议的工作。<br>
ARP（地址解析）协议是一种解析协议，本来主机是完全不知道这个IP对应的是哪个主机的哪个接口，当主机要发送一个IP包的时候，会首先查一下自<br>
己的ARP高速缓存（就是一个IP-MAC地址对应表缓存），如果查询的IP－MAC值对不存在，那么主机就向网络发送一个ARP协议广播包，这个广播包<br>
里面就有待查询的IP地址，而直接收到这份广播的包的所有主机都会查询自己的IP地址，如果收到广播包的某一个主机发现自己符合条件，那么就准备好一个包<br>
含自己的MAC地址的ARP包传送给发送ARP广播的主机，而广播主机拿到ARP包后会更新自己的ARP缓存（就是存放IP-MAC对应表的地方）。发送<br>
广播的主机就会用新的ARP缓存数据准备好数据链路层的的数据包发送工作。<br>
一个典型的arp缓存信息如下，在任意一个系统里面用“arp -a”命令:<br>
Interface: 192.168.11.3 --- 0x2<br>
&nbsp;&nbsp;Internet Address&nbsp; &nbsp;&nbsp; &nbsp;Physical Address&nbsp; &nbsp;&nbsp; &nbsp;Type<br>
&nbsp;&nbsp;192.168.11.1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 00-0d-0b-43-a0-2f&nbsp; &nbsp;&nbsp;&nbsp;dynamic<br>
&nbsp;&nbsp;192.168.11.2&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; 00-01-4a-03-5b-ea&nbsp; &nbsp;&nbsp;&nbsp;dynamic<br>
<br>
<br>
都会得到这样的结果。<br>
这样的高速缓存是有时限的，一般是20分钟（伯克利系统的衍生系统）。</li>
</ul> ]]></description>
		<eb:creationDate>2008-10-20 19:25:14</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ Linux服务优化详解 ]]></title>
		<link>http://blog.tom.com/ccna/article/1838.html</link>
		<description><![CDATA[ ConsoleKit<br>
Fedota 7的新功能Fedora - Fast User Switchin，如果你想要使用这个新功能就开着，反之关掉吧。<br>
NetworkManager, NetworkManagerDispatcher<br>
自动在多种网络连接中进行转换，如果你的电脑有Wireless WiFi 和 Ethernet，开着它吧，Fedora能自动为你选择最好的可用连接。像我这样<br>
只用一个网络连接设置的，还是关掉吧。<br>
anacron, atd, crond<br>
这是一些调试程序的后台服务，一般的桌面用户可以把anacron, atd关了，如果你打算常时间开机，那就把crond打开。 建议始终把crond开着。<br>
auditd<br>
用于存放内核生成的系统审查记录，这些记录会被一些程序使用。特别是对于SELinux用户来说，还是开着吧。<br>
autofs<br>
自动挂在移动硬盘，没什么说的，开着。<br>
avahi-daemon, avahi-dnsconfd<br>
主要用于Zero Configuration Networking ，关吧，一般无用。<br>
bluetooth, hcid, hidd, sdpd, dund, pand<br>
蓝牙相关，无蓝牙者，关关关。<br>
btseed, bttrack<br>
BT相关，无法用BT的，可以关了<br>
capi<br>
ISDN硬件支持，大部分用户可以关了<br>
cpuspeed<br>
CPU速度调整，如果你用的是Pentium-M, Centrino, AMD PowerNow, Transmetta, Intel SpeedStep, Athlon-64, Athlon-X2, Intel Core 2<br>
开着吧；如果不是还是关了吧，开着也无用。<br>
cupsd<br>
CUPS打印机支持，没有打印机或者是其他类型打印机的，可以关了<br>
dhcdbd<br>
D-BUS系统网络接口，主要为你提供网络连接设置，强烈建议开着，除非你用固定IP上网。<br>
firstboot<br>
Fedora安装完之后的那个用户向导，一般可以关了<br>
gpm<br>
Text console（CTRL-ALT-F1,F2..）鼠标支持，如果你不经常用Text console，可以关了<br>
haldaemon<br>
HAL（Hardware Abstraction Layer）服务，开着吧<br>
hplip, hpiod, hpssd<br>
HPLIP打印机支持，如果你有开着吧。<br>
httpd<br>
Apache HTTP网页服务器， 如果你不开发网页，关吧<br>
ip6tables<br>
如果你不用 IPv6，关了<br>
iptables<br>
防火墙，没什么说的，开着<br>
irda<br>
红外线设备支持，无者关<br>
irqbalance<br>
多核CPU支持， 无着关<br>
isdn<br>
ISDN modem支持， 无者关<br>
jexec<br>
如果你安装java 1.6 就会有这个，让你可以双击运行 *.jar 文件。不想要就关<br>
kudzu<br>
Fedora硬盘侦测服务，当你更换或添加硬盘的时候可以使用，平时可以关了<br>
lirc<br>
红外线遥控器支持， 无者关<br>
mcstrans<br>
主要用于SELinux，如果你不用SELinux，可以关了<br>
mdmonitor<br>
RAID支持， 无者关<br>
messagebus<br>
Linux ICP 服务， 强列建议开着。<br>
netfs<br>
如果你需要网络共享文件，那就开着<br>
netplugd<br>
对大部分用户基本无用，关<br>
network<br>
没什么说的。开着；除非你不上网<br>
nfs, nfslock<br>
文件共享支持，不需要的可以关了<br>
nscd<br>
NIS, NIS+, LDAP, or hesiod服务密码控制， 没有这些服务的可以关了<br>
ntpd<br>
网络时间同步，和windows的那个差不多，不需要的可以关了<br>
nvidia-96XX 或者 nvidia-97XX<br>
livna的nvidia显卡驱动，开<br>
pcscd<br>
智能卡支持，无者关<br>
readahead_early, readahead_later<br>
开机内存载入优化， 开着吧<br>
restorecond<br>
SELinux用于监控文件， 不用SELinux的可以关了<br>
rpcbind<br>
RPC服务，一般可以关闭<br>
rpcgssd, rpcidmapd, rpcsvcgssd<br>
NFS支持，不用NFS的可以关闭<br>
sendmail<br>
邮件传送代理，如果你用Webmail 或者 Thunderbird, Kmail之类的来收发邮件。可以关了<br>
setroubleshoot<br>
SELinux Troubleshooting， 不用SELinux的可以关了<br>
smartd<br>
SMART Disk Monitoring， 快速开机自检，开着吧<br>
smolt<br>
无用，关吧<br>
sshd<br>
OpenSSH服务器，通常可以关了，这是服务器端，关闭不影响ssh的使用<br>
syslog<br>
系统日志，开着吧<br>
vncserver<br>
一般桌面用户可以关了<br>
winbind<br>
不用Samba服务器的话， 可以关了<br>
wpa_supplicant<br>
无线设备支持，无者关<br>
ypbind<br>
不用NIS/YP，可以关了<br>
yum-update<br>
自动定期升级检测， 如果你经常手动升级。可以关了 ]]></description>
		<eb:creationDate>2008-10-20 19:15:17</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ ACL介绍 ]]></title>
		<link>http://blog.tom.com/ccna/article/1677.html</link>
		<description><![CDATA[ <div id="message1581781">访问控制列表（Access Control List，ACL） 是路由器接口的指令列表，用来控制端口进出的数据包。ACL适用于所有的被路由协议，如IP、IPX、AppleTalk等。<br>
　　　　ACL的定义也是基于每一种协议的。如果路由器接口配置成为支持三种协议（IP、AppleTalk以及IPX）的情况，那么，用户必须定义三种ACL来分别控制这三种协议的数据包。<br>
　　<br>
　　ACL的作用<br>
　　<br>
　　ACL可以限制网络流量、提高网络性能。例如，ACL可以根据数据包的协议，指定数据包的优先级。<br>
　　<br>
　　ACL提供对通信流量的控制手段。例如，ACL可以限定或简化路由更新信息的长度，从而限制通过路由器某一网段的通信流量。<br>
　　<br>
　　ACL是提供网络安全访问的基本手段。如图1所示，ACL允许主机A访问人力资源网络，而拒绝主机B访问。<br>
　　<br>
　　ACL可以在路由器端口处决定哪种类型的通信流量被转发或被阻塞。例如，用户可以允许E-mail通信流量被路由，拒绝所有的Telnet通信流量。<br>
　　<br>
　　ACL的执行过程<br>
　　<br>
　　一个端口执行哪条ACL，这需要按照列表中的条件语句执行顺序来判断。如果一个数据包的报头跟表中某个条件判断语句相匹配，那么后面的语句就将被忽略，不再进行检查。<br>
　　<br>
　　ACL具体的执行流程见图2。<br>
　　<br>
　　在图2中，数据包只有在跟第一个判断条件不匹配时，它才被交给ACL中的下一个条件判断语句进行比较。如果匹配（假设为允许发送），则不管是第一条还是最后一条语句，数据都会立即发送到目的接口。如果所有的ACL判断语句都检测完毕，仍没有匹配的语句出口，则该数据包将视为被拒绝而被丢弃。<br>
　　<br>
　　这里要注意，ACL不能对本路由器产生的数据包进行控制。<br>
　　<br>
　　ACL的分类<br>
　　<br>
　　目前有两种主要的ACL:标准ACL和扩展ACL。<br>
　　<br>
　　这两种ACL的区别是，标准ACL只检查数据包的源地址; 扩展ACL既检查数据包的源地址，也检查数据包的目的地址，同时还可以检查数据包的特定协议类型、端口号等。<br>
　　<br>
　　网络管理员可以使用标准ACL阻止来自某一网络的所有通信流量，或者允许来自某一特定网络的所有通信流量，或者拒绝某一协议簇（比如IP）的所有通信流量。<br>
　　<br>
　　扩展ACL比标准ACL提供了更广泛的控制范围。例如，网络管理员如果希望做到“允许外来的Web通信流量通过，拒绝外来的FTP和Telnet等通信流量”，那么，他可以使用扩展ACL来达到目的，标准ACL不能控制这么精确。<br>
　　　&nbsp;&nbsp;<br>
　　在路由器配置中，标准ACL和扩展ACL的区别是由ACL的表号来体现的，上表指出了每种协议所允许的合法表号的取值范围。<br>
　　<br>
　　正确放置ACL<br>
　　<br>
　　ACL通过过滤数据包并且丢弃不希望抵达目的地的数据包来控制通信流量。然而，网络能否有效地减少不必要的通信流量，这还要取决于网络管理员把ACL放置在哪个地方。<br>
　　<br>
　　假设在图3所示的一个运行TCP/IP协议的网络环境中，网络只想拒绝从RouterA的T0接口连接的网络到RouterD的E1接口连接的网络的访问，即禁止从网络1到网络2的访问。<br>
　　<br>
　　根据减少不必要通信流量的通行准则，网管员应该尽可能地把ACL放置在靠近被拒绝的通信流量的来源处，即RouterA上。如果网管员使用标准ACL来进行网络流量限制，因为标准ACL只能检查源IP地址，所以实际执行情况为：凡是检查到源IP地址和网络1匹配的数据包将会被丢掉，即网络1到网络2、网络3和网络4的访问都将被禁止。由此可见，这个ACL控制方法不能达到网管员的目的。同理，将ACL放在RouterB和RouterC上也存在同样的问题。只有将ACL放在连接目标网络的RouterD上（E0接口），网络才能准确实现网管员的目标。由此可以得出一个结论: 标准ACL要尽量靠近目的端。<br>
　　<br>
　　网管员如果使用扩展ACL来进行上述控制，则完全可以把ACL放在RouterA上，因为扩展ACL能控制源地址（网络1），也能控制目的地址（网络2），这样从网络1到网络2访问的数据包在RouterA上就被丢弃，不会传到RouterB、RouterC和RouterD上，从而减少不必要的网络流量。因此，我们可以得出另一个结论：扩展ACL要尽量靠近源端。<br>
　　<br>
　　ACL的配置<br>
　　<br>
　　ACL的配置分为两个步骤：<br>
　　<br>
　　第一步:在全局配置模式下，使用下列命令创建ACL：<br>
　　<br>
　　Router (config)# access-list access-list-number {permit | deny } {test-conditions}<br>
　　<br>
　　其中，access-list-number为ACL的表号。人们使用较频繁的表号是标准的IP ACL（1—99）和扩展的IP ACL（100－199）。<br>
　　<br>
　　在路由器中，如果使用ACL的表号进行配置，则列表不能插入或删除行。如果列表要插入或删除一行，必须先去掉所有ACL，然后重新配置。当ACL中条数很多时，这种改变非常烦琐。一个比较有效的解决办法是：在远程主机上启用一个TFTP服务器，先把路由器配置文件下载到本地，利用文本编辑器修改ACL表，然后将修改好的配置文件通过TFTP传回路由器。<br>
　　<br>
　　这里需要特别注意的是，在ACL的配置中，如果删掉一条表项，其结果是删掉全部ACL，所以在配置时一定要小心。<br>
　　<br>
　　在Cisco IOS11.2以后的版本中，网络可以使用名字命名的ACL表。这种方式可以删除某一行ACL，但是仍不能插入一行或重新排序。所以，笔者仍然建议使用TFTP服务器进行配置修改。<br>
　　<br>
　　第二步：在接口配置模式下，使用access-group命令ACL应用到某一接口上：<br>
　　<br>
　　Router (config-if)# {protocol} access-group access-list-number {in | out }<br>
　　<br>
　　其中，in和out参数可以控制接口中不同方向的数据包，如果不配置该参数，缺省为out。<br>
　　<br>
　　ACL在一个接口可以进行双向控制，即配置两条命令，一条为in，一条为out，两条命令执行的ACL表号可以相同，也可以不同。但是，在一个接口的一个方向上，只能有一个ACL控制。<br>
　　<br>
　　值得注意的是，在进行ACL配置时，网管员一定要先在全局状态配置ACL表，再在具体接口上进行配置，否则会造成网络的安全隐患。<br></div> ]]></description>
		<eb:creationDate>2008-05-07 11:03:47</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
    <item>
		<title><![CDATA[ nat ]]></title>
		<link>http://blog.tom.com/ccna/article/1659.html</link>
		<description><![CDATA[ <a href="http://baike.baidu.com/pic/2/1145757033625650.jpg" target="_blank"><img title="点击查看大图" alt="" hspace="5" src="http://baike.baidu.com/pic/2/1145757033625650_small.jpg" align="right" vspace="5" border="0"></a> 网络地址转换（NAT）<br>
网络地址转换(NAT,Network Address Traslation)被广泛应用于各种类型Internet接入方式和备种类型的网络中。原因很简单，NAT不仅完美地解决了lP地址不足的问题，而且还能够有效地避免来自网络外部的攻击，隐藏并保护网络内部的计算机。虽然NAT可以借助于某些代理服务器未实现，但考虑到运算成本和网络性能，很多时候都是在路由器上来实现的。关于NAT的考试在CISCO认证中，占有很大一部分，下面我们从下面几个部分，由浅入深，带领您认识NAT，掌握NAT,精通NAT。<br>
一、网络地址转换概述<br>
随着接入Internet的计算机数量的不断猛增，IP地址资源也就愈加显得捉襟见肘。事实上，除了中国教育和科研计算机网(CERNET)外，一般用户几乎申请不到整段的C类IP地址。在其他ISP那里，即使是拥有几百台计算机的大型局域网用户，当他们申请IP地址时，所分配的地址也不过只有几个或十几个IP地址。显然，这样少的IP地址根本无法满足网络用户的需求，于是也就产生了NAT技术。<br>
l.NAT简介<br>
借助于NAT，私有(保留)地址的"内部"网络通过路由器发送数据包时，私有地址被转换成合法的IP地址，一个局域网只需使用少量IP地址(甚至是1个)即可实现私有地址网络内所有计算机与Internet的通信需求。<br>
NAT将自动修改IP报文头申的源IP地址和目的IP地址，IP地址校验则在NAT处理过程中自动完成。有些应用程序将源IP地址嵌入到IP报文的数据部分中，所以还需要同时对报文进行修改，以匹配IP头中已经修改过的源IP地址................<br>
二、网络地址转换的实现<br>
在配置网络地址转换的过程之前，首先必须搞清楚内部接口和外部接□，以及在哪个外都接口上启用NAT。通常情况下，连接到用户内部网络的接口是NAT内部接口，而连接到外部网络(如Internet)的接口是NAT外部接□................<br>
三、网络地址转换经典配置实例<br>
示例一：全部采用端口复用地址转换<br>
当ISP分配的IP地址数量很少，网络又没有其他特殊需求，即无需为Internet提供网络服务时，可采用端口利用地址转换方式，使网络内的计算机采用同一IP地址访问Internet，在节约IP地址资源的同时，又可有效保护网络内部的计算机。<br>
网络环境为：<br>
局域网采用10Mb/s光纤，以城域网方式接入Internet，如图4-2-2所示。路由器选用拥有2个10/100 Mb/s自适应端口的Cisco 2611。内部网络使用的IP地址段为192.168.100.1~192.101.254，局域网端口Ethernet 0的IP地址为192.168.100.1,子网掩码为255.255.0.0。网络分配的合法IP地址范围为202.99.160.128~202.99.160.131,连接ISP的端口Ethernet 1的IP地址为202.99.160.129,子网掩码为255.255.255.252。可用于转换的IP地址为202.99.160.130。要求网络内部的所有计算机均可访问Internet................<br>
网络地址转换(NAT)概述<br>
网络地址转换(NAT,Network Address Traslation)被广泛应用于各种类型Internet接入方式和备种类型的网络中。原因很简单，NAT不仅完美地解决了lP地址不足的问题，而且还能够有效地避免来自网络外部的攻击，隐藏并保护网络内部的计算机。<br>
虽然NAT可以借助于某些代理服务器未实现，但考虑到运算成本和网络性能，很多时候都是在路由器上来实现的。<br>
随着接入Internet的计算机数量的不断猛增，IP地址资源也就愈加显得捉襟见肘。事实上，除了中国教育和科研计算机网(CERNET)外，一般用户几乎申请不到整段的C类IP地址。在其他ISP那里，即使是拥有几百台计算机的大型局域网用户，当他们申请IP地址时，所分配的地址也不过只有几个或十几个IP地址。显然，这样少的IP地址根本无法满足网络用户的需求，于是也就产生了NAT技术。<br>
l.NAT简介<br>
借助于NAT，私有(保留)地址的"内部"网络通过路由器发送数据包时，私有地址被转换成合法的IP地址，一个局域网只需使用少量IP地址(甚至是1个)即可实现私有地址网络内所有计算机与Internet的通信需求。<br>
NAT将自动修改IP报文头申的源IP地址和目的IP地址，p地址校验则在NAT处理过程中自动完成。有些应用程序将源IP地址嵌入到IP报文的数据部分中，所以还需要同时对报文进行修改，以匹配IP头中已经修改过的源IP地址。否则，在报文数据都分崩嵌入IP地址的应用程序就不能正常工作。令人遗憾的是，尽管NAT的Cisco版本可以处理许多应用，但它毕竟也不是万能的，一些应用还是无法被支持。表4一2一1列举了Cisco NAT支持的和不支持的应用。<br>
2.NAT实现方式<br>
NAT的实现方式有三种，即静态转换、动态转换相端口多路复用。<br>
静态转换是指将内部网络的私有IP地址转换为公IP地址时，IP地址对是一对--的，是一成不变的，某个私有IP地址只转换为某个公有IP地址。借助于静态转换，局实现外部网络对内部网络中某些特定设备(如服务器)的访问。 动态转换是指将内部网络的私有IP地址转换为公用IP地址时，IP地址对是不确定的，而是随机的，所有被授权访问上ternet的私有IP地址可随机转换为任何指定的合法IP地址。也就是说，只要指定哪些内部地址可以进行转换，以及用哪些合法地址作为外部地址时，就可以进行动态转换。动态转换可以使用多个合法外部地址集。当ISP提供的合法IP地址略少于网络内部的计算机数量时。可以未用动态转换的方式。<br>
端口多路复用是指改变外出数据包的源端口并进行端口转换，即端口地址转换(FAT，Port Address Translation).采用端口多路复用方式。内部网络的所有主机均可共享一个合法外部IP地址实现对Internet的访问，从而可以最大限度地节约IP地址资源。同时，又可隐藏网络内部的所有主机，有效避兔来自internet的攻击"因此，目前网络申应用最多的就是端口多路复用方式了。<br>
网络地址转换(NAT)的实现<br>
在配置网络地址转换的过程之前，首先必须搞清楚内部接口和外部接□，以及在哪个外都接口上启用NAT。通常情况下，连接到用户内部网络的接口是NAT内部接口，而连接到外部网络(如Internet)的接口是NAT外部接□。<br>
1.静态地址转换的实现<br>
假设内部局域网使用的lP地址段为192.168.100.1~192.168.100.254，路由器局域网端□(即默认网关)的IP地址为192.168.100"1，子网掩码为255.255.255.0。网络分配的合法IP地址范围为61.159.62.128~61.159.62.135，路由器在广域网中的IP地址为61.159.62.129，子网掩码为255.255.255.248可用于转换的IP地址范围为61.159.63.130~61.159.62.134。要求将内部网止192.168.100.2~192.168.100.6分别转换为合法IP地址61.159.62.130~61.159.62.134。<br>
第一步，设置外部端口。<br>
interface serial 0<br>
ip address 61.159.62.129.255.255.255.248<br>
ip nat outside<br>
第二步，设置内部端口。<br>
interface ethernet 0<br>
ip address 192.168.100.1.255.255.0<br>
ip nat inside<br>
第三步，在内部本地与内部合法地址之间建立静态地址转换。<br>
ip nat inside source static 内部本地地址内部合法地址<br>
示例：<br>
ip nat inside source static 192.168.100.2 61.159.62.130//将内部网络地址192.168.100.2转换为合法IP地址61.159.62.130<br>
ip nat inside source static 192.168.100.3 61.159.62.131//将内部网络地址192.168.100.3转换为合法IP地址61.159.62.131<br>
ip nat inside source static 192.168.100.4 61.159.62.132//将内部网络地址192.168.100.4转换为合法IP地址61.159.62.132<br>
ip nat inside source static 192.168.100.5 61.159.62.133//将内部网络地址192.168.100.5转换为合法IP地址61.159.62.133<br>
ip nat inside source static 192.168.100.6 61.159.62.134//将内部网络地址192.168.100.6转换为合法IP地址61.159.62.134<br>
至此，静态地址转换配置完毕。<br>
2.动态地址转换的实现<br>
假设内部网络使用的IP地址段为172.16.100.1~172.16.100.254,路由器局域网端口（即默认网关）的IP地址为172.16.100.1,子网掩码为255.255.2585.0。网络分配的合法IP地址范围为61.159.62.128~61.159.62.191，路由器在广域网中的IP地址为61.159.62.129,子网掩码为255.255.255.192,可用于转换的IP地址范围为61.159.62.130~61.159.62.190。要求将内部网址172.16.100.1~172.16.100.254动态转换为合法IP地址61.159.62.130~61.159.62.190。<br>
第一步，设置外部端口。<br>
设置外部端口命令的语法如下：<br>
ip nat outside<br>
示例：<br>
interface serial 0//进入串行端口serial 0<br>
ip address 61.159.62.129 255.255.248//将其IP地址指定为61.159.62.129,子网掩码为255.255.255.248<br>
ip nat outside //将串行口serial 0设置为外网端口<br>
注意，可以定义多个外部端口。<br>
第二步，设置内部端口。<br>
设置内部接口命令的语法如下：<br>
ip nat inside<br>
示例：<br>
interface ethernet 0 //进入以太网端口Ethernet 0<br>
ip address 172.16.100.1 255.255.255.0 // 将其IP地址指定为172.16.100.1,子网掩码为255.255.255.0<br>
ip nat inside //将Ethernet 0 设置为内网端口。<br>
注意，可以定义多个内部端口。<br>
第三步，定义合法IP地址池。<br>
定义合法IP地址池命令的语法如下：<br>
ip nat pool 地址池名称 起始IP地址 终止IP地址 子网掩码<br>
其中，地址池名字可以任意设定。<br>
示例：<br>
ip nat pool net 61.159.62.130 61.159.62.190 netmask 255.255.255.192//指明地址缓冲池的名称为net,IP地址范围为61.159.62.130~61.159.62.190,子网掩码为255.255.255.192。需要注意的是，即使掩码为255.255.255.0，也会由起始IP地址和终止IP地址对IP地址池进行限制。<br>
或ip nat pool test 61.159.62.130 61.159.62.190 prefix-length 26<br>
注意，如果有多个合法IP地址范围，可以分别添加。例如，如果还有一段合法IP地址范围为"211.82.216.1~211.82.216.254"，那么，可以再通过下述命令将其添加至缓冲池中。<br>
ip nat pool cernet 211.82.216.1 211.82.216.254 netmask 255.255.255.0<br>
或<br>
ip nat pool test 211.82.216.1 211.82.216.254 prefix-length 24<br>
第四步，定义内部网络中允许访问Internet的访问列表。<br>
定义内部访问列表命令的语法如下：<br>
access-listl 标号 permit 源地址 通配符（其中，标号为1~99之间的整数）<br>
access-listl permit 172.16.100.0 0.0.0.255 //允许访问Internet的网段为172.16.100.0~172.16.100.255，主机掩码为0.0.0.255。需要注意的是，在这里采用的是主机掩码，而非子网掩码。子网掩码与主机掩码的关系为：主机掩码+子网掩码=255.255.255.255。例如，子网掩码为255.255.0.0，则主机掩码为0.0.255.255；子网掩码为255.0.0.0,则主机掩码为0.255.255.255;子网掩码为255.252.0.0,则主机掩码为0.3.255.255;子网掩码为255.255.255.192，刚主机掩码为 0.0.0.63。<br>
另外，如果想将多个IP地址段转换为合法IP地址，可以添加多个访问列表。例如，当欲将172.16.98.0~172.16.98.255和172.16.99.0~172.16.99.255转换为合法IP地址时，应当添加下述命令：<br>
access-list2 permit 172.16.98.0~0.0.0.255<br>
access-list2 permit 172.16.99.0~0.0.0.255<br>
第五步，实现网络地址转换。<br>
在全局设置模式下，将由access-list指定的内部本地地址与指定的内部合法地址池进行地址转换。命令语法如下：<br>
ip nat inside source list 访问列表标号 pool 内部合法地址池名字<br>
示例：<br>
ip nat inside source list 1 pool chinanet<br>
如果有多个内部访问列表，可以一一添加，以实现网络地址转换，如<br>
ip nat insde source list 2 pool chinanet<br>
ip nat insde source list 2 pool chinanet<br>
如果有多个地址池，也可以一一添加，以增加合法地址池范围，如<br>
ip nat insde source list 2 pool cernet<br>
ip nat insde source list 2 pool cernet<br>
ip nat insde source list 2 pool cernet<br>
至此，动态地址转换设置完毕。<br>
3.端口复用动态地址转换<br>
内部网络使用的IP地址段为10.100.100.1~10.100.100.254,路由器局域网端口（即默认网关）的IP地址为10.100.100.1，子网掩码为255.255.255.0。网络分配的合法IP地址范围为202.99.160.0~202.99.160.3,路由器广域网中的IP地址为202.99.160.1,子网掩码为255.255.255.252，可用于转换的IP地址为202.99.160.2。要求将内部网址10.100.100.1~10.100.100.254 转换为合法IP地址202.99.160.2。<br>
第一步，设置外部端口。<br>
interface serial 0<br>
ip address 202.99.160.1 255.255.255.252<br>
in nat outside<br>
第二步，设置内部端口。<br>
interface ethernet 0<br>
?ip address 1.100.100.1 255.255.255.0<br>
?ip nat inside<br>
第三步，定义合法IP地址池。<br>
in nat pool onlyone 202.99.160.2 202.99.160.2 netmask 255.255.255.252<br>
// 指明地址缓冲池的名称为onlyone,IP地址范围为202.99.160.2,子网掩码为255.255.255.252。由于本例只有一个IP地址可用，所以，起始IP地址与终止IP地址均为202.99.160.2。如果有多个IP地址，则应当分别键入起止的IP直址。<br>
第四步，定义内部访问列。<br>
access-list 1 permit 10.100.100.0 0.0.0.255<br>
允许访问Internetr的网段为10.100.100.0~10.100.100.255，子网掩码为255.255.255.0。需要注意的是，在这里子网掩码的顺序跟平常所写的顺序相反，即0.255.255.255。<br>
第五步，设置复用动态地址转换。<br>
在全局设置模式下，设置在内部的本地地址与内部合法IP地址间建立复用动态地址转换。命令语法如下：<br>
ip nat inside source list访问列表号pool内部合法地址池名字overload<br>
示例：<br>
ip nat inside source list1 pool onlyone overload //以端口复用方式，将访问列表1中的私有IP地址转换为onlyone IP地址池中定义的合法IP地址。<br>
至此，端口复用动态地址转换完成。<br>
网络地址转换(NAT)-实例<br>
示例一：全部采用端口复用地址转换<br>
当ISP分配的IP地址数量很少，网络又没有其他特殊需求，即无需为Internet提供网络服务时，可采用端口利用地址转换方式，使网络内的计算机采用同一IP地址访问Internet，在节约IP地址资源的同时，又可有效保护网络内部的计算机。<br>
网络环境为：<br>
局域网采用10Mb/s光纤，以城域网方式接入Internet，如图4-2-2所示。路由器选用拥有2个10/100 Mb/s自适应端口的Cisco 2611。内部网络使用的IP地址段为192.168.100.1~192.101.254，局域网端口Ethernet 0的IP地址为192.168.100.1,子网掩码为255.255.0.0。网络分配的合法IP地址范围为202.99.160.128~202.99.160.131,连接ISP的端口Ethernet 1的IP地址为202.99.160.129,子网掩码为255.255.255.252。可用于转换的IP地址为202.99.160.130。要求网络内部的所有计算机均可访问Internet。<br>
案例分析：<br>
既然只有一个可用的合法IP地址，同时处于局域网的服务器又只为局域网提供服务，而不允许Internet中的主机对其访问，因此完全可以采用端口复用地址转换方式实现NAT，使得网络内的所有计算机均可独立访问Internet。<br>
配置清单：<br>
interface fastethernet0/0<br>
ip address 192.168.100.1 255.255.0.0 //定义本地端口IP地址<br>
duplex auto<br>
speed auto<br>
ip nat inside // 定义为本地端口<br>
!<br>
interface fastethernet0/1<br>
ip address 202.99.160.129 255.255.255.252<br>
duplx auto<br>
speed auto<br>
ip nat outside<br>
!<br>
ip nat pool onlyone 202.99.160.130 202.99.160.130 netmadk 255.255.255.252 //定义合法IP地址池，名称为onlyone access-list 1 permit 192.168.100.0 0.0.0.255 //定义本地访问列表<br>
access-list 1 permit 192.168.100.0 0.0.0.255<br>
ip nat inside source list1 pool onlyone overload //采用端口复用动态地址转换<br>
示例二：动态地址+端口复用地址转换<br>
许多FTP网站考虑到服务器性能和Internet连接带宽的占用问题，都限制同一IP地址的多个进程访问。如果采用端口复地址转换方式，则网络内的所以计算机都采用同一IP地址访问Internet,那么，将因此而被禁止对该网站的访问。所以，当提供的合法IP地址数量稍多时，可同时采用端口复用和动态地址转换方式，从而既可保证所有用户都能够获得访问Internet的权力，同时，又不致、某些计算机因使用同一IP地址而被限制权限。需要注意的是，由于所有计算机都采用动态地址转换方式，因此Internet中的所有计算机将无法实现对网络内部服务器的访问。<br>
网络环境：<br>
局域网以2Mb/s DNA专线接入Internet，路由器选用安装了广域网模块的Cisco 2611,如图4-2-2所示。内部网络使用的IP地址段为172.16.100.1~172.16.102.254,局域网端口Ethernet 0的IP地址为172.16.100.1,子网掩码为255.255.0.0。网络分配的合法IP地址范围为202.99.160.128~202.99.160.129,子网掩码为255.255.255.192,可用于转换的IP地址范围为202.99.160.130~202.99.160.190。要求网络部分的部分计算机可以不受任何限制地访问Internet，服务器无需提供Internet访问服务。<br>
案例分析：<br>
既然要求网络中的部分计算机可以不受任何限制地访问Internet,同时，服务器无需提供Internet访问服务，那么，只需采用动态地址转换+端口复用地址转换方式即可实现。部分有特殊需求的计算机采用动态地址转换的NAT方式，其他计算机则采用端口复用地址转换的NAT方式。因此，部分有特殊需求的计算机可采用内部网址172.16.100.1~172.16.100.254，并动态转换为合法地址202.99.160.130~202.99.160.189，其他计算机采用内部网址172.16.101.1~172.16.102.254,全部转换为202.99.160.190。<br>
配置清单：<br>
interface fastethernet0/1<br>
ip address 10.100.100.1 255.255.255.0 //定义局域网端口IP地址<br>
duplex auto<br>
speed auto<br>
ip nat inside //定义为局域端口<br>
!<br>
interface serial 0/0<br>
ip address 202.99.160.129 255.255.255.192 //定义广域网端口IP地址<br>
!<br>
duplex auto<br>
speed auto<br>
ip nat outside //定义为广域端口<br>
!<br>
ip nat pool public 202.99.160.130 202.130.160.190 netmask 255.255.255.192 //定义合法IP地址池，名称为public<br>
ip nat pool super 202.99.160.130 202.130.160.189 netmask 255.255.255.192 //定义合法IP地址池，名称为super<br>
ip nat inside source list1 pool super //定义列表达1采用动态地址转换<br>
ip nat inside source list2 pool public overload? //定义列表2采用端口复用地址转换<br>
access-list1 permit 172.16.100.0 0.0.0.255 //定义本地访问列表1<br>
access-list2 permit 172.16.102.0 0.0.0.255 //定义本地访问列表2<br>
access-list2 permit 172.16.102.0 0.0.0.255<br>
示例三：静态地址转换+端口复用地址转换<br>
其实在很多时候，网络中的服务器既为网络内部的客户提供网络服务，又同时为Internet中的用户提供访问服务。因此，如果采用端口复用地址转换或动态地址转换，将由于无法确定服务器的IP地址，而导致Internet用户无法实现对网络内部服务器的访问。此时，就应当采用静态地址转换+端口复用地址转换的NAT方式。也就是说，对服务器采用静态地址转换，以确保服务器拥有固定的合法IP地址。而对普通的客户计算机则采用端口复用地址转换，使所有用户都享有访问Internet的权力。<br>
网络环境为：<br>
局域网采用10Mb/s光纤，以城域网方式接入Internet，如图4-2-2所示。路由器选用拥有2个10/100 Mb/s自适应端口的Cisco 2611。内部网络使用的IP地址段为10.18.100.1~10.18.104.254,局域网端口Ethernet 0的IP地址为10.18.100.1,子网掩码为255.255.0.0。网络分配的合法IP地址范围为211.82.220.80~211.82.220.87，连接ISP的端口Ethernet 1的IP地址为211.82.220.81,子网掩码为255.255.255.248。要求网络内部的所有计算机均可访问Internet，并且在Internet中提供Web、E-mail、FTP和Media等4种服务。<br>
案例分析：<br>
既然网络内的服务器要求能够被Internet访问到，那么，这部分主机必须拥有合法的IP地址，也就是说，服务器必须采用静态地址转换。其他计算机由于没有任何限制，所以，可采用端口复用地址转换的NAT方式。因此，服务器可采用内网址10.18.100.1~10.18.100.254，并分别映射为一个合法的IP地址。其他计算机则采用内部网址10.18.101.1~172.16.104.254,并全部转换为一个合法的IP地址。<br>
配置清单：<br>
interface fastethernet0/0<br>
ip address 10.18.100.1 255.255.0.0 //定义局域网口IP地址<br>
duplex auto<br>
speed auto<br>
ip nat inside //定义局域网口<br>
!<br>
interface fastethernet0/1<br>
ip address 211.82.220.81 255.255.255.248 //定义广域网口IP地址<br>
duplex auto<br>
speed auto<br>
ip nat outside //定义广域网口<br>
!<br>
ip nat pool every 211.82.220.86 211.82.220.86 netmask 255.255.255.248 //定义合法IP地址池<br>
access-list 1 permit 10.18.101.0 0.0.0.255 //定义本地访问列表1<br>
access-list 1 premit 10.18.102.0 0.0.0.255<br>
access-list 1 premit 10.18.103.0 0.0.0.255<br>
access-list 1 premit 10.18.104.0 0.0.0.255<br>
ip nat inside source list1 pool every overload //定义列表达1采用端口复用地址转换<br>
ip nat inside source static 10.18.100.10 211.82.220.82 //定义静态地址转换<br>
ip nat inside source static 10.18.100.11 211.82.220.83<br>
ip nat inside source static 10.18.100.12 211.82.220.84<br>
ip nat inside source static 10.18.100.13 211.82.220.85<br>
示例四：TCP/UDP端口NAT映射<br>
如果ISP提供的合法IP地址的数量较多，我们自然可以采用静态地址转换+端口复用动态地址转换的方式得以完美实现。但如果ISP只提供4个IP地址，其中2个作为网络号和广播地址而不可使用，1个IP地址要用于路由器定义为默认网关， 那么将只剩下1个IP地址可用。当然我们也可以利用这个仅存的一个IP地址采用端口复用地址转换技术，从而实现整个局域网的Internet接入。但是由于服务器也采用动态端口，因此，Internet中的计算机将无法访问到网络内部的服务器。有没有好的解决问题的方案呢？这就是TCP/UDP端口NAT映射。<br>
我们知道，不同应用程序使用的TCP/UDP的端口是不同的，比如，Web服务使用50，FTP服务使用21，SMTP服务使用25，POP3服务使用110，等等。因此，可以将不同的TCP端口绑定至不同的内部IP地址，从而只使用一个合法的IP地址，即可在允许内部所有服务器被Internet访问的同时，实现内部所有主机对Internet访问。<br>
网络环境：<br>
局域网采用10Mb/s光纤，以城域网方式接入Internet，如图4-2-5所示。路由器选用拥有2个10/100 Mb/s自适应端口的Cisco 2611。内部网络使用的IP地址段为192.169.1.1~192.168.1.254，局域网端口Ethernet 0的IP地址为192.168.1.1,子网掩码为255.255.255.0。网络分配的合法IP地址范围为，211.82.220.128~211.82.220.131,连接ISP的端口Ethernet 1的IP地址为211.82.220.129,子网掩码为255.225.255.252，可用于转换的IP地址为211.82.220.130。要求网络内部的所有计算机均可访问Internet。<br>
案例分析：<br>
既然只有一个可用的合法IP地址，当然只能采用端口复用方式实现NAT，不过，由于同时又要求网络内部的服务器可以被Internet访问到，因此，必须使用PAT创建TCP/UDP端口的NAT映射。需要注意的是，也可以直接使用广域端口创建TCP/UDP端口的NAT映射，也就是说，即使只有一个IP地址，也可以完美实现端口复用。由于合法IP地址位于路由器端口上，所以，不再需要定义NAT池，只简单地使用inside source list语句即可。<br>
需要注意的是，由于每种应用服务都有自己默认的端口，所以，这种NAT方式下，网络内部每种应用服务中只能各自有一台服务器成为Internet中的主机，例如，只能有一台Web服务器，一台E-mail服务，一台FTP服务器。尽管可以采用改变默认端口的方式创建多台应用服务器，但这种服务器在访问时比较困难，要求用户必须先了解某种服务采用的新TCP端口。<br>
配置清单：<br>
interface fastethernet0/0<br>
ip address 10.18.100.1 255.255.0.0 //指定局域网口的IP地址<br>
duplex auto<br>
speed auto<br>
ip nat inside //指定局域网接口<br>
!<br>
interface fastethernet0/1<br>
ip address 211.82.220.129 255.255.255.248 //指定广域网口的IP地址<br>
access-list 1 permit 192.168.1.0 0.0.0.255<br>
!<br>
ip nat inside source list1 interface fastethernet0/1 overload //启用端口复用地址转换，并直接采用fastethernet0/1的IP地址。<br>
ip nat inside source static tcp 192.168.1.11 80 202.99.160.129.80<br>
ip nat inside source static tcp 192.168.1.12 21 202.99.160.129.21<br>
ip nat inside source static tcp 192.168.1.13 25 202.99.160.129.25<br>
ip nat inside source static tcp 192.168.1.13 110 202.99.160.129 110<br>
示例五：利用地址转换实现负载均衡<br>
随着访问量的上升，当一台服务器难以胜任时，就必须采用负载均衡技术，将大量的访问合理地分配至多台服务器上。当然，实现负载均衡的手段有许多种，比如可以采用服务器群集负载均衡、交换机负载均衡、DNS解析负载均衡等等。<br>
其实除此以外，也可以通过地址转换方式实现服务器的负载均衡。事实上，这些负载均衡的实现大多是采用轮询方式实现的，使每台服务器都拥有平等的被访问机会。<br>
网络环境：<br>
局域网以2Mb/s DDN专线拉入Internet,路由器选用安装了广域网模块的Cisco 2611,如图4-2-6所示。内部网络使用的IP地址段为10.1.1.1~10.1.3.254，局域网端口Ethernet 0的IP地址为10.1.1.1,子网掩码为255.255.0.0。网络分配的合法IP地址范围为202.110.198.80~202.110.198.87,连接ISP的端口Ethernet 1的IP地址为202.110.198.81,子网掩码为255.255.255.248。要求网络内部的所有计算机均可访问Internet，并且在3台Web服务器和2台FTP服务器实现负载均衡。<br>
案例分析：<br>
既然要求网络内所有计算机都可以接入Internet,而合法IP地址又只有5个可用，当然可采用端口复用地址转换方式。本来对服务器通过采用静态地址转换，赋予其合法IP地址即可。但是，由于服务器的访问量太大（或者是服务器的性能太差），不得不使用多台服务器作负载均衡，因此，必须将一个合法IP地址转换成多相内部IP地址，以轮询方式减轻每台服务器的访问压力。<br>
配置文件：<br>
interface fastethernet0/1<br>
ip adderss 10.1.1.1 255.255.0.0 //定义局域网端口IP地址<br>
duplex auto<br>
speed auto<br>
ip nat inside //定义为局域端口<br>
!<br>
interface serial 0/0<br>
ip address 202.110.198.81 255.255.255.248 //定义广域网端口IP地址<br>
duplex auto<br>
speed auto<br>
ip nat outside //定义为广域端口<br>
!<br>
access-list 1 permit 202.110.198.82 //定义轮询地址列表1<br>
access-list 2 permit 202.110.198.83<br>
access-list 3 permit 10.1.1.0 0.0.255.255 //定义本地访问列表3<br>
!<br>
ip nat pool websev 10.1.1.2 10.1.1.1 255.255.255.248 type rotary //定义Web服务器的IP地址池，Rotary关键字表示准备使用轮询策略从NAT池中取出相应的IP地址用于转换进来的IP报文，访问202.110.198.82的请求将依次发送给10.1.1.2、10.1.1.2和10.1.1.4<br>
ip nat pool ftpsev 10.1.1.8 10.1.1.9 255.255.255.248 type rotary<br>
ip nat pool normal 202.110.198.84 202.110.198.84 netmask 255.255.255.248 //定义合法IP地址池，名称为normal<br>
ip nat inside destination list 1 pool websev //inside destination list 语句定义与列表1相匹配的IP地址的报文将使用轮询策略<br>
ip nat inside destination list 2 pool ftpsev<br> ]]></description>
		<eb:creationDate>2008-04-20 17:53:55</eb:creationDate>
		<eb:modificationDate></eb:modificationDate>
    </item>
</channel>
</rss>