网络技术中的NAT地址转换技术,一分钟了解下( 二 )


cisco1#ping 192.168.23.3
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
注:当数据包到达cisco2时会将192.168.12.1转化成192.168.34.1,这时cisco3会收到这个数据包,因为目的地址没变 。但cisco3给cisco1回应时,将以192.168.34.1为目的地址,这是在cisco3上没有相关的路由条目 。
cisco3(config)#ip route 192.168.34.0 255.255.255.0 s 1
注:在cisco3上配置去往cisco1上公有地址的路由 。
cisco1#ping
Protocol [ip]:
Target IP address: 192.168.23.3
Repeat count [5]: 50
Sending 50, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
!!!!!!!!!!!!!!! ------------------Ping通说明路由添加正确 。
Terminal-Server#2
[Resuming connection 2 to cisco2 ... ]
01:16:55: NAT*: s=192.168.12.1->192.168.34.1, d=192.168.23.3 [134]
01:16:55: NAT*: s=192.168.23.3, d=192.168.34.1->192.168.12.1 [134]
省略…
cisco2#show ip nat tr
Pro Inside global Inside local Outside local Outside global
--- 192.168.34.1 192.168.12.1 --- ---
4、用192.168.12.2 ping 192.168.23.3
cisco1#ping
Protocol [ip]:
Target IP address: 192.168.23.3
Repeat count [5]: 20
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: y
Source address or interface: 192.168.12.2
Sending 20, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
Packet sent with a source address of 192.168.12.2
!!!!!!!!!!
注:要求使用扩展的命令 。可以选择详细的参数 。比如这里可以使用辅助的ip地址 。使用cisco1接口s0的辅助ip地址来作为源地址 。
Terminal-Server#2
[Resuming connection 2 to cisco2 ... ]
01:35:02: NAT*: s=192.168.12.2->192.168.34.2, d=192.168.23.3 [22]
01:35:02: NAT*: s=192.168.23.3, d=192.168.34.2->192.168.12.2 [22]
省略…
注:源地址192.168.12.2转换成192.168.34.2 。很明显调用了第2个公有地址 。
cisco2#show ip nat tr
Pro Inside global Inside local Outside local Outside global
--- 192.168.34.1 192.168.12.1 --- ---
--- 192.168.34.2 192.168.12.3 --- ---
5、用192.168.12.3 ping 192.168.23.3
cisco1#ping
Protocol [ip]:
Target IP address: 192.168.23.3
Repeat count [5]: 20
Extended commands [n]: y
Source address or interface: 192.168.12.3-------------用第3个私有地址来ping192.168.23.3 。
Sending 20, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
Packet sent with a source address of 192.168.12.3
U.U.U.U.U.--------------结果不能ping通到目的 。
Terminal-Server>2
[Resuming connection 2 to cisco2 ... ]
00:22:02: NAT: translation failed (A), dropping packet s=192.168.12.3 d=192.168.23.3
00:22:02: NAT: translation failed (A), dropping packet s=192.168.12.3 d=192.168.23.3
省略…
注:从调试的信息中可以查找出不能ping通的原因 。是因为地址转换的失败而丢包 。
cisco2#show ip nat tr--通过显示NAT表也可以发现没有192.168.12..3的条目 。
Pro Inside global Inside local Outside local Outside global
--- 192.168.34.1 192.168.12.1 --- ---
--- 192.168.34.2 192.168.12.2 --- ---
解决的方法: 1、清除NAT表中的条目,将公有地址池中的公有地址释放出来 。
2、将NAT超时时间改小,让被转换的目标地址能在短时间内得到释放 。请大家自己研究
cisco2#clear ip nat tr *
cisco2#show ip nat tr
Terminal-Server>1
[Resuming connection 1 to r4 ... ]
cisco1#ping
Protocol [ip]:
Target IP address: 192.168.23.3
Extended commands [n]: y
Source address or interface: 192.168.12.3
Sending 5, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
Packet sent with a source address of 192.168.12.3
!!!!!-------又可以ping通对端 。
Terminal-Server>2
[Resuming connection 2 to cisco2 ... ]
00:46:21: NAT: s=192.168.12.3->192.168.34.2, d=192.168.23.3 [55]
00:46:21: NAT*: s=192.168.23.3, d=192.168.34.2->192.168.12.3 [55]
省略…
注:调试所显示的转换过程 。
cisco2#sh ip nat tr
Pro Inside global Inside local Outside local Outside global
--- 192.168.34.2 192.168.12.3 --- ---
注:NAT表中有了转换的条目 。
6、配置PAT
cisco2(config)#no ip nat pool cisco 192.168.34.1 192.168.34.2 prefix-length 24
cisco2(config)#ip nat pool cisco 192.168.34.1 192.168.34.1 prefix-length 24
cisco2(config)#no ip nat inside source list 1 pool cisco
cisco2(config)#ip nat inside source list 1 pool cisco overload
7、在cisco1用192.168.12.1上ping 192.168.23.3


推荐阅读