NAT(地址解析协议)
第七部分,也是本次更新的最后一部分,NAT(Network Address Translation),即地址解析协议。通俗理解,地址解析协议就是当一个单位只拥有一个公网ip地址,当内网中的主机想要访问因特网时,可以通过在NAT路由器上将其本地地址转换成全球IP地址的方式实现,从而实现内网中主机都可以访问因特网。
网络拓扑图如下:
在还没有配置nat的情况下,pc0和pc1是不能访问pc2的,因为R0右边接口使用的是202.116.66.1,而下面端口使用192.168.1.1,从pc0发出的icmp可以到达pc2,因为路由表中有到202.116.78.0/24的路由信息,但是从pc2回来的数据包找不到pc0,因为三台路由器上没有到192.168.1.0/24的路由信息,所以需要把192.168.1.2转化成和R0右边接口的地址,就可以实现访问pc2。右边同理,只是变成了多个内网ip对应一个外网ip,随机动态分配。
左边部分使用静态地址转换协议,即一个内网ip只能对应一个公网ip,右边部分使用动态转换协议,即一段内网ip对应一个公网IP。通过配置,使pc0和pc1都能访问pc2.
基础配置
#r0
en conf t int f0/0 ip address 192.168.1.1 255.255.255.0 no shut int s0/0/0 ip address 202.116.66.1 255.255.255.0 no shut exit router ospf 1 network 192.168.1.0 0.0.0.255 area 1 network 202.116.66.0 0.0.0.255 area 1
#r1
en conf t int s0/0/0 ip add 202.116.66.2 255.255.255.0 no shut int s0/0/1 ip add 202.116.64.1 255.255.255.0 no shut int f0/0 ip add 202.116.78.1 255.255.255.0 no shut exit router ospf 1 network 202.116.66.0 0.0.0.255 area 1 network 202.116.64.0 0.0.0.255 area 1 network 202.116.78.0 0.0.0.255 area 1
#r2
en conf t int f0/0 ip address 10.0.1.1 255.255.255.0 no shut int s0/0/0 ip address 202.116.64.2 255.255.255.0 no shut exit router ospf 1 network 10.0.1.0 0.0.0.255 area 1 network 202.116.64.0 0.0.0.255 area 1
静态NAT
#r0
exit ip nat inside source static 192.168.1.2 202.116.67.1 int f0/0 ip nat inside int s0/0/0 ip nat outside #r1 exit ip route 202.116.67.0 255.255.255.0 202.116.66.1
##动态NAT
#r2
exit ip nat pool abin 202.116.65.1 202.116.65.10 netmask 255.255.255.0 access-list 1 permit 10.0.1.2 0.0.0.255 ip nat inside source list 1 pool abin int f0/0 ip nat inside int s0/0/0 ip nat outside
#r1
ip route 202.116.65.0 255.255.255.0 202.116.64.2
结果检测:
使用pc0 ping 通 pc2:
使用pc1 ping 通 pc2: