<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>大千世界 &#187; cisco</title>
	<atom:link href="http://www.zhangdaqian.net/blog/tag/cisco/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zhangdaqian.net</link>
	<description>Hold Infinity in the palm of your hand</description>
	<lastBuildDate>Wed, 14 Jul 2010 16:25:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>人生就像茶几，摆满了杯具</title>
		<link>http://www.zhangdaqian.net/blog/%e4%ba%ba%e7%94%9f%e5%b0%b1%e5%83%8f%e8%8c%b6%e5%87%a0%ef%bc%8c%e6%91%86%e6%bb%a1%e4%ba%86%e6%9d%af%e5%85%b7.htm</link>
		<comments>http://www.zhangdaqian.net/blog/%e4%ba%ba%e7%94%9f%e5%b0%b1%e5%83%8f%e8%8c%b6%e5%87%a0%ef%bc%8c%e6%91%86%e6%bb%a1%e4%ba%86%e6%9d%af%e5%85%b7.htm#comments</comments>
		<pubDate>Thu, 08 Oct 2009 10:19:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[life journey]]></category>
		<category><![CDATA[cisco]]></category>

		<guid isPermaLink="false">http://www.zhangdaqian.net/blog/%e4%ba%ba%e7%94%9f%e5%b0%b1%e5%83%8f%e8%8c%b6%e5%87%a0%ef%bc%8c%e6%91%86%e6%bb%a1%e4%ba%86%e6%9d%af%e5%85%b7.htm</guid>
		<description><![CDATA[人生就像茶几，摆满了杯具，偶尔洗洗就成了喜剧！
你还想看

NAT Order of Operation
NAT/PAT中对于FTP的处理，以及PAT后的非标准21 FTP端口设置

]]></description>
			<content:encoded><![CDATA[<p>人生就像茶几，摆满了杯具，偶尔洗洗就成了喜剧！</p>
<h3>你还想看</h3>
<ul class="related_post">
<li><a href="http://www.zhangdaqian.net/blog/nat-order-of-operation.htm" title="NAT Order of Operation">NAT Order of Operation</a></li>
<li><a href="http://www.zhangdaqian.net/blog/natpat%e4%b8%ad%e5%af%b9%e4%ba%8eftp%e7%9a%84%e5%a4%84%e7%90%86%ef%bc%8c%e4%bb%a5%e5%8f%8apat%e5%90%8e%e7%9a%84%e9%9d%9e%e6%a0%87%e5%87%8621-ftp%e7%ab%af%e5%8f%a3%e8%ae%be%e7%bd%ae.htm" title="NAT/PAT中对于FTP的处理，以及PAT后的非标准21 FTP端口设置">NAT/PAT中对于FTP的处理，以及PAT后的非标准21 FTP端口设置</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.zhangdaqian.net/blog/%e4%ba%ba%e7%94%9f%e5%b0%b1%e5%83%8f%e8%8c%b6%e5%87%a0%ef%bc%8c%e6%91%86%e6%bb%a1%e4%ba%86%e6%9d%af%e5%85%b7.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NAT Order of Operation</title>
		<link>http://www.zhangdaqian.net/blog/nat-order-of-operation.htm</link>
		<comments>http://www.zhangdaqian.net/blog/nat-order-of-operation.htm#comments</comments>
		<pubDate>Thu, 08 Oct 2009 10:16:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[cisco]]></category>

		<guid isPermaLink="false">http://www.zhangdaqian.net/blog/nat-order-of-operation.htm</guid>
		<description><![CDATA[Introduction
This document illustrates that the order in which transactions are processed using Network Address Translation (NAT) is based on whether a packet is going from the inside network to the outside network, or from the outside network to the inside network.
Prerequisites
Requirements
Readers of this document should have knowledge of the following topic:


Network Address Translation (NAT). For [...]]]></description>
			<content:encoded><![CDATA[<h2><a id="intro" name="intro">Introduction</a></h2>
<p>This document illustrates that the order in which transactions are processed using Network Address Translation (NAT) is based on whether a packet is going from the inside network to the outside network, or from the outside network to the inside network.</p>
<h2><a id="prereq" name="prereq">Prerequisites</a></h2>
<h3><a id="req" name="req">Requirements</a></h3>
<p>Readers of this document should have knowledge of the following topic:</p>
<ul>
<li>
<p>Network Address Translation (NAT). For more information on NAT, see <a href="http://www.cisco.com/warp/customer/556/nat-cisco.shtml">How NAT Works</a>.</p>
</li>
</ul>
<h3><a id="hw" name="hw">Components Used</a></h3>
<p>This document is not restricted to specific software and hardware versions.</p>
<p><strong>Note:</strong> The information in this document is based on the Software Version, Cisco IOS® Software Release 12.2(27)</p>
<h3><a id="conv" name="conv">Conventions</a></h3>
<p>For more information on document conventions, refer to the <a href="http://www.cisco.com/en/US/tech/tk801/tk36/technologies_tech_note09186a0080121ac5.shtml">Cisco Technical Tips Conventions</a>.</p>
<p> <span id="more-242"></span><br />
<h2><a id="topic1" name="topic1">NAT Overview</a></h2>
<p>In the table below, when NAT performs the global to local, or local to global, translation is different in each flow.</p>
<table cellpadding="3" width="60%" cellspacing="1" border="1" bgcolor="#FFFFFF">
<tbody>
<tr>
<th bgcolor="#CCCCFF">
<p>Inside-to-Outside</p>
</th>
<th bgcolor="#CCCCFF">
<p>Outside-to-Inside</p>
</th>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<ul>
<li>
<p>If IPSec then check input access list</p>
</li>
<li>
<p>decryption &#8211; for CET (Cisco Encryption Technology) or IPSec</p>
</li>
<li>
<p>check input access list</p>
</li>
<li>
<p>check input rate limits</p>
</li>
<li>
<p>input accounting</p>
</li>
<li>
<p>policy routing</p>
</li>
<li>
<p>routing</p>
</li>
<li>
<p>redirect to web cache</p>
</li>
<li>
<p><strong>NAT inside to outside (local to global translation)</strong></p>
</li>
<li>
<p>crypto (check map and mark for encryption)</p>
</li>
<li>
<p>check output access list</p>
</li>
<li>
<p>inspect (Context-based Access Control (CBAC))</p>
</li>
<li>
<p>TCP intercept</p>
</li>
<li>
<p>encryption</p>
</li>
<li>
<p>Queueing</p>
</li>
</ul>
</td>
<td bgcolor="#FFFFFF">
<ul>
<li>
<p>If IPSec then check input access list</p>
</li>
<li>
<p>decryption &#8211; for CET or IPSec</p>
</li>
<li>
<p>check input access list</p>
</li>
<li>
<p>check input rate limits</p>
</li>
<li>
<p>input accounting</p>
</li>
<li>
<p><strong>NAT outside to inside (global to local translation)</strong></p>
</li>
<li>
<p>policy routing</p>
</li>
<li>
<p>routing</p>
</li>
<li>
<p>redirect to web cache</p>
</li>
<li>
<p>crypto (check map and mark for encryption)</p>
</li>
<li>
<p>check output access list</p>
</li>
<li>
<p>inspect CBAC</p>
</li>
<li>
<p>TCP intercept</p>
</li>
<li>
<p>encryption</p>
</li>
<li>
<p>Queueing</p>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
<h2><a id="topic2" name="topic2">NAT Configuration and Output</a></h2>
<p>The following example demonstrates how the order of operations can effect NAT. In this case, only NAT and routing are shown.</p>
<p><img src="http://www.cisco.com/image/gif/paws/6209/5a-1.gif" height="123" width="575" usemap="" alt="5a-1.gif" border="0"/></p>
<p>In the above example, Router-A is configured to translate the inside local address 171.68.200.48 to 172.16.47.150, as shown in the configuration below.</p>
<blockquote>
<pre>
!
version 11.2
no service udp-small-servers
no service tcp-small-servers
!
hostname Router-A
!
enable password ww
!
<strong>ip nat inside source static 171.68.200.48 172.16.47.150</strong>
<em>
              <span style="COLOR: #0000ff">!--- This command creates a static NAT translation !--- between 171.68.200.48 and 172.16.47.150 </span>
            </em>
ip domain-name cisco.com
ip name-server 171.69.2.132
!
interface Ethernet0
 no ip address
 shutdown
!
interface Serial0
 ip address 172.16.47.161 255.255.255.240
 <strong>ip nat inside</strong>
<em>
              <span style="COLOR: #0000ff">!--- Configures Serial0 as the NAT inside interface</span>
            </em>
 no ip mroute-cache
 no ip route-cache
 no fair-queue
!
interface Serial1
 ip address 172.16.47.146 255.255.255.240
 <strong>ip nat outside</strong>
<em>
              <span style="COLOR: #0000ff">!--- Configures Serial1 as the NAT outside interface</span>
            </em>
 no ip mroute-cache
 no ip route-cache
!
no ip classless
<strong>ip route 0.0.0.0 0.0.0.0 172.16.47.145</strong>
<em>
              <span style="COLOR: #0000ff">!--- Configures a default route to 172.16.47.145</span>
            </em>

ip route 171.68.200.0 255.255.255.0 172.16.47.162
!
!
line con 0
 exec-timeout 0 0
line aux 0
line vty 0 4
 password ww
 login
!
end
</pre>
</blockquote>
<p>The translation table indicates that the intended translation exists.</p>
<blockquote>
<pre>
Router-A#<strong>show ip nat translation</strong>
Pro Inside global      Inside local       Outside local      Outside global
--- 172.16.47.150      171.68.200.48      ---                ---
</pre>
</blockquote>
<p>The following output is taken from Router-A with <strong><a href="http://www.cisco.com/en/US/docs/ios/12_3t/debug/command/reference/dbg_i2gt.html#wp1086651">debug ip packet detail</a></strong> and <strong><a href="http://www.cisco.com/en/US/docs/ios/12_3t/debug/command/reference/dbg_i2gt.html#wp1127362">debug ip nat</a></strong> enabled, and a ping issued from device 171.68.200.48 destined for 172.16.47.142.</p>
<p><strong>Note:</strong> Debug commands generate a significant amount of output. Use them only when traffic on the IP network is low, so other activity on the system is not adversely affected. Before issuing <strong>debug</strong> commands, please see <a href="http://www.cisco.com/en/US/tech/tk801/tk379/technologies_tech_note09186a008017874c.shtml">Important Information on Debug Commands</a>.</p>
<blockquote>
<pre>
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
    ICMP type=8, code=0
IP: s=172.16.47.161 (local), d=171.68.200.48 (Serial0), len 56, sending
    ICMP type=3, code=1
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
    ICMP type=8, code=0
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
    ICMP type=8, code=0
IP: s=172.16.47.161 (local), d=171.68.200.48 (Serial0), len 56, sending
    ICMP type=3, code=1
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
    ICMP type=8, code=0
IP: s=171.68.200.48 (Serial0), d=172.16.47.142, len 100, unroutable
    ICMP type=8, code=0
IP: s=172.16.47.161 (local), d=171.68.200.48 (Serial0), len 56, sending
    ICMP type=3, code=1
</pre>
</blockquote>
<p>Since there are no NAT debug messages in the output above, you know that the existing static translation is not being used and that the router does not have a route for the destination address (172.16.47.142) in its routing table. The result of the non-routable packet is an <a href="http://www.iana.org/assignments/icmp-parameters">ICMP Unreachable message</a>, which is sent to the inside device.</p>
<p>However, Router-A has a default route of 172.16.47.145, so why is the route considered non-routable?</p>
<p>Router-A has <strong>no ip classless</strong> configured, which means if a packet destined for a &#8220;major&#8221; network address (in this case, 172.16.0.0) for which subnets exist in the routing table, the router does not rely on the default route. In other words, issuing the <strong>no ip classless</strong> command turns off the router&#8217;s ability to look for the route with the longest bit match. To change this behavior, you have to configure <strong><a href="http://www.cisco.com/en/US/docs/ios/12_2/ipaddr/command/reference/fipras_r.html#wp1018033">ip classless</a></strong> on Router-A. The <strong><a href="http://www.cisco.com/en/US/docs/ios/12_2/ipaddr/command/reference/fipras_r.html#wp1018033">ip classless</a></strong> command is enabled by default on Cisco routers with IOS Version 11.3 and above.</p>
<blockquote>
<pre>
Router-A#<strong>configure terminal</strong>
Enter configuration commands, one per line.  End with CTRL/Z.
Router-A(config)#<strong>ip classless</strong>
Router-A(config)#<strong>end</strong>

Router-A#<strong>show ip nat translation</strong>
%SYS-5-CONFIG_I: Configured from console by console nat tr
Pro Inside global      Inside local       Outside local      Outside global
--- 172.16.47.150      171.68.200.48      ---                ---
</pre>
</blockquote>
<p>Repeating the same ping test as before, we see that the packet gets translated and the ping is successful.</p>
<blockquote>
<pre>
Ping Response on device 171.68.200.48

D:\&gt;ping 172.16.47.142
Pinging 172.16.47.142 with 32 bytes of data:

Reply from 172.16.47.142: bytes=32 time=10ms TTL=255
Reply from 172.16.47.142: bytes=32 time&lt;10ms TTL=255
Reply from 172.16.47.142: bytes=32 time&lt;10ms TTL=255
Reply from 172.16.47.142: bytes=32 time&lt;10ms TTL=255

Ping statistics for 172.16.47.142:
    Packets: Sent = 4, Received = 4, Lost = 0 (0%)
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum =  10ms, Average =  2ms

Debug messages on Router A indicating that the packets generated by device
171.68.200.48 are getting translated by NAT. 

Router-A#
<strong>*Mar 28 03:34:28: IP: tableid=0, s=171.68.200.48 (Serial0), d=172.16.47.142 (Serial1), routed via RIB</strong>
<strong>*Mar 28 03:34:28: NAT: s=171.68.200.48-&gt;172.16.47.150, d=172.16.47.142 [160]</strong>
<strong>*Mar 28 03:34:28: IP: s=172.16.47.150 (Serial0), d=172.16.47.142 (Serial1), g=172.16.47.145, len 100, forward</strong>
<strong>*Mar 28 03:34:28: ICMP type=8, code=0</strong>
<strong>*Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150-&gt;171.68.200.48 [160]</strong>
<strong>*Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), routed via RIB</strong>
<strong>*Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0), g=172.16.47.162, len 100, forward</strong>
<strong>*Mar 28 03:34:28: ICMP type=0, code=0</strong>
*Mar 28 03:34:28: NAT*: s=171.68.200.48-&gt;172.16.47.150, d=172.16.47.142 [161]
*Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150-&gt;171.68.200.48 [161]
*Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48
(Serial0), routed via RIB
*Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0),
g=172.16.47.162, len 100, forward
*Mar 28 03:34:28: ICMP type=0, code=0
*Mar 28 03:34:28: NAT*: s=171.68.200.48-&gt;172.16.47.150, d=172.16.47.142 [162]
*Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150-&gt;171.68.200.48 [162]
*Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48
(Serial0), routed via RIB
*Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0),
g=172.16.47.162, len 100, forward
*Mar 28 03:34:28: ICMP type=0, code=0
*Mar 28 03:34:28: NAT*: s=171.68.200.48-&gt;172.16.47.150, d=172.16.47.142 [163]
*Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150-&gt;171.68.200.48 [163]
*Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48
(Serial0), routed via RIB
*Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0),
g=172.16.47.162, len 100, forward
*Mar 28 03:34:28: ICMP type=0, code=0
*Mar 28 03:34:28: NAT*: s=171.68.200.48-&gt;172.16.47.150, d=172.16.47.142 [164]
*Mar 28 03:34:28: NAT*: s=172.16.47.142, d=172.16.47.150-&gt;171.68.200.48 [164]
*Mar 28 03:34:28: IP: tableid=0, s=172.16.47.142 (Serial1), d=171.68.200.48
(Serial0), routed via RIB
*Mar 28 03:34:28: IP: s=172.16.47.142 (Serial1), d=171.68.200.48 (Serial0),
g=172.16.47.162, len 100, forward
*Mar 28 03:34:28: ICMP type=0, code=0

