内网访问NAT后的服务器问题.docx

上传人:小飞机 文档编号:5040451 上传时间:2023-05-31 格式:DOCX 页数:17 大小:123.47KB
返回 下载 相关 举报
内网访问NAT后的服务器问题.docx_第1页
第1页 / 共17页
内网访问NAT后的服务器问题.docx_第2页
第2页 / 共17页
内网访问NAT后的服务器问题.docx_第3页
第3页 / 共17页
内网访问NAT后的服务器问题.docx_第4页
第4页 / 共17页
内网访问NAT后的服务器问题.docx_第5页
第5页 / 共17页
亲,该文档总共17页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《内网访问NAT后的服务器问题.docx》由会员分享,可在线阅读,更多相关《内网访问NAT后的服务器问题.docx(17页珍藏版)》请在三一办公上搜索。

1、总是有人询问关于NAT后的设备访问问题,针对cisco设备现解决如下:如图所示,该企业申请ADSL上网,只获得了一个公有合法IP地址。企业有一个WEB服务器提供访问,可以使用端口地址重定向功能来完成。Router(config)#int e0(1)Router(config-if)#ip add 10.1.1.254 255.255.255.0Router(config-if)#ip nat insideRouter(config)#int e1Router(config-if)#ip add 202.1.1.1 255.255.255.252Router(config-if)#ip nat

2、outsideRouter(config)#ip nat inside source static tcp 10.1.1.1 80 202.1.1.1 80(2)Router(config)#access-list 1 permit 10.1.1.0 0.0.0.255(4)Router(config)#ip nat inside source list 1 interface e1 overload(5)Router(config)#ip route 0.0.0.0 0.0.0.0 202.1.1.2(6)命令解释:(1):配置路由器接口 IP地址及标记NAT的内部端口和外部端口(2):当外

3、部用户访问服务器202.1.1.1:80,路由器使用静态NAT的方式转到10.1.1.1:80(4):配置标准访问控制列表,匹配内部10.1.1.0/24网络的主机(5):配置PAT,允许内部10.1.1.0/24用户能够进行NAT转换(6):配置静态路由,使经过NAT转换后的数据包能够发送至ISP经过这些配置后,企业内部网络用户能够正常访问外部资源,外部Internet用户能够浏览该 企业的网站(假设网站地址为)。这时候,我们会发现企业内部网络用户无法 使用来访问内部网站。现解决该问题办法如下:Router(config)#ip dns server(1)Router(config)#ip

4、domain-lookup(2)Router(config)#ip name-server 202.96.64.68(3)Router(config)#ip host 10.1.1.1(4)内部网络主机的DNS配置成10.1.1.254 命令解释:(1):启用路由器DNS服务功能(2) :启用DNS的外部查询功能,一般来说,该功能路由器缺省启用(3) :指定所查找的上级DNS服务器地址(根据本地情况确定)(4) :手工配置DNS本地条目搞定。注意:如果路由器负担较重,请另外建立一个内部DNS服务器。另外,如果企业规模不是很大,还可以让路由器担当DHCP服务器功能。新增配置如下:Router(c

5、onfig)#server dhcpRouter(config)#ip dhcp excluded-address 10.1.1.254Router(config)#ip dhcp excluded-address 10.1.1.1Router(config)#ip dhcp pool ABCRouter(dhcp-config)#network 10.1.1.0 /24Router(dhcp-config)#dns-server 10.1.1.254Router(dhcp-config)#default-router 10.1.1.254久前写的,最近看到又有讨论DNAT的,做个参考。看到论

6、坛内很多弟兄做了 DNAT,外网正常访问,内网却无法访问.现将原因总结如下: 设网络结构如下:外网某机器为W1,路由器为R1,内网服务器为S1,内网某机器为C1,设服务为80 地址分布如下:R1:外(eth0): 192.168.0.5 内(eth1): 192.168.1.254S1: 192.168.1.5C1:192.168.1.8原因如下:外网为什么能成功:当W1以某IP端口 80访问R1的外网地址192.168.0.5时,数据包到达192.168.0.5的接口 eth0,ROS根据DNAT规则做了到S1 192.168.1.5的转发,S1 192.168.1.5收到来自某IP的 包后

