本文件提供使用 ip nat outside source list 指令的範例組態,並包含 NAT 程序中 IP 封包實際情況的簡要說明。您可使用此指令,轉譯從網路外傳送至網路內之 IP 封包的來源位址。此操作轉換反向傳輸的IP資料包的目的地址(從網路內部到網路外部)。在網路重疊,也就是內部網路位址和外部網路位址重疊的情況下,此指令相當實用。網路圖就是一個例子。
本文件沒有特定需求。
本文件所述內容不限於特定軟體和硬體版本。但是本檔案中的資訊是根據以下軟體和硬體版本:
Cisco 2500系列路由器
在所有路由器上運行的Cisco IOS®軟體版本12.2(24a)
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路正在作用,請確保您已瞭解任何指令可能造成的影響。
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
本節提供用於設定本文件中所述功能的資訊。
注意:要查詢有關本文檔中使用的命令的其他資訊,請使用命令查詢工具(僅限註冊客戶)。
本檔案會使用以下網路設定:
從Router 2514W Loopback0介面(172.16.88.1)向路由器2501E Loopback0介面(171.68.1.1)發出ping命令時,會發生以下情況:
路由器2514W將資料包轉發到路由器2514X,因為它配置了預設路由。在路由器2514X的外部介面上,資料包的源地址(SA)為172.16.88.1,目標地址(DA)為171.68.1.1。由於ip nat outside source list命令所使用的access-list 1中允許SA,因此將其轉換為NAT池Net171中的地址。請注意,ip nat outside source list命令引用NAT池「Net171」。 在這種情況下,地址將轉換為171.68.16.10,這是NAT池中的第一個可用地址。轉換後,路由器2514X在路由表中查詢目標,然後路由資料包。路由器2501E在其傳入介面上看到SA為171.68.16.10且DA為171.68.1.1的資料包。它通過向171.68.16.10傳送網際網路控制消息協定(ICMP)回應回覆進行響應。如果沒有路由,則丟棄該資料包。在本例中,它有一個(預設)路由,因此它使用SA 171.68.1.1和DA 171.68.16.10將資料包傳送到路由器2514X。路由器2514X在其內部介面上看到該資料包,並檢查通往171.68.16.10地址的路由。如果沒有回應,則會使用ICMP無法到達回覆進行回應。在本例中,由於ip nat outside source命令的add-route選項(該選項根據外部全域性地址與外部本地地址之間的轉換新增主機路由),因此它有到171.68.16.10的路由,所以它將資料包轉換回172.16.88.1地址,並將資料包路由出其外部介面。
路由器2514W |
---|
hostname 2514W ! !--- Output suppressed. interface Loopback0 ip address 172.16.88.1 255.255.255.0 ! !--- Output suppressed. interface Serial0 ip address 172.16.191.254 255.255.255.252 no ip mroute-cache ! !--- Output suppressed. ip classless ip route 0.0.0.0 0.0.0.0 172.16.191.253 !--- Default route to forward packets to 2514X. ! !--- Output suppressed. |
路由器2514X |
---|
hostname 2514X ! !--- Output suppressed. ! interface Ethernet1 ip address 171.68.192.202 255.255.255.0 ip nat inside no ip mroute-cache no ip route-cache ! !--- Output suppressed. interface Serial1 ip address 172.16.191.253 255.255.255.252 ip nat outside no ip mroute-cache no ip route-cache clockrate 2000000 ! ip nat pool Net171 171.68.16.10 171.68.16.254 netmask 255.255.255.0 !--- NAT pool defining Outside Local addresses to be used for translation. ! ip nat outside source list 1 pool Net171 add-route !--- Configures translation for Outside Global addresses !--- with the NAT pool. ip classless ip route 172.16.88.0 255.255.255.0 172.16.191.254 ip route 171.68.1.0 255.255.255.0 171.68.192.201 !--- Static routes for reaching the loopback interfaces !--- on 2514W and 2501E. access-list 1 permit 172.16.88.0 0.0.0.255 !--- Access-list defining Outside Global addresses to be translated. ! !--- Output suppressed. ! |
路由器2501E |
---|
hostname 2501E ! !--- Output suppressed. interface Loopback0 ip address 171.68.1.1 255.255.255.0 ! interface Ethernet0 ip address 171.68.192.201 255.255.255.0 ! !--- Output suppressed. ip classless ip route 0.0.0.0 0.0.0.0 171.68.192.202 !--- Default route to forward packets to 2514X. ! !--- Output suppressed. |
本節提供的資訊可用於確認您的組態是否正常運作。
輸出直譯器工具(僅供註冊客戶使用)支援某些show命令,此工具可讓您檢視show命令輸出的分析。
show ip nat translations命令可用於檢查轉換條目,如下輸出所示。
2514X# show ip nat translations Pro Inside global Inside local Outside local Outside global --- 171.68.1.1 171.68.1.1 171.68.16.10 172.16.88.1 --- --- --- 171.68.16.10 172.16.88.1 2514X#
上面的輸出顯示,外部全域性地址172.16.88.1(路由器2514W的Loopback0介面上的地址)被轉換為外部本地地址171.68.16.10。
您可以使用show ip route 命令檢查路由表專案,如下所示:
2514X# show ip route Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 ia - IS-IS inter area, * - candidate default, U - per-user static route o - ODR, P - periodic downloaded static route Gateway of last resort is not set 171.68.0.0/16 is variably subnetted, 3 subnets, 2 masks C 171.68.192.0/24 is directly connected, Ethernet1 S 171.68.1.0/24 [1/0] via 171.68.192.201 S 171.68.16.10/32 [1/0] via 172.16.88.1 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks S 172.16.88.0/24 [1/0] via 172.16.191.254 C 172.16.191.252/30 is directly connected, Serial1 2514X#
輸出中顯示了外部本地地址171.68.16.10的/32路由,該路由是由ip nat outside source命令的add-route選項建立的。此路由用於路由和轉換從網路內部傳輸到網路外部的資料包。
本節提供的資訊可用於對組態進行疑難排解。
此輸出是在路由器2514X上運行debug ip packet和debug ip nat 命令的結果,同時從路由器2514W loopback0介面地址(172.16.88.1)對路由器2501E loopback0介面地址(171.68.1.1)執行ping:
*Mar 1 00:02:48.079: NAT*: s=172.16.88.1->171.68.16.10, d=171.68.1.1 [95] !--- The source address in the first packet arriving on !--- the outside interface is first translated. *Mar 1 00:02:48.119: IP: tableid=0, s=171.68.16.10 (Serial1), d=171.68.1.1 (Ethernet1), routed via RIB *Mar 1 00:02:48.087: IP: s=171.68.16.10 (Serial1), d=171.68.1.1 (Ethernet1), g=171.68.192.201, len 100, forward !--- The ICMP echo request packet with the translated source address !--- is routed and forwarded on the inside interface. *Mar 1 00:02:48.095: IP: tableid=0, s=171.68.1.1 (Ethernet1), d=171.68.16.10 (Serial1), routed via RIB !--- The ICMP echo reply packet arriving on the inside interface !--- is first routed based on the destination address. *Mar 1 00:02:48.099: NAT: s=171.68.1.1, d=171.68.16.10->172.16.88.1 [95] !--- The destination address in the packet is then translated. *Mar 1 00:02:48.103: IP: s=171.68.1.1 (Ethernet1), d=172.16.88.1 (Serial1), g=172.16.191.254, len 1 00, forward !--- The ICMP echo reply packet with the translated destination !--- address is forwarded on the outside interface.
對外部介面上接收的每個資料包重複上述過程。
使用ip nat outside source list命令(動態NAT)而不是ip nat outside source static命令(靜態NAT)的主要區別在於,在路由器(針對NAT配置)驗證資料包的轉換條件之前,轉換表中沒有條目。在上方範例中,具有SA 172.16.88.1(進入路由器2514X的外部介面)的封包符合access-list 1(ip nat outside source list 指令所使用的標準)。因此,資料包必須來自外部網路,內部網路的資料包才能與路由器2514W loopback0介面通訊。
在此示例中,需要注意兩個重要事項。
首先,當資料包從外部傳輸到內部時,首先進行轉換,然後檢查路由表以查詢目標。當資料包從內部傳輸到外部時,首先檢查路由表以查詢目標,然後進行轉換。
其次,必須注意使用上述每個命令時IP資料包的哪個部分被轉換。下表包含一條准則:
指令 | 動作 |
---|---|
ip nat outside source list |
|
ip nat inside source list |
|
以上准則表明有多種方式可以轉換資料包。根據您的特定需求,您應確定如何定義NAT介面(內部或外部),以及路由表在轉換之前或之後應包含哪些路由。請記住,資料包的轉換部分取決於資料包的傳輸方向以及您如何配置NAT。
修訂 | 發佈日期 | 意見 |
---|---|---|
1.0 |
26-Sep-2014 |
初始版本 |