本產品的文件集力求使用無偏見用語。針對本文件集的目的,無偏見係定義為未根據年齡、身心障礙、性別、種族身分、民族身分、性別傾向、社會經濟地位及交織性表示歧視的用語。由於本產品軟體使用者介面中硬式編碼的語言、根據 RFP 文件使用的語言,或引用第三方產品的語言,因此本文件中可能會出現例外狀況。深入瞭解思科如何使用包容性用語。
思科已使用電腦和人工技術翻譯本文件,讓全世界的使用者能夠以自己的語言理解支援內容。請注意,即使是最佳機器翻譯,也不如專業譯者翻譯的內容準確。Cisco Systems, Inc. 對這些翻譯的準確度概不負責,並建議一律查看原始英文文件(提供連結)。
本文件說明如何在 NAT 環境中疑難排解 IP 連線問題。
本文件沒有特定需求。
本文件所述內容不限於特定軟體和硬體版本。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
如需文件慣例的詳細資訊,請參閱思科技術提示慣例。
本文檔介紹了如何通過檢視以下兩個示例來排除NAT環境中的IP連線問題:
下面的基本步驟有助於確定NAT操作中是否存在問題:
1.檢驗配置,並明確定義NAT應該實現的目標。根據檢查,您可以確定是否存在配置問題。有關NAT配置的資訊,請參閱配置網路地址轉換。
2.驗證轉換表中是否存在正確的轉換。
3.使用show和debug命令驗證轉換是否發生。
4.詳細檢查資料包發生的情況,並檢驗路由器是否具有轉發資料包所需的正確路由資訊。
在第一種情況中,路由器4可以ping路由器5(172.16.6.5),但不能ping路由器7(172.16.11.7):
Router4#ping 172.16.6.5
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.6.5, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 1/1/2 ms
Router4#ping 172.16.11.7
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.11.7, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
Router4#
關於此場景的重要注意事項:
interface GigabitEthernet1
ip address 172.16.11.6 255.255.255.0
ip nat outside
negotiation auto
no mop enabled
no mop sysid
!
interface GigabitEthernet2
ip address 172.16.6.6 255.255.255.0
ip nat outside
negotiation auto
no mop enabled
no mop sysid
!
interface GigabitEthernet3
ip address 10.10.10.6 255.255.255.0
ip nat inside
negotiation auto
no mop enabled
no mop sysid
!
!
ip nat pool test 172.16.11.70 172.16.11.71 prefix-length 24 ip nat inside source static 10.10.10.4 172.16.6.14 ip nat inside source list 7 pool test
!
ip access-list standard 7
10 permit 10.10.50.4
20 permit 10.10.60.4
30 permit 10.10.70.4
1.首先,您需要確定NAT是否正常工作。根據先前的配置,可以確定Router 4的IP地址10.10.10.4已靜態轉換為172.16.6.14。您可以在Router 6上使用show ip nat translation命令以驗證轉換表中是否存在轉換:
NAT-Router#show ip nat translations
Pro Inside global Inside local Outside local Outside global
--- 172.16.6.14 10.10.10.4 --- ---
Total number of translations: 1
NAT-Router#
2.確保Router 4發出IP流量時進行此轉譯。您可以從Router6以兩種方式完成此操作。使用show ip nat statistics命令運行NAT調試或監控NAT統計資訊。由於debug命令是最後選用命令,因此請從show命令開始。
3.監控計數器以確保它隨著從Router 4接收流量而增大。每次使用轉換表轉換地址時,計數器都會遞增。
4.清除統計資訊,然後顯示統計資訊,然後嘗試從Router 4對Router 7執行ping,然後再次顯示統計資訊。
NAT-Router#clear ip nat statistics
NAT-Router#
NAT-Router#show ip nat statistics
Total active translations: 1 (1 static, 0 dynamic; 0 extended)
Outside interfaces:
GigabitEthernet1, GigabitEthernet2
Inside interfaces:
GigabitEthernet3
Hits: 0 Misses: 0
Expired translations: 0
Dynamic mappings:
-- Inside Source
[Id: 1] access-list 7 pool test refcount 0
pool test: id 1, netmask 255.255.255.0
start 172.16.11.70 end 172.16.11.71
type generic, total addresses 2, allocated 0 (0%), misses 0
nat-limit statistics:
max entry: max allowed 0, used 0, missed 0
In-to-out drops: 0 Out-to-in drops: 0
Pool stats drop: 0 Mapping stats drop: 0
Port block alloc fail: 0
IP alias add fail: 0
Limit entry add fail: 0
NAT-Router#
在Router 4上使用ping 172.16.11.7命令後,Router 6上的NAT統計資訊為:
Router4#ping 172.16.11.7
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.11.7, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
Router4#
NAT-Router#show ip nat statistics
Total active translations: 2 (1 static, 1 dynamic; 1 extended)
Outside interfaces:
GigabitEthernet1, GigabitEthernet2
Inside interfaces:
GigabitEthernet3
Hits: 4 Misses: 1
Expired translations: 0
Dynamic mappings:
-- Inside Source
[Id: 1] access-list 7 pool test refcount 0
pool test: id 1, netmask 255.255.255.0
start 172.16.11.70 end 172.16.11.71
type generic, total addresses 2, allocated 0 (0%), misses 0
nat-limit statistics:
max entry: max allowed 0, used 0, missed 0
In-to-out drops: 0 Out-to-in drops: 0
Pool stats drop: 0 Mapping stats drop: 0
Port block alloc fail: 0
IP alias add fail: 0
Limit entry add fail: 0
NAT-Router#
您可以從show命令中看到命中數遞增。如果從思科路由器成功執行ping,命中數將增加10。轉換源路由器(路由器4)傳送的網際網路控制消息協定(ICMP)回應,並且還需要轉換來自目標路由器(路由器7)的回應應答資料包,總共有10次命中。5次命中的丟失是因為未轉換回應回覆或未從Router 7傳送。
接下來,檢視是否可以找到路由器7不將回應回覆封包傳送到路由器4的任何原因。此時此刻,接下來的步驟已經發生:
注意:確認資料包是否到達目的路由器的另一個選項是使用嵌入式資料包捕獲(EPC)或使用帶有訪問清單(ACL)的debug ip icmp/debug ip資料包。
現在,您需要檢查Router 7的路由表,以驗證是否存在通往172.16.6.14的路由:
Router7#show ip route
Codes: L - local, C - connected, S - static, 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, m - OMP
n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
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
H - NHRP, G - NHRP registered, g - NHRP registration summary
o - ODR, P - periodic downloaded static route, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
& - replicated local route overrides by connected
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks
C 172.16.11.0/24 is directly connected, GigabitEthernet1
L 172.16.11.7/32 is directly connected, GigabitEthernet1
Router7#
從先前的輸出中,您可以觀察到Router 7的路由表中沒有用於172.16.6.14子網的路由。更正此錯誤並將路由新增到配置後,ping就會工作。 使用show ip nat statistics命令監控NAT統計資訊非常有用。但是,在包含多個轉換的更複雜的NAT環境中,此show命令不再有用,需要在路由器上使用調試。
Router7#configure terminal Enter configuration commands, one per line. End with CNTL/Z. Router7(config)#ip route 172.16.6.0 255.255.255.0 172.16.11.6 Router7(config)#end Router7#
Router4#ping 172.16.11.7 Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 172.16.11.7, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/8 ms Router4#
NAT-Router#show ip nat statistics Total active translations: 2 (1 static, 1 dynamic; 1 extended) Outside interfaces: GigabitEthernet1, GigabitEthernet2 Inside interfaces: GigabitEthernet3 Hits: 9 Misses: 1 Expired translations: 0 Dynamic mappings: -- Inside Source [Id: 1] access-list 7 pool test refcount 0 pool test: id 1, netmask 255.255.255.0 start 172.16.11.70 end 172.16.11.71 type generic, total addresses 2, allocated 0 (0%), misses 0 nat-limit statistics: max entry: max allowed 0, used 0, missed 0 In-to-out drops: 0 Out-to-in drops: 0 Pool stats drop: 0 Mapping stats drop: 0 Port block alloc fail: 0 IP alias add fail: 0 Limit entry add fail: 0 NAT-Router#
在此問題中,Router 4可以ping通Router 5和Router 7,但10.10.50.0網路上的裝置無法與Router 5或Router 7通訊。
Router4#ping 172.16.11.7 source 10.10.50.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.11.7, timeout is 2 seconds:
Packet sent with a source address of 10.10.50.4
.....
Success rate is 0 percent (0/5)
Router4#ping 172.16.6.5 source 10.10.50.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.6.5, timeout is 2 seconds:
Packet sent with a source address of 10.10.50.4
.....
Success rate is 0 percent (0/5)
Router4#
此問題的網路圖保持不變:
interface GigabitEthernet1
ip address 172.16.11.6 255.255.255.0
ip nat outside
negotiation auto
no mop enabled
no mop sysid
!
interface GigabitEthernet2
ip address 172.16.6.6 255.255.255.0
ip nat outside
negotiation auto
no mop enabled
no mop sysid
!
interface GigabitEthernet3
ip address 10.10.10.6 255.255.255.0
ip nat inside
negotiation auto
no mop enabled
no mop sysid
!
!
ip nat pool test 172.16.11.70 172.16.11.71 prefix-length 24 ip nat inside source static 10.10.10.4 172.16.6.14 ip nat inside source list 7 pool test
!
ip access-list standard 7
10 permit 10.10.50.4
20 permit 10.10.60.4
30 permit 10.10.70.4
從Router 6的配置中,可以看到NAT應該將10.10.50.4動態轉換為NAT池中第一個名為test的可用地址。地址池包含地址172.16.11.70和172.16.11.71。通過此問題,您可以瞭解路由器5和路由器7收到的資料包的源地址是172.16.11.70或172.16.11.71。這些地址與Router 7位於同一子網中,因此Router 7必須具有到該子網的直連路由,但是,如果它還沒有該路由,Router 5需要到該子網的路由。
您可以使用show ip route命令來檢視Router 5路由表確實列出了172.16.11.0:
Router5#show ip route
Codes: L - local, C - connected, S - static, 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, m - OMP
n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
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
H - NHRP, G - NHRP registered, g - NHRP registration summary
o - ODR, P - periodic downloaded static route, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
& - replicated local route overrides by connected
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 3 subnets, 2 masks
C 172.16.6.0/24 is directly connected, GigabitEthernet1
L 172.16.6.5/32 is directly connected, GigabitEthernet1
S 172.16.11.0/24 [1/0] via 172.16.6.6
您可以使用show ip route命令檢視Router 7路由表將172.16.11.0列為直連子網:
Router7#show ip route
Codes: L - local, C - connected, S - static, 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, m - OMP
n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA
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
H - NHRP, G - NHRP registered, g - NHRP registration summary
o - ODR, P - periodic downloaded static route, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
& - replicated local route overrides by connected
Gateway of last resort is not set
172.16.0.0/16 is variably subnetted, 3 subnets, 2 masks
S 172.16.6.0/24 [1/0] via 172.16.11.6
C 172.16.11.0/24 is directly connected, GigabitEthernet1
L 172.16.11.7/32 is directly connected, GigabitEthernet1
檢查NAT轉換表,並驗證是否有預期的轉換。由於所需的轉換是動態建立的,因此您必須首先傳送來自相應地址的IP流量。從10.10.50.4發往172.16.11.7的ping命令傳送後,路由器6(NAT路由器)中的轉換表會顯示下一個輸出:
NAT-Router#show ip nat translations
Pro Inside global Inside local Outside local Outside global
--- 172.16.6.14 10.10.10.4 --- ---
--- 172.16.11.70 10.10.50.4 --- ---
Total number of translations: 2
由於預期的轉換位於轉換表中,因此您知道ICMP回應封包已適當地轉換。一個選項是您可以監控NAT統計資訊,但這種方法在複雜的環境中用處不大。另一種方法是在NAT路由器(路由器6)上運行NAT調試。傳送來源為10.10.50.4且目的地為172.16.11.7的ping時,可以執行debug ip nat。調試結果位於下一個代碼示例中:
注意:在路由器上使用任何debug命令時,可能會使路由器過載,使其無法操作。請務必非常小心,如果可能,不要在思科技術支援工程師的監督下在關鍵的生產路由器上運行調試。
NAT-Router#show logging Syslog logging: enabled (0 messages dropped, 0 flushes, 0 overruns) Console logging: level debugging, 39 messages logged Monitor logging: level debugging, 0 messages logged Buffer logging: level debugging, 39 messages logged Trap logging: level informational, 33 message lines logged Log Buffer (4096 bytes): 05:32:23: NAT: s=10.10.50.4->172.16.11.70, d=172.16.11.7 [70] 05:32:23: NAT*: s=172.16.11.7, d=172.16.11.70->10.10.50.4 [70] 05:32:25: NAT*: s=10.10.50.4->172.16.11.70, d=172.16.11.7 [71] 05:32:25: NAT*: s=172.16.11.7, d=172.16.11.70->10.10.50.4 [71] 05:32:27: NAT*: s=10.10.50.4->172.16.11.70, d=172.16.11.7 [72] 05:32:27: NAT*: s=172.16.11.7, d=172.16.11.70->10.10.50.4 [72] 05:32:29: NAT*: s=10.10.50.4->172.16.11.70, d=172.16.11.7 [73] 05:32:29: NAT*: s=172.16.11.7, d=172.16.11.70->10.10.50.4 [73] 05:32:31: NAT*: s=10.10.50.4->172.16.11.70, d=172.16.11.7 [74] 05:32:31: NAT*: s=172.16.11.7, d=172.16.11.70->10.10.50.4 [74]
Router7#show monitor capture cap buffer brief
----------------------------------------------------------------------------
# size timestamp source destination dscp protocol
----------------------------------------------------------------------------
0 114 0.000000 172.16.11.70 -> 172.16.11.7 0 BE ICMP
1 114 2.000000 172.16.11.70 -> 172.16.11.7 0 BE ICMP
2 114 4.000000 172.16.11.70 -> 172.16.11.7 0 BE ICMP
3 114 6.001999 172.16.11.70 -> 172.16.11.7 0 BE ICMP
4 114 8.001999 172.16.11.70 -> 172.16.11.7 0 BE ICMP
從先前的偵錯輸出中您可以看到,第一行顯示已轉換為172.16.11.70的來源位址10.10.50.4。第二行顯示172.16.11.70的目的地址被轉換回10.10.50.4。此模式會在調試的其餘部分中重複。這意味著NAT路由器在兩個方向上轉換資料包。此外,從封包擷取可以看到,路由器7確實收到來源為172.16.11.70、目的地為172.16.11.7的ICMP封包。
後續步驟是對此問題的當前狀態的回顧:
1. Router 4將來源為10.10.50.4的封包傳送到172.16.11.7(或172.16.6.5,取決於執行的測試)。
2. NAT路由器對資料包執行NAT轉換,並將源地址為172.16.11.70、目的地地址為172.16.11.7的資料包轉發。
3.路由器7傳送的響應的來源為172.16.11.7,目的地為172.16.11.70。
4. NAT路由器(路由器6)對資料包執行NAT,從而導致源地址為172.16.11.7、目的地地址為10.10.50.4的資料包。
5. NAT路由器(路由器6)根據其路由表中的資訊將資料包路由到10.10.50.4。
此時,您需要使用show ip route和show ip cef命令來確認NAT路由器(路由器6)的路由表中是否有必要的路由。
NAT-Router#show ip route Codes: L - local, C - connected, S - static, 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, m - OMP n - NAT, Ni - NAT inside, No - NAT outside, Nd - NAT DIA 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 H - NHRP, G - NHRP registered, g - NHRP registration summary o - ODR, P - periodic downloaded static route, l - LISP a - application route + - replicated route, % - next hop override, p - overrides from PfR & - replicated local route overrides by connected Gateway of last resort is not set 10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks C 10.10.10.0/24 is directly connected, GigabitEthernet3 L 10.10.10.6/32 is directly connected, GigabitEthernet3 172.16.0.0/16 is variably subnetted, 6 subnets, 2 masks C 172.16.6.0/24 is directly connected, GigabitEthernet2 L 172.16.6.6/32 is directly connected, GigabitEthernet2 L 172.16.6.14/32 is directly connected, GigabitEthernet2 C 172.16.11.0/24 is directly connected, GigabitEthernet1 L 172.16.11.6/32 is directly connected, GigabitEthernet1 L 172.16.11.70/32 is directly connected, GigabitEthernet1
NAT-Router#show ip route 10.10.50.4 % Subnet not in table NAT-Router#show ip cef 10.10.50.4 0.0.0.0/0 no route NAT-Router#
在NAT路由器中新增缺少的路由後,ping現在成功:
NAT-Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
NAT-Router(config)#ip route 10.10.50.4 255.255.255.255 10.10.10.4
NAT-Router(config)#end
NAT-Router#
Router4#ping 172.16.11.7 source 10.10.50.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.11.7, timeout is 2 seconds:
Packet sent with a source address of 10.10.50.4
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/2 ms
Router4#ping 172.16.6.5 source 10.10.50.4
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.6.5, timeout is 2 seconds:
Packet sent with a source address of 10.10.50.4
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/2/4 ms
Router4#
使用此核對表排除常見問題:
如果您發現轉換表中未安裝相應的轉換,請驗證:
如果在轉換表中安裝了正確的轉換條目,但未使用,請檢查:
解決連線問題:
埠80的NAT轉換不起作用,但其他埠的轉換正常工作。
要解決此問題:
執行與NAT相關的show命令或show running-config或write memory命令時,會出現try later錯誤消息。這是由NAT表大小增加引起的。當NAT表的大小增加時,路由器會耗盡記憶體。
主機可以傳送數百個轉換,這會導致CPU使用率高。換句話說,它可以使表變大,從而導致CPU以100%的速度運行。ip nat translation max-entries 300命令會建立每台主機300個數量限制或路由器上轉換數量的聚合限制。因應措施是使用ip nat translation max-entries all-hosts 300命令。
當您嘗試將兩個內部IP地址配置為一個公用的IP地址(該地址監聽相同的埠)時,將出現此消息。
% X.X.X.X already mapped (172.30.62.101 -> X.X.X.X)
若要更正此問題,請將公用IP地址配置為具有兩個內部IP地址,並在DNS中使用兩個公用IP地址。
這是 no-alias
選項。其 no-alias
選項表示路由器不響應這些地址,也不安裝ARP條目。如果另一台路由器將NAT池用作內部全域性池,該全域性池由連線的子網上的地址組成,則會為該地址生成別名,以便路由器可以響應這些地址的地址解析協定(ARP)請求。這會導致路由器具有虛假地址的ARP條目。
此錯誤消息只是一條資訊性消息,對裝置的正常行為沒有任何影響。
Bad token 0, wanted TOK_NUMBER|TOK_PUNCT
此錯誤表示NAT嘗試對FTP開放中的位址進行第4層修復,但找不到它在封包中轉譯所需的IP位址。 之所以消息中包含令牌,是因為在IP資料包中搜尋令牌或一組符號,可以找到資料包中的IP地址,以便找到轉換所需的詳細資訊。
啟動FTP作業階段時,會交涉兩個通道,一個指令通道和一個資料通道。這兩個地址具有不同的埠號。FTP客戶端和伺服器協商第二個資料通道以傳輸檔案。通過控制通道交換的資料包的格式為「PORT,i,i,i,i,p,p」,其中i,i,i,i是IP地址的四個位元組,p,p指定埠。NAT會嘗試匹配此模式,並在必要時轉換地址/埠。NAT必須轉換兩個通道方案。NAT會掃描命令流中的數字,直到它認為找到了需要轉換的port命令。然後,它會解析轉換,並使用相同的格式計算該轉換。
如果資料包已損壞,或者FTP伺服器或客戶端的命令格式不正確,NAT將無法正確計算轉換,並會生成該錯誤。可以將FTP客戶端設定為被動,使其發起兩個通道。
修訂 | 發佈日期 | 意見 |
---|---|---|
1.0 |
27-Dec-2023 |
初始版本 |