7、S1会发出正确的相应,此响应的目的IP为W1的IP,根据默认网关(R1的eth1) 192.168.1.254规则把回应包发到R1,因为R1先前DNAT的关系(有DNAT的记录),R1 回做一个反方向的NAT转发,从而数据包能够正确的到达W1,因此能够正确通信。内网为什么不能成功:1、DNAT规则是针对eth0 口配置的:设 R1 的 DNAT 规则:iptables -1 nat - A PREROUTING - i eth0 -p tcp -m tcp -d 192.168.0.5 - dport 80 - j DNAT - -to-destinstion 192.168.1.5当C1以1

8、92.168.0.5为目的IP访问80服务的时候,数据包从192.168.1.254 口传入,R1根 据路由规则,会把目的192.168.0.5的地址直接送到上层接口,而不会经过R1为eth0接口 配置的DNAT规则,那么此时192.168.0.5开了 80服务了吗?很显然没有,因此无法访问。2、DNAT的规则是全局的:设 R1 的 DNAT 规则:iptables -t nat -A PREROUTING -p tcp -m tcp -d 192.168.0.5 -dport 80 -j DNAT -to-destinstion 192.168.1.5当C1以192.168.0.5为目的IP

9、访问80服务的时候,数据包从192.168.1.254 口传入,R1根 据DNAT规则会把此数据包DNAT到正确的S1服务器192.168.1.5,当S1收到包的时候S1 会根据自己的路由表不经过R1的转发而会直接把数据发到C1,因为C1和S1是在同一个 网络,这时候C1回收到S1的回应,按说此时应该能正常通信。但不幸的是我们忽略了源 IP的问题。C1是把数据包发给的是R1的外网IP 192.168.0.5,而收到的IP的源地址却是S1 的IP192.168.1.5,虽然数据包的除IP外所有的都是正确的,但C1仍然不会接受,会把这个 包丢弃的。因此通信还是无法进行。解决办法:1、从DNS入手,

10、在内网设置自己的DNS,或者编辑client的hosts表把S1的地 址不要解析成外网的IP,这样就变成内网的通信,还不占用ROS的带宽。这是我首推的方 法。2、如果一定要走ROS,首先你要为每个可能进入的接口配置相应的DNAT策略, 当然使用我上面举例的全局策略就完全可以的,那么我们下面应该如何设置呢?又有两种情 况:1)如果可以把服务器放到一个单独的网段请你及时这样做。因为这样可以避免攻 击,便于控制等等好处N多了。麻烦就是需要ROS多加一个网卡当然如果你配置多地址的 话,网卡都可以省了,不过这么省不太好吧。当然还需要配置正确的SNAT。2)有些人说我就不能放到单独的网段,那我也有办法,这

11、是我最不赞成的方法, 就是请你删掉S1上到192.168.1.0网络的路由表项目,这样会强制S1到C1的数据包走R1, 这样R1就可以实施相反的转换,当然也就可以正常通信了。 route del net 192.168.1.0 netmask 255.255.255.0 gw * dev ethl以上是我对所谓的回流问题的个人见解。你看后有3种情况:1、写的不好没法看,或我都知道了不用看,请别拿石头丢我,我很脆弱。不过有 错误尽管提,我很虚心。2、和你想的差不多,那恭喜你,我先写出来了。3、看不懂。没法子,我语文很差,逻辑很差,英文很差。你将就将就吧。NAT后无法在内网通过外部IP访问内部服务

