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:

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

abin在路上

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值