113人参与 • 2024-08-03 • 网站优化
本篇文章利用cisco packet tracer网络模拟进行nat端口映射,实现外网访问内网服务器。
机器名 | ip地址 | 网关ip | 子网掩码 |
---|---|---|---|
server0 | 192.168.1.2 | 192.168.1.1 | 255.255.255.0 |
server1 | 192.168.1.3 | 192.168.1.1 | 255.255.255.0 |
pc0 | 114.25.63.24 | 114.25.63.1 | 255.255.255.0 |
接口名称 | ip地址 | 子网掩码 |
---|---|---|
fa0/0 | 192.168.1.1 | 255.255.255.0 |
fa0/1 | 66.1.1.1 | 255.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
为客户路由器配置默认路由,让客户路由器可以达到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网络
接口名称 | ip地址 | 子网掩码 |
---|---|---|
fa0/0 | 66.1.1.254 | 255.255.255.0 |
fa0/1 | 114.25.63.1 | 255.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
以上配置完成后,测试各个主机的连通性,这里不再介绍。
由于这里使用http服务,则应该对应两个服务器的80端口进行映射
端口映射表 | |||
---|---|---|---|
私网ip | 私网机器端口 | 公网ip | 公网机器端口 |
192.168.1.2 | 80 | 66.1.1.2 | 6666 |
192.168.1.3 | 80 | 66.1.1.2 | 8888 |
配置信息如下:
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
如果映射成功,则可以通过66.1.1.2:6666访问server0(192.168.1.2)
这里,可以去修改server0的index.html的内容
如果映射成功,则可以通过66.1.1.2:8888访问server1(192.168.1.3)
nat还有一种静态配置,即一个公网ip映射一个私网ip。
nat端口映射可以实现一个公网ip映射多个私网ip,只需要控制端口号的选择。
您想发表意见!!点此发布评论
版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。
发表评论