12、的问题的详细说明(原创)减小字体增大字体作者:佚名来源:不详发布时间:2005-12-9 12:16:47最近,到处看到有人问这个问题,怎么以前没人问,现在这么多人问呢?前两天我还在华为 的论坛上仔细的说了这个问题,现在复制到这边来。希望能帮助大家理解这个问题。这是个理论问题,我们先从NAT讲起:NAT有两种基本类型,一种是SNAT(Source NAT),一种是DNAT(Dest. NAT).SNAT即源NAT是改变数据包的IP层中的源IP地址,一 般是用来将不合法的IP外出请求转换成合法的IP的外出请求,就是普通的用一个或者几个 合法IP来带动一整个非法IP段接入。DNAT即目的NAT,就

13、是改变数据包的目标IP地址, 使得能对数据包重新定向,可以用做负载均衡或者用于将外部的服务请求重定向到内网的非 法IP的服务器上。好了,罗嗦了一通,大致就是这样了。那么之所以会出现无法在DNAT的内部网络 通过DNAT服务的外部IP地址来访问的情况,是因为,如果服务从内部请求,那么经过DNAT 转换后,将目标IP改写成内网的IP地址,譬如172.16.10.254,而请求的机器的IP是 172.16.10.100,数据包被网关172.16.10.1顺利的重定向到172.16.10.254的服务端口,然后, 192.16.10.254根据请求发送回应给目的IP地址,就是172.16.10.100

14、,但是,问题出现了,因 为172.16.10.100请求的地址是外部IP假设是221.232.34.56,所以他等待着221.232.34.56的 回应,而172.16.10.254的回应请求被看做是非法的,被丢弃了。这就是问题的所在了。呵呵,写的有点混乱,不好意思。不知道大家明白没有.那么如何解决这个问题,我 说个用iptables实现的例子,#我们先把发向外网IP221.232.34.56 80号端口的数据重定向到172.16.10.254理论上来 讲,如果只要从外网访问,这就完成了。iptables -t nat -A PREROUTING -p tcp -d 221.232.34.56

15、 -dport 80 -j DNAT -to-destination 172.16.10.254#解决内网通过外网IP访问的情况iptables -t nat -A POSTROUTING -p tcp -d 172.16.10.254 -dport 80 -j SNAT -to-source 172.16.10.1我们将内网的请求强行送回到网关172.16.10.1,依靠网关在内核建立的状态表再转发到 真实的请求地址172.16.10.100.当然,这并不是最好的解决方法,最好的解决方法是将服务器放在另外一个网段,也就 是说所谓的DMZ (解除武装区),这样就不会出现上面所说的问题了。如果大

16、家还不清楚,给个参考文档:http:/iptables-就先说到这里了,我要去上班了。fushuyong 回复于:2004-07-24 13:33:53居然一个人都没回复的,难道这个问题不具备普遍性?我爱臭豆腐回复于:2004-07-26 08:08:08goodjlwhc 回复于:2004-07-26 08:54:02这个DNAT(又叫端口映射),这个问题网上的问法基本就是“为什么内网不可以访问自己网 关上的端口映射,即外面正常转入数据了。为什么内部不给反向转回?”实际上用iptables -t nat -A PREROUTING -p tcp -d wan_ip -dport 80 -j

17、DNAT -to lan_ip:80就可以很好解决了如果基于网络设备,比如ethx,的DNAT就存在上面的问题了至于 freebsd 的 ipfilter, ipfwopenbsd的packet filter,都存在这个问题,不过都可以通过重定向来源数据到本地回环然后 解决hcjia 回复于:2004-07-26 09:47:59如果防火墙PIX没有DMZ (两个端口),如何解决这个问题呢?njdaboy_cn 回复于:2004-07-26 11:12:32 好贴!skylove 回复于:2004-07-26 13:07:34把服务器裸到外网上。不过防火墙上该走桥方式的嘛。古回复于:2004-

