色魔王子7 发表于 2017-7-10 06:10:13

NAT理论+LAB

  NAT的作用:
   通过NAT把内部地址翻译成合法的公网IP地址,连接至Internet,节约有限的IPV4公网地址。
  NAT术语:

  实验:

  拓扑描述:
  PC通过路由器模拟终端,IP地址为192.168.1.100。
  内部网络边界处有路由器GW连接内网与外网,内部接口IP地址为192.168.1.1/24;外部接口IP地址为61.177.7.1。
  Server模拟公网的服务器,IP地址为61.177.7.2/24
  基础配置:



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

注:基础配置完成之后,PC要能与网关互通;网关GW能与Server互通;PC不能与Server互通。

  NAT-1:静态NAT。
  在本地地址(内网主机)和全局地址之间做一对一的地址映射;只能实现一个公网地址对应一个私网地址,不能从根本上解决IPV4地址不够用的问题;
  只适用于某些特殊的环境。



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时会出现如下日志:
*Mar1 00:31:23.667: NAT*: s=192.168.1.100->61.177.7.1, d=61.177.7.2
*Mar1 00:31:23.731: NAT*: s=61.177.7.2, d=61.177.7.1->192.168.1.100
说明已经成功将主机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
页: [1]
查看完整版本: NAT理论+LAB