当前位置: 代码网 > 服务器>网站运营>网站优化 > NAT端口映射,实现外网访问内网服务器

NAT端口映射,实现外网访问内网服务器

2024年08月03日 网站优化 我要评论
本篇文章利用Cisco Packet Tracer网络模拟进行NAT端口映射,实现外网访问内网服务器。

前言

本篇文章利用cisco packet tracer网络模拟进行nat端口映射,实现外网访问内网服务器。

一、搭建网络拓扑

在这里插入图片描述

网络拓扑图

1.1 配置server和pc

机器名ip地址网关ip子网掩码
server0192.168.1.2192.168.1.1255.255.255.0
server1192.168.1.3192.168.1.1255.255.255.0
pc0114.25.63.24114.25.63.1255.255.255.0

1.1.1 配置server0

在这里插入图片描述

1.1.2 配置server1

在这里插入图片描述

1.1.3 配置pc0

在这里插入图片描述

1.2 配置客户路由器

1.2.1 配置路由器ip

接口名称ip地址子网掩码
fa0/0192.168.1.1255.255.255.0
fa0/166.1.1.1255.255.255.0

配置信息如下:

1. 配置fa0/0接口
router>enable
router#
router#configure
router(config)#
router(config)#interface fa0/0
router(config-if)#ip address 192.168.1.1 255.255.255.0
router(config-if)#no shutdown
router(config-if)#exit
router(config)#

2. 配置fa0/1接口
router(config)#interface fa0/1
router(config-if)#ip address 66.1.1.1 255.255.255.0
router(config-if)#no shutdown

1.2.2 配置静态路由

为客户路由器配置默认路由,让客户路由器可以达到114.25.63.0/24网络。

命令:ip route 目标网段 目标网段掩码 下一跳路由的ip
这里设置默认路由
下一跳路由ip的意思是通过其可以到达目标网段
router(config)#ip route 0.0.0.0 0.0.0.0 66.1.1.254

或者可以设置静态路由
router(config)#ip route 114.25.63.0 255.255.255.0 66.1.1.254

以上两种配置的其中一种,均可以到达114.25.63.0/24网络

1.3 配置isp路由器

接口名称ip地址子网掩码
fa0/066.1.1.254255.255.255.0
fa0/1114.25.63.1255.255.255.0

配置信息如下:

1. 配置fa0/0接口
router>enable
router#
router#configure
router(config)#
router(config)#interface fa0/0
router(config-if)#ip address 66.1.1.254 255.255.255.0
router(config-if)#no shutdown
router(config-if)#exit
router(config)#

2. 配置fa0/1接口
router(config)#interface fa0/1
router(config-if)#ip address 114.25.63.1 255.255.255.0
router(config-if)#no shutdown

以上配置完成后,测试各个主机的连通性,这里不再介绍。

二、配置端口映射

2.1 在客户路由器配置端口映射

由于这里使用http服务,则应该对应两个服务器的80端口进行映射

端口映射表
私网ip私网机器端口公网ip公网机器端口
192.168.1.28066.1.1.26666
192.168.1.38066.1.1.28888

配置信息如下:

router>enable
router#
router#configure
router(config)#
1. 配置接口fa0/0为内网口
router(config)#interface fa0/0
router(config-if)#ip nat inside
router(config-if)#exit
router(config)#
2. 配置接口fa0/1为外网口
router(config)#interface fa0/1
router(config-if)#ip nat outside
router(config-if)#exit
router(config)#

3. 私网ip 端口->公网ip 端口
命令:ip nat inside source static 协议(udp或tcp) 私网ip 端口 公网ip 端口
router(config)#ip nat inside source static tcp 192.168.1.2 80 66.1.1.2 6666
router(config)#ip nat inside source static tcp 192.168.1.3 80 66.1.1.2 8888

2.2 测试公网计算机访问私网服务器

2.2.1 pc0向server0发送http请求

如果映射成功,则可以通过66.1.1.2:6666访问server0(192.168.1.2)

在这里插入图片描述
这里,可以去修改server0的index.html的内容

在这里插入图片描述

2.2.1 pc0向server1发送http请求

如果映射成功,则可以通过66.1.1.2:8888访问server1(192.168.1.3)

在这里插入图片描述

总结

nat还有一种静态配置,即一个公网ip映射一个私网ip。
nat端口映射可以实现一个公网ip映射多个私网ip,只需要控制端口号的选择。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com