18、07-26 16:50:56防火墙不一定就支持混合模式哦。onebuyone 回复于:2004-07-27 14:29:24以前这样的问题比较多见。现在感觉好久没有遇到这样的问题了。现在大多数的防火墙都能 够实现这样的访问。具体各个厂家的解决方法可能不同。Check Point防火墙是把请求访问 的数据包的源地址更改为防火墙的外部公有的IP地址,这样内部的服务器返回的数据包会 先传到防火墙外部的公有IP地址后再传递到内部的请求计算机。至于其他防火墙是不是这 样就没有留意。小蟹 回复于:2004-07-27 16:11:31有防火墙的话做一个端口映射就什么都解决了fushuyong 回复于:20

19、04-07-29 23:22:34呵呵,其实这个问题很具备现实意义,因为有很多厂商的路由器和防火墙在设计的时候并没 有考虑到有这种引用,当然,一般的建议是将服务器放在DMZ区,这样就不会出现问题了。子小水兽回复于:2004-07-30 19:48:26 在cisco的路由器中怎么做dnat?likuku 回复于:2004-08-03 19:09:20艾。早有人有专文论述和解决这个问题了。OS 是 FreeBSD 防火墙是 ipfilter, NAT 部分是 ipfilter 的 ipnat.是cnfug的第12期文章,非常详细,结合网络嗅探器进行TCP/IP理论分析,还有解决方法:基于IP F

20、ilter的NAT透析一一曾慧鹏fug.org/journal/12/02.htmlRyker 回复于:2004-08-10 15:16:17太经典啦,我这就有这个问题回去搞定wangrujun 回复于:2004-08-14 08:57:22在防火墙上解决这个问题未免太笨。应该用dns来解决这个问题。干干净净,清清爽爽,对 带宽又没有任何影响。关键问题是,楼主说的我看不懂,但是我知道以前当我们用NE05的时候,曾经是好使的, 就是说内网用户通过公网的IP或者域名来访问与自己在同一内网的某台服务器时(在NE05 上为改服务器做的静态IP映射),是好使的,后来华为的人为我们的NE05进行软件版本升

21、 级后,反而不好用了,我在华为论坛看到这个问题了,大概有个帖子就是楼主发的吧。另外我以前用过CISCODE路由器,也曾经好使过。yzz_jn 回复于:2004-08-16 21:29:31quote:b57e424592=fushuyong”居然一个人都没回复的,难道这个问题不具备普遍性?/quote:b57e424592好:em02:level 回复于:2004-08-20 21:22:01:)paulwang 回复于:2004-08-23 11:21:20有必要怎么复杂吗,建个内部DNS不就可以解决这样的问题吗?随便说说,没仔细看你 的帖wingger 回复于:2004-08-23 13:

22、37:26有碰到过。不过用DNS 了不过有时调试的时候还要要用到的,不错:lol:dugong 回复于:2004-08-25 11:04:35看了各位的帖子,感觉小弟的情况类似这样,可是我已经使用DMZ 了,却也不好用,以前 发过帖子,可没人回答大家帮忙再看看,谢谢了。PIX防火墙中的WEB,外网可以访问,内网的反而不行,奇怪了。小弟搞了好长时间,头都晕了,大家帮忙看看配置,谢谢。网络情况是以下拓扑图所标示的,从外界访问网站没问题,内部机器上Internet也没问题, 就是内部机器访问网站不行,直接输入服务器IP地址也不行,真是奇了怪了。以下是PIX的配置,路由器没有作特别设置,只是作为联出去

23、的设备,除了 IP设置外,就 是静态路由 ip route 0.0.0.0 0.0.0.0 10.255.64.125。nameif ethernet0 outside security0 nameif ethernetl inside security100 nameif ethernet2 DMZ security10 hostname Firewalldomain-name Pfixup protocol ftp 21fixup protocol http 80fixup protocol h323 1720fixup protocol rsh 514fixup protocol rts

24、p 554fixup protocol smtp 25fixup protocol sqlnet 1521fixup protocol sip 5060no fixup protocol skinny 2000no namesname 192.168.0.6 insidename 192.168.1.1 DMZname 221.13.19.114 outsideaccess-list 101 permit icmp any anyaccess-list 101 permit ip any anypager lines 24interface ethernet0 autointerface et