Router-A#<strong>undebug all</strong>
All possible debugging has been turned off
</pre>
</blockquote>
<p>The above example shows that when a packet is traversing inside to outside, a NAT router checks its routing table for a route to the outside address before it continues to translate the packet. Therefore, it is important that the NAT router has a valid route for the outside network. The route to the destination network must be known through an interface that is defined as <a href="http://www.cisco.com/warp/customer/556/8.html">NAT outside</a> in the router configuration.</p>
<p>It is important to note that the return packets are translated before they are routed. Therefore, the NAT router must also have a valid route for the <a href="http://www.cisco.com/warp/customer/556/8.html">Inside local address</a> in its routing table.</p>
<h3>你还想看</h3>
<ul class="related_post">
<li><a href="http://www.zhangdaqian.net/blog/%e4%ba%ba%e7%94%9f%e5%b0%b1%e5%83%8f%e8%8c%b6%e5%87%a0%ef%bc%8c%e6%91%86%e6%bb%a1%e4%ba%86%e6%9d%af%e5%85%b7.htm" title="人生就像茶几，摆满了杯具">人生就像茶几，摆满了杯具</a></li>
<li><a href="http://www.zhangdaqian.net/blog/natpat%e4%b8%ad%e5%af%b9%e4%ba%8eftp%e7%9a%84%e5%a4%84%e7%90%86%ef%bc%8c%e4%bb%a5%e5%8f%8apat%e5%90%8e%e7%9a%84%e9%9d%9e%e6%a0%87%e5%87%8621-ftp%e7%ab%af%e5%8f%a3%e8%ae%be%e7%bd%ae.htm" title="NAT/PAT中对于FTP的处理，以及PAT后的非标准21 FTP端口设置">NAT/PAT中对于FTP的处理，以及PAT后的非标准21 FTP端口设置</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.zhangdaqian.net/blog/nat-order-of-operation.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NAT/PAT中对于FTP的处理，以及PAT后的非标准21 FTP端口设置</title>
		<link>http://www.zhangdaqian.net/blog/natpat%e4%b8%ad%e5%af%b9%e4%ba%8eftp%e7%9a%84%e5%a4%84%e7%90%86%ef%bc%8c%e4%bb%a5%e5%8f%8apat%e5%90%8e%e7%9a%84%e9%9d%9e%e6%a0%87%e5%87%8621-ftp%e7%ab%af%e5%8f%a3%e8%ae%be%e7%bd%ae.htm</link>
		<comments>http://www.zhangdaqian.net/blog/natpat%e4%b8%ad%e5%af%b9%e4%ba%8eftp%e7%9a%84%e5%a4%84%e7%90%86%ef%bc%8c%e4%bb%a5%e5%8f%8apat%e5%90%8e%e7%9a%84%e9%9d%9e%e6%a0%87%e5%87%8621-ftp%e7%ab%af%e5%8f%a3%e8%ae%be%e7%bd%ae.htm#comments</comments>
		<pubDate>Sat, 19 Sep 2009 14:40:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tech]]></category>
		<category><![CDATA[cisco]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[nat]]></category>

		<guid isPermaLink="false">http://www.zhangdaqian.net/blog/natpat%e4%b8%ad%e5%af%b9%e4%ba%8eftp%e7%9a%84%e5%a4%84%e7%90%86%ef%bc%8c%e4%bb%a5%e5%8f%8apat%e5%90%8e%e7%9a%84%e9%9d%9e%e6%a0%87%e5%87%8621-ftp%e7%ab%af%e5%8f%a3%e8%ae%be%e7%bd%ae.htm</guid>
		<description><![CDATA[
这里先要对FTP的两种模式说一下：

引用一张Cisco上面的图：
http://www.cisco.com/image/gif/paws/82018/pix-asa-enable-ftp-2.gif

 
FTP分为两种模式： 主动Active 被动 Passive
主动模式下是使用21作为控制， 20作为数据口。
首先是客户端通过大于1023的端口发起到服务器21端口的控制连接，信息交换完成后。服务器从20端口发起连接到客户端提供的接收端口。
这是传统意义上的FTP行为。
被动模式是使用21作为控制，然后服务器自动选择一个大于1023的端口作为数据。
首先是客户端通过大于1023的端口发起到服务器21端口的控制连接，信息交换完成后。服务器告诉客户端一个大于1023的端口作为数据口，
然后客户端再以另外一个大于1023的端口发起连接到服务器提供的数据端口进行数据传输。
目前大多数服务器都支持这种模式，而且大部分客户端都默认采用被动模式和服务器进行传输。
好了，当我们在内网有两台服务器FTP SEVER1和FTP SERVER2都需要被外网访问的时侯，我们会分别为这两个服务器做映射出去。
假定FTP SERVE1(10.0.0.100)占用公网IP(x.x.x.x)的21端口，FTP SERVER2(10.0.0.200)占用公网IP(x.x.x.x)的2211端口。那么我们就会这么写：
ip nat inside source static tcp 10.0.0.100 21 x.x.x.x 21 extendable

ip nat inside source static tcp 10.0.0.200 21 x.x.x.x 2211 extendable
这样做了以后，我们会发现FTP SERVER1是正常的，而FTP SERVER2却不正常，表现为登录以后无法列出目录:
以下为FTP 客户端的LOG：


[xx:xx:03] PASV [xx:xx:03] 227 Entering Passive Mode (10,0,0,200,6,32) [xx:xx:24] Data Socket Error: Connection timed out [xx:xx:24] List Complete: 0 bytes in 21.44 (1.00 [...]]]></description>
			<content:encoded><![CDATA[<div>
<div>这里先要对FTP的两种模式说一下：</div>
</p></div>
<div>引用一张Cisco上面的图：</div>
<div><a href="http://www.cisco.com/image/gif/paws/82018/pix-asa-enable-ftp-2.gif">http://www.cisco.com/image/gif/paws/82018/pix-asa-enable-ftp-2.gif</a></div>
<div><img src="http://www.cisco.com/image/gif/paws/82018/pix-asa-enable-ftp-2.gif" style="WIDTH: 564px; HEIGHT: 457px" height="30" width="179" usemap="" alt="pix-asa-enable-ftp-2.gif" border="0"/></div>
<p> <span id="more-240"></span>
<div>FTP分为两种模式： 主动Active 被动 Passive</div>
<div>主动模式下是使用21作为控制， 20作为数据口。</div>
<div>首先是客户端通过大于1023的端口发起到服务器21端口的控制连接，信息交换完成后。服务器从20端口发起连接到客户端提供的接收端口。</div>
<div>这是传统意义上的FTP行为。</div>
<div>被动模式是使用21作为控制，然后服务器自动选择一个大于1023的端口作为数据。</div>
<div>首先是客户端通过大于1023的端口发起到服务器21端口的控制连接，信息交换完成后。服务器告诉客户端一个大于1023的端口作为数据口，</div>
<div>然后客户端再以另外一个大于1023的端口发起连接到服务器提供的数据端口进行数据传输。</div>
<div>目前大多数服务器都支持这种模式，而且大部分客户端都默认采用被动模式和服务器进行传输。</div>
<div>好了，当我们在内网有两台服务器FTP SEVER1和FTP SERVER2都需要被外网访问的时侯，我们会分别为这两个服务器做映射出去。</div>
<div>假定FTP SERVE1(10.0.0.100)占用公网IP(x.x.x.x)的21端口，FTP SERVER2(10.0.0.200)占用公网IP(x.x.x.x)的2211端口。那么我们就会这么写：</div>
<div>ip nat inside source static tcp 10.0.0.100 21 x.x.x.x 21 extendable</div>
<div>
<div>ip nat inside source static tcp 10.0.0.200 21 x.x.x.x 2211 extendable</div>
<div>这样做了以后，我们会发现FTP SERVER1是正常的，而FTP SERVER2却不正常，表现为登录以后无法列出目录:</div>
<div>以下为FTP 客户端的LOG：</div>
<div>
<hr/></div>
<div>[xx:xx:03] PASV <br/>[xx:xx:03] 227 Entering Passive Mode (10,0,0,200,6,32) <br/>[xx:xx:24] Data Socket Error: Connection timed out <br/>[xx:xx:24] List Complete: 0 bytes in 21.44 (1.00 KBps)<br />
<hr/></div>
<div>这是为什么呢？</div>
<div>答案就是在被动模式下，FTP SEVER告诉客户端的数据端口，无法被访问。为什么 FTP SERVER1又可以呢？</div>
<div>因为FTP SERVER1在对外映射的时侯采用了21端口，IOS会自动识别这个端口是FTP控制口，</div>
<div>从而去检查里面FTP数据控制数据发现服务器告诉客户端的这个用于传送数据的端口，然后自动的添加一条映射。</div>
<div>phanx# sh ip nat tr | in 10.0.0.100: <br/>tcp x.x.x.x:21 10.0.0.100:21 y.y.y.y:1585 y.y.y.y:1585 <br/>tcp x.x.x.x:21 10.0.0.100:21 &#8211; - <br/>tcp x.x.x.x:1812 10.0.0.20:1812 y.y.y.y:1594 y.y.y.y:1594</div>
<div>而FTP SERVER2映射的端口2211无法自动被识别成FTP端口，所以IOS不会自动的为它建立数据端口的映射。</div>
<div>解决的办法就是用 ip nat service 来指定这个端口。</div>
<div>access-list <strong>10</strong> permit 10.0.0.200</div>
<div>ip nat service <strong>10</strong> ftp tcp port 21</div>
<div>注意，这里的tcp port 21是指的 10.0.0.200的FTP端口21而不是 x.x.x.x的2211。如果FTP SERVER2用的FTP端口是其他的，那么就写对应的端口号。</div>
<div>这样做了以后，我们的FTP SERVER2就可以以 x.x.x.x:2211 的方式被公网访问了。</div>
<div>说道这里，问题已经解决了。但是，有人可能会提出来，既然FTP SERVER1用被动很正常，x.x.x.x:20端口并没有使用，</div>
<div>那为什么不用把FTP SERVER2主动模式来映射呢？比如这样做:</div>
<div>ip nat inside source static tcp 10.0.0.200 20 x.x.x.x 20 extendable</div>
<div>
<div>ip nat inside source static tcp 10.0.0.200 21 x.x.x.x 2211 extendable</div>
</p></div>
<div>OK. 这样做其实对于一部分情况是没有问题的。例如客户机的地址是公网地址，或者说能被FTP SERVER2所访问的地址。</div>
<div>但是如果客户机也是通过NAT/PAT上网的呢？假设客户端地址是192.168.1.111我们将看到这样的情况：</div>
<div>
<hr/></div>
<div>[00:14:10] PORT <strong><span style="COLOR: #ff0000">192,168,1,111</span></strong> ,6,179 <br/>[00:14:10] 200 PORT Command successful. <br/>[00:14:10] REST 2028256 <br/>[00:14:10] 350 Restarting at 2028256. Send STORE or RETRIEVE. <br/>[00:14:10] RETR fool.exe <br/>[00:14:10] 150 Opening BINARY mode data connection for fool.exe (924668 Bytes). <br/>[00:14:11] 425 Cannot open data connection. <br/>[00:14:11] Transfer Failed!<br />
<hr/></div>
<div>因为是主动模式，是服务器主动送数据给客户机。那客户机通过控制信息就需要告诉服务器往哪里送，</div>
<div>但是FTP客户端并不知道自己的公网地址和端口，并且客户机也没有能力去自己的NAT/PAT网关上去开放一个端口让服务器来送数据。</div>
<div>所以它是以自己的实际地址去告诉服务器的。对于服务器而言，这个地址是无法被访问到的，所以这个办法也有行不通的地方。</div>
<div>当然，如果FTP客户端支持uPNP能识别到翻译后的公网地址，NAT/PAT网关也有uPNP的能力的话，主动模式的这个问题应该就能解决。</div>
<div>BTW：主动模式的FTP又被称为 &#8220;firewall <span style="COLOR: #ff0000">UN</span>friendly&#8221;，什么原因？ 好好理解哦～</div>
<div>PIX/ASA上面的配置方法见：</div>
<div>
<h2><strong>PIX/ASA 7.x: Enable FTP/TFTP Services Configuration Example</strong></h2>
<p><a href="http://www.cisco.com/en/US/products/ps6120/products_configuration_example09186a00807ee585.shtml">http://www.cisco.com/en/US/products/ps6120/products_configuration_example09186a00807ee585.shtml</a></p>
</p></div>
</p></div>
<h3>你还想看</h3>
<ul class="related_post">
<li><a href="http://www.zhangdaqian.net/blog/%e4%ba%ba%e7%94%9f%e5%b0%b1%e5%83%8f%e8%8c%b6%e5%87%a0%ef%bc%8c%e6%91%86%e6%bb%a1%e4%ba%86%e6%9d%af%e5%85%b7.htm" title="人生就像茶几，摆满了杯具">人生就像茶几，摆满了杯具</a></li>
<li><a href="http://www.zhangdaqian.net/blog/nat-order-of-operation.htm" title="NAT Order of Operation">NAT Order of Operation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.zhangdaqian.net/blog/natpat%e4%b8%ad%e5%af%b9%e4%ba%8eftp%e7%9a%84%e5%a4%84%e7%90%86%ef%bc%8c%e4%bb%a5%e5%8f%8apat%e5%90%8e%e7%9a%84%e9%9d%9e%e6%a0%87%e5%87%8621-ftp%e7%ab%af%e5%8f%a3%e8%ae%be%e7%bd%ae.htm/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
