PC: interface FastEthernet0/0
no shutdown
ip address 192.168.1.100 255.255.255.0
!
no ip routing #关闭路由功能。
!
ip default-gateway 192.168.1.1 #配置网关指向出口网关GW。 GW: interface FastEthernet0/0
ip address 61.177.7.1 255.255.255.0
no shutdown
!
interface FastEthernet0/1
ip address 192.168.1.1 255.255.255.0
no shutdown
Server: interface FastEthernet0/1
ip address 61.177.7.2 255.255.255.0
no shutdown
GW:
ip nat inside source static 192.168.1.100 61.177.7.1 #配置静态NAT
!
interface FastEthernet0/0 #接口调用
ip nat outside
!
interface FastEthernet0/1 #接口调用
ip nat inside 验证:
PC处验证如下:
PC#ping 61.177.7.2 #可能访问Server 61.177.7.2。
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 61.177.7.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/30/44 ms
GW处验证:
GW#show ip nat translations #NAT地址转换表
Pro Inside global Inside local Outside local Outside global
--- 61.177.7.1 192.168.1.100 --- ---
!
GW#debug ip nat #开启NAT debug排错功能。
IP NAT debugging is on
在PC去PING 61.177.7.2时会出现如下日志:
*Mar 1 00:31:23.667: NAT*: s=192.168.1.100->61.177.7.1, d=61.177.7.2 [30]
*Mar 1 00:31:23.731: NAT*: s=61.177.7.2, d=61.177.7.1->192.168.1.100 [30]
说明已经成功将主机192.168.1.100转换成61.177.7.1出公网。
注:静态NAT地址转换表无法通过命令直接清除。 NAT-2:动态NAT。
GW:
access-list 1 permit 192.168.1.0 0.0.0.255 #通过标准ACL抓取源私网地址段。
!
ip nat pool cisco 61.177.7.1 61.177.7.5 netmask 255.255.255.0 #地址公网地址池。
!
ip nat inside source list 1 pool cisco #通过匹配ACL列表与公网地址池,实现动态NAT。 验证:
PC处验证:
PC#ping 61.177.7.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 61.177.7.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/30/44 ms
GW处验证:
GW#sh ip nat translations
GW#sh ip nat translations
Pro Inside global Inside local Outside local Outside global
--- 61.177.7.1 192.168.1.100 --- ---
--- 61.177.7.2 192.168.1.101 --- ---
--- 61.177.7.3 192.168.1.102 --- ---
--- 61.177.7.4 192.168.1.103 --- ---
--- 61.177.7.5 192.168.1.104 --- ---
当PC地址为192.168.1.105时,结果如下:
PC(config-if)#ip address 192.168.1.105 255.255.255.0 #由于公网地址被分配完,导致192.168.1.105这台主机无法访问Server。
PC(config-if)#do ping 61.177.7.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 61.177.7.2, timeout is 2 seconds:
U.U.U
Success rate is 0 percent (0/5)
清NAT地址表:
GW#clear ip nat translation *
!
GW#sh ip nat translations
为空
GW# NAT-3:PAT
GW:
ip nat inside source list 1 interface fastEthernet 0/0 overload 验证:
PC处验证:
PC#ping 61.177.7.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 61.177.7.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 16/30/44 ms
GW处验证:
GW#sh ip nat translations
Pro Inside global Inside local Outside local Outside global
icmp 61.177.7.1:13 192.168.1.105:13 61.177.7.2:13 61.177.7.2:13