25、hernet1 autointerface ethernet2 autoicmp permit any outsideicmp permit any insidemtu outside 1500mtu inside 1500mtu DMZ 1500ip address outside 221.13.19.114 255.255.255.240ip address inside 192.168.0.6 255.255.255.0ip address DMZ 192.168.1.1 255.255.255.0ip audit info action alarmip audit attack act

26、ion alarmpdm location 192.168.0.1 255.255.255.255 insidepdm location 192.168.1.2 255.255.255.255 DMZpdm location 192.168.0.6 255.255.255.255 insidepdm location 221.13.19.114 255.255.255.255 outsidepdm history enablearp timeout 14400global (outside) 1 221.13.19.119-221.13.19.126 netmask 255.255.255.2

27、40global (outside) 1 221.13.19.117 netmask 255.255.255.240global (DMZ) 1 192.168.1.4-192.168.1.24 netmask 255.255.255.0 nat (inside) 1 192.168.0.0 255.255.255.0 0 0nat (DMZ) 1 192.168.1.0 255.255.255.0 0 0static (DMZ,outside) 221.13.19.118 192.168.1.2 netmask 255.255.255.255 0 0access-group 101 in i

28、nterface DMZconduit permit tcp host 221.13.19.118 eq www anyconduit permit icmp host 221.13.19.118 anyconduit permit tcp host 221.13.19.118 eq pop3 anyconduit permit tcp host 221.13.19.118 eq smtp anyconduit permit tcp host 221.13.19.118 eq ftp anyconduit permit tcp host 221.13.19.118 eq 2005 anycon

29、duit permit tcp host 221.13.19.118 eq 3000 anyconduit permit tcp host 221.13.19.118 eq 3389 anyconduit permit icmp 221.13.19.112 255.255.255.240 anyconduit permit tcp 192.168.0.0 255.255.255.0 range 6891 6900 anyconduit permit udp 192.168.0.0 255.255.255.0 range 5004 65535 anyroute outside 0.0.0.0 0

30、.0.0.0 221.13.19.113 1timeout xlate 3:00:00timeout conn 1:00:00 half-closed 0:10:00 udp 0:02:00 rpc 0:10:00 h323 0:05:00 sip 0:30:00 sip_media 0:02:00timeout uauth 0:05:00 absoluteaaa-server TACACS+ protocol tacacs+aaa-server RADIUS protocol radiushttp server enablehttp 192.168.0.1 255.255.255.255 i

31、nsidehttp 192.168.0.0 255.255.255.0 insideno snmp-server locationno snmp-server contactsnmp-server community publicno snmp-server enable trapsfloodguard enableno sysopt route dnattelnet 10.220.52.16 255.255.255.240 outsidetelnet 10.0.0.0 255.0.0.0 outsidetelnet 192.168.0.0 255.255.255.0 insidetelnet

32、 10.220.52.17 255.255.255.255 insidetelnet 192.168.1.0 255.255.255.0 insidetelnet 10.220.52.17 255.255.255.255 DMZtelnet timeout 5ssh timeout 5terminal width 80小弟已经看了若干遍了,很多可能性都考虑到了,还是不行,哪位老大辛苦看看配置,哪里 有问题?谢谢了。thy_email 回复于:2004-09-30 13:12:14静态nat ,动态nat,源nat,目的natglobalnatstatic=conduct没搞清楚什么关系??快乐

33、玩家 回复于:2004-12-09 17:03:59楼上几位,我用FreeBSD下,也有类似问题内网用户可以访问内网WEB服务器的外网IP,但不能访问同一台服务器的FTP。外网用户却可以访问这台FTP这是怎么回事呀?盼请各位高人指导啊qiuqiu_wang 回复于:2005-01-19 23:16:04 好文章,可看不太明白,我看得头都大了.东方补白回复于:2005-01-20 09:41:52,fengyu2002 回复于:2005-04-19 17:30:44ip nat outside destination static global-ip local-iphunterdong 回复于

