1.在cisco1、2、3上完成基本的配置,根据拓扑
2.在cisco2上完成NAT的基本配置
3.理解静态NAT,动态NAT和PAT的原理
设备从左到右分别为1-3
1、配置每个设备的名称和接口的ip地址
cisco1(config)#interface serial 0
cisco1(config-if)#ip address 192.168.12.1 255.255.255.0
cisco1(config-if)#ip address 192.168.12.2 255.255.255.0 secondary
注:配置辅助ip地址。
cisco1(config-if)#ip address 192.168.12.3 255.255.255.0 secondary
cisco1(config-if)#no sh
cisco2(config)#interface serial 0
cisco2(config-if)#ip address 192.168.12.254 255.255.255.0
cisco2(config-if)#no shutdown
cisco2(config-if)#clock rate 64000
cisco2(config)#interface serial 1
cisco2(config-if)#ip add 192.168.23.2 255.255.255.0
cisco2(config-if)#no shutdown
cisco2(config-if)#clock rate 64000
cisco2(config-if)#exit
cisco3(config)#interface serial 1
cisco3(config-if)#ip add 192.168.23.3 255.255.255.0
cisco3(config-if)#no shutdown
cisco3(config-if)#exit
2、在cisco2上完成静态NAT的配置。
cisco2(config)#ip nat inside source static 192.168.12.1 192.168.23.4
注:Inside关键字指定内部源本地ip地址转换成内部全局ip地址。当数据由内向外是转换是源地址。回应时转换的是目标地址。静态NAT转换一对一。内部局部地址:在内部网络使用的地址。内部全局地址:用来代替一个或多个本地地址的,对外的,向NIC注册过的地址。
cisco2(config)#interface serial 0
cisco2(config-if)#ip nat inside-----------指定了s0接口在内部。
cisco2(config-if)#int s 1
cisco2(config-if)#ip nat out--------------指定s1接口在外部。
cisco2(config-if)#end
cisco2#debug ip nat
IP NAT debugging is on
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)
注:用本地地址192.168.12.1 Ping 192.168.23.3,结果没有ping通,为什么?
cisco2#show ip nat translations
注:查看cisco2上是否有地址转换的NAT表。
cisco1(config)#ip route 192.168.23.0 255.255.255.0 serial 0
cisco1(config)#end
注:为cisco1上加上去往cisco3的路由。
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:
!!!!!
注:可以ping 通说明加上了路由可以让数据发出去也能回来。
Success rate is 100 percent (5/5), round-trip min/avg/max = 68/74/88 ms
cisco1#ping---------------使用扩展ping。
Protocol [ip]:
Target IP address: 192.168.23.3
Repeat count [5]: 50----------发送50数据包。
Datagram size [100]:
Timeout in seconds [2]:
Extended commands [n]: ----------------这里不使用扩展的命令,直接回车。表示使用主ip地址192.168.12.1来ping192.168.23.3。
Sweep range of sizes [n]:
Type escape sequence to abort.
Sending 50, 100-byte ICMP Echos to 192.168.23.3, timeout is 2 seconds:
!!!!!!!!!!!!!!!!!!!!!
Terminal-Server#2-----------快速切换到cisco2上。来查看具体的转换过程。
[Resuming connection 2 to cisco2 ... ]
00:18:28: NAT*: s=192.168.12.1->192.168.23.4, d=192.168.23.3 [38]
00:18:28: NAT*: s=192.168.23.3, d=192.168.23.4->192.168.12.1 [38] 省略…
注:第一个条目是将源地址进行转化。那第二个条目是将目的地址进行转化。
cisco2#show ip nat translations
Pro Inside global Inside local Outside local Outside global
--- 192.168.23.4 192.168.12.1 --- ---
注:建立了NAT表,当有流量符合这个匹配规则时就会两个地址进行转换。
2、在cisco2上完成动态NAT的配置。
cisco2(config)#no ip nat inside source static 192.168.12.1 192.168.23.4------------将原来的静态NAT的条目删除。
若不能删除请执行命令:clear ip nat tran *
cisco2(config)#access-list 1 permit 192.168.12.0 0.0.0.255
注:通过使用用户访问控制列表来定义本地地址池。
cisco2(config)#ip nat pool cisco 192.168.34.1 192.168.34.2 p 24
注:通过使用用户访问控制列表来定义本地地址池。
cisco2(config)#ip nat inside source list 1 pool cisco
注:定义公有地址池,命名为cisco。地址的范围是192.168.34.1到192.168.34.2,子网掩码用前缀表示24。也可以使用关键字network+具体的网段。
3、用192.168.12.1 ping 192.168.23.3
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
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 100 percent (5/5), round-trip min/avg/max = 68/71/80 ms
Terminal-Server>2
[Resuming connection 2 to cisco2 ... ]
01:01:55: NAT*: s=192.168.12.1->192.168.34.1, d=192.168.23.3 [74]
01:01:55: NAT*: s=192.168.23.3, d=192.168.34.1->192.168.12.1 [74]
省略…
cisco2#sh ip nat tr
Pro Inside global Inside local Outside local Outside global
Icmp 192.168.34.1:6 192.168.12.1:6 192.168.23.3:6 192.168.23.3:6
注:由于发送的ping包,所以显示转换的是icmp协议。随机产生端口号6。
cisco2#
01:02:55: NAT: expiring 192.168.34.1 (192.168.12.1) icmp 6 (6)
注:约1分钟的时间释放地址转换的空间。
cisco2# sh ip nat translations----查找NAT,表中没有任何的转换条目。
cisco2#
8、在cisco1用192.168.12.2上ping 192.168.23.3
cisco1#ping
Protocol [ip]:
Target IP address: 192.168.23.3
Extended commands [n]: y
Source address or interface: 192.168.12.2
Type escape sequence to abort.
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.2
!!!!!
Terminal-Server>2
[Resuming connection 2 to r5 ... ]
01:03:37: NAT: s=192.168.12.2->192.168.34.1, d=192.168.23.3 [75]
01:03:37: NAT*: s=192.168.23.3, d=192.168.34.1->192.168.12.2 [75]
省略…
cisco2#sh ip nat tr
Pro Inside global Inside local Outside local Outside global
icmp 192.168.34.1:7 192.168.12.2:7 192.168.23.3:7 192.168.23.3:7
注:端口号已改为7。
cisco2#
01:04:37: NAT: expiring 192.168.34.1 (192.168.12.2) icmp 7 (7)