此产品的文档集力求使用非歧视性语言。在本文档集中,非歧视性语言是指不隐含针对年龄、残障、性别、种族身份、族群身份、性取向、社会经济地位和交叉性的歧视的语言。由于产品软件的用户界面中使用的硬编码语言、基于 RFP 文档使用的语言或引用的第三方产品使用的语言,文档中可能无法确保完全使用非歧视性语言。 深入了解思科如何使用包容性语言。
思科采用人工翻译与机器翻译相结合的方式将此文档翻译成不同语言,希望全球的用户都能通过各自的语言得到支持性的内容。 请注意:即使是最好的机器翻译,其准确度也不及专业翻译人员的水平。 Cisco Systems, Inc. 对于翻译的准确性不承担任何责任,并建议您总是参考英文原始文档(已提供链接)。
本文档介绍如何排除NAT环境中的IP连接问题。
本文档没有任何特定的要求。
本文档不限于特定的软件和硬件版本。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
有关文件规则的更多信息请参见“ Cisco技术提示规则”。
本文档介绍如何通过查看以下两个示例来排除NAT环境中的IP连接问题:
下面的基本步骤有助于确定NAT操作中是否存在问题:
检验配置,并明确定义NAT应该实现的目标。根据检查,您可以确定配置是否有问题。有关NAT配置的信息,请参阅配置网络地址转换。
检验转换表中是否有正确转换。
使用show和debug命令验证转换是否发生。
详细检查数据包的运行情况,并检验路由器是否具有转发数据包所需的正确路由信息。
在第一种场景中,路由器4可以ping路由器5(172.16.6.5),但不能ping路由器7(172.16.11.7):
NAT拓扑
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是否正常工作。根据之前的配置,可以确定路由器4的IP地址10.10.10.4被静态转换为172.16.6.14。通过在路由器 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.确保在路由器4发出IP流量时进行此转换。您可以通过两种方式从Router 6执行此操作。使用show ip nat statistics命令运行NAT调试或监控NAT统计信息。由于debug命令是最后的手段,因此请从show命令开始。
3.监控计数器,确保它在接收来自路由器4的流量时增加。每次使用转换表转换地址时,计数器都会递增。
4.清除统计信息,然后显示统计信息,然后尝试从路由器4 ping路由器7,然后再次显示统计信息。
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命令看到命中数递增。从Cisco路由器成功执行ping操作后,命中数增加10。转换源路由器(路由器4)发送的互联网控制消息协议(ICMP)响应,并且还需要转换来自目标路由器(路由器7)的响应应答数据包,总命中数为十次。5次命中的丢失是因为回应应答未转换或未从路由器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#
在此问题中,路由器4可以ping路由器5和路由器7,但10.10.50.0网络上的设备无法与路由器5或路由器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#
此问题的网络图保持不变:
NAT拓扑
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
通过路由器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 命令查看路由器 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 命令查看路由器 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命令时,可能会使路由器过载,从而导致路由器无法运行。务必非常小心,如果可能,不要在没有Cisco技术支持工程师监督的情况下在关键的生产路由器上运行调试。
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
从之前的调试输出中您可以看到,第一行显示源地址10.10.50.4已转换为172.16.11.70。第二行显示目的地址172.16.11.70已转换回10.10.50.4。整个 debug 命令执行过程的其余部分会重复这一情况。这意味着NAT路由器会双向转换数据包。此外,从数据包捕获可以看出,路由器7确实接收了源地址为172.16.11.70、目的地址为172.16.11.7的ICMP数据包。
后续步骤是此问题当前状态的总结:
1.路由器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 会话时,它将协商命令信道和数据信道这两条信道。它们是具有不同端口号的两个 IP 地址。FTP客户端和服务器协商第二个数据通道以传输文件。通过控制信道交换的数据包的格式为“PORT,i,i,i,i,p,p”,其中i,i,i,i是IP地址的四个字节,p,p指定端口。NAT会尝试匹配此模式,并在必要时转换地址/端口。NAT必须转换两个通道方案。NAT会扫描命令流中的数字,直到它认为找到了需要转换的端口命令。然后解析转换,以相同格式计算。
如果数据包已损坏,或者FTP服务器或客户端的命令格式不正确,NAT将无法正确计算转换,并生成该错误。可以将FTP客户端设置为被动,使其启动两个通道。
版本 | 发布日期 | 备注 |
---|---|---|
3.0 |
14-Aug-2023 |
更新的替换文本、文章说明、标题、拼写和格式。 |
2.0 |
05-Jul-2022 |
重新认证 |
1.0 |
14-Nov-2001 |
初始版本 |