34、:2005-05-11 09:41:20我看了,好象你是缺access-group的定义只有 access-group 101 in interface dmz应该把 101 给 inside, 100 给 outsidedmz 似乎不需要 access-groupUnderstanding the alias Command for the Cisco Secure PIX FirewallThe alias command has two possible functions:It can be used to do DNS Doctoring of DNS replies from an

35、 external DNS server.In DNS Doctoring, the PIX changes the DNS response from a DNS server to be a different IP address than the DNS server actually answered for a given name.This process is used when we want the actual application call from the internal client to connect to an internal server by its

36、 internal IP address.It can be used to do Destination NAT (dnat) of one destination IP address to another IP address.In dnat, the PIX changes the destination IP of an application call from one IP address to another IP address.This process is used when we want the actual application call from the int

37、ernal client to the server in a perimeter (dmz) network by its external IP address. This does not doctor the DNS replies.For example, if a host sends a packet to 99.99.99.99, you can use the alias command to redirect traffic to another address, such as 10.10.10.10. You can also use this command to p

38、revent conflicts when you have IP addresses on a network that are the same as those on the Internet or another intranet.For more information, consult the PIX documentation.Hardware and Software VersionsThe information in this document is based on the software and hardware versions below.Cisco Secure

39、 PIX Firewall Software Releases 5.0.x and laterTranslating an Internal Address with DNS DoctoringIn the first example, the web server has an IP address of 10.10.10.10, and the global IP address of this web server is 99.99.99.99.Note: The DNS server is on the outside. Verify that the DNS server resol

40、ves your domain name to the global IP address of the web server by issuing an nslookup command. The result of the nslookup on the client PC should be the internal IP address of the server (10.10.10.10), because the DNS reply gets doctored as it passes through the PIX.Also note that, for DNS fixup to

41、 work properly, proxy-arp has to be disabled. If you are using the alias command for DNS fixup, disable proxy-arp with the following command after the alias command has been executed.sysopt noproxyarp internal_interfaceNetwork DiagramWeb server10.10.10.10If we want the machine with the IP address 10

42、.10.10.25 to access this web server by its domain name (), we need to implement the alias command as follows:alias (inside) 10.10.10.10 99.99.99.99 255.255.255.255!This command sets up DNS Doctoring. It is initiated from the clientsin! the inside network. It watches for DNS replies that contain! 99.

43、99.99.99, then replaces the 99.99.99.99 address with the10.10.10.10! address in the DNS reply sent to the client PC.Next, a static translation must be created for the web server, and we need to give anyone on the Internet access to the web server on port 80 (http):static(inside,outside) 99.99.99.99

44、10.10.10.10 netmask 255.255.255.255 ! This command creates a static translation between the web servers!real address 10.10.10.10 to the global IP address 99.99.99.99.To grant permission for access, you should use access list commands, as shown below.access-list 101 permit tcp any host 99.99.99.99 eq

45、 www access-group 101 in interface outside!- These commands permit any outside user to access the web server on port 80.If you prefer the older syntax, you can use a conduit command as follows.conduit permit tcp host 99.99.99.99 eq www any!- This command permits any outside user to access the web se

46、rver on port 80.Translating a DMZ Address with Destination NATIf the web server is on the DMZ network of the PIX, the alias command must be used to do Destination NAT (dnat). In our example, the web server on the DMZ has an IP address of 192.168.100.10, and the outside IP address for this web server

47、 is 99.99.99.99. We want to use dnat to translate the IP address 99.99.99.99 to 192.168.100.10 on the actual call to the server; the DNS call and reply will be unchanged. In this example the DNS response seen by the internal client PC will be the external 99.99.99.99 IP address, since it is not DNS doctored.Network DiagramDNS ServerOutside10.10.10.25In this example, we want machines in the 10.10.10.0 /2

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号