2024年6月13日发(作者:)

实验利用NAT实现外网主机访问内网服务器

【实验名称】

利用NAT实现外网主机访问内网服务器

【实验目的】

掌握NAT源地址转换和目的地址转换的区别,掌握如何向外网发布内网的服务器

【背景描述】

你是某公司的网络管理员,公司只向ISP申请了一个公网IP地址,现公司的网站在内网,

要求在互联网也可以访问公司网站,请你实现。172.16.8.5是web服务器的IP地址。

【需求分析】

内网服务器能够转换成外网公网IP,被互联网访问

外网主机

【实验拓扑】

63.19.6.5

F1/1:172.16.8.1

F1/0

200.1.8.7

F1/0

200.1.8.8

F1/1: 63.19.6.1

WEB服务器

172.16.8.5

图11-2 实验拓扑图

【预备知识】

路由器基本配置知识、NAT知识

【实验设备】

路由器(带串口) 两台

V.35线缆(DTE/DCE) 1对

PC 1台

直连线 1条

【实验原理】

NAT(网络地址转换或网络地址翻译),是指将网络地址从一个地址空间转换为另一个

地址空间的行为。

NAT将网络划分为内部网络(inside)和外部网络(outside)两部分。局域网主机利用

NAT访问网络时,是将局域网内部的本地地址转换为了全局地址(互联网合法IP地址)后转

发数据包。

NAT分为两种类型:NAT(网络地址转换)和NAPT(网络地址端口转换)。NAT是实

现转换后一个本地IP地址对应一个全局地址。NAPT是实现转换后多个本地IP地址对应一个

全局IP地址。目前网络中由于公网IP地址紧缺,而局域网主机数较多,因此一般使用动态的

NAPT实现局域网多台主机共用一个或少数几个公网IP访问互联网。

【实验步骤】

第一步:路由器基本配置

R1(config)#

R1 (config)#interface FastEthernet 1/1

R1 (config-if)#ip address 172.16.8.1 255.255.255.0

R1 (config-if)#no shutdown

R1 (config-if)#exit

R1 (config)#interface interface FastEthernet 1/0

R1 (config-if)#ip address 200.1.8.7 255.255.255.0

R1 (config-if)#no shutdown

R1 (config-if)#exit

R2 (config)#interface fastEthernet 1/1

R2 (config-if)#ip address 63.19.6.1 255.255.255.0

R2 (config-if)#no shutdown

R2 (config-if)#exit

R2 (config)#interface interface FastEthernet 1/0

R2 (config-if)#ip address 200.1.8.8 255.255.255.0

R2 (config-if)#no sh

R2 (config-if)#end

第二步:配置默认路由

R1(config)#ip route 0.0.0.0 0.0.0.0 200.1.8.8

第三步:配置NAT

R1(config)#interface fastEthernet 1/1

R1(config-if)#ip nat inside

R1(config-if)#exit

R1(config)#interface fastEthernet 1/0

R1(config-if)#ip nat outside

R1(config-if)#exit

R1(config)# ip nat inside source static tcp 172.16.8.5 80 200.1.8.5 80

第四步:验证测试

1、在内网主机配置WEB服务

2、在外网的1台主机通过浏览器访问内网web服务器映射的公网地址200.1.8.5

R1#show ip nat translations

Pro Inside global Inside local Outside local Outside global

tcp 200.1.8.5:80 172.16.8.5:80 63.19.6.1:1033 63.19.6.1:1033

R1#show ip nat statistics

Total translations: 1, max entries permitted: 30000

Peak translations: 2 @ 00:11:25 ago

Outside interfaces: FastEthernet 0/0

Inside interfaces: FastEthernet 0/1

Rule statistics:

[ID: 5] inside source static

hit: 2

match (before routing):

tcp packet with destination-ip 200.1.8.5 destination-port 23

action :

translate ip packet's destination-ip use ip 172.16.8.5 with port set to 23

【注意事项】

1、不要把inside和outside应用的接口弄错

2、配置目标地址转换后,需要利用静态NAPT配置静态的端口地址转换



【参考配置】

R1#sh running-config

Current configuration : 919 bytes

!

version RGNOS 10.1.00(4), Release(18443)(Tue Jul 17 20:50:30 CST 2007

-ubu1server)

hostname R1

!

ip access-list standard 3

10 permit host 200.1.8.5

!

interface FastEthernet 1/0

ip nat outside

ip address 200.1.8.7 255.255.255.0

duplex auto

speed auto

!

interface FastEthernet 1/1

ip nat inside

ip address 172.16.8.1 255.255.255.0

duplex auto

speed auto

!

ip nat inside source static tcp 172.16.8.5 80 200.1.8.5 80

!

ip route 0.0.0.0 0.0.0.0 200.1.8.8

!

line con 0

line aux 0

line vty 0 4

login

!

end

R2#sh running-config

Current configuration : 550 bytes

!

version RGNOS 10.1.00(4), Release(18443)(Tue Jul 17 20:50:30 CST 2007

-ubu1server)

hostname R2

!

enable password 7 151b5f72

!

!

interface FastEthernet 1/0

ip address 200.1.8.8 255.255.255.0

duplex auto

speed auto

!

interface FastEthernet 1/1

ip address 63.19.6.1 255.255.255.0

duplex auto

speed auto

!

i

line con 0

line aux 0

line vty 0 4

login

password 7 0549546d

!

end