跳至主要内容

内网域名访问内网服务器(二)


将碰到的好帖子做一个集合
NAT分析(内网用户通过域名访问服务器)

下面是我对两个帖子的学习整理

第一个帖子

环境假设

内网服务器的私网地址为192.168.2.251,将服务器的80端口映射至202.101.1.1的80端口上,并申请域名www.sina.com,内网PC机的IP地址为192.168.2.2
在路由器外网口配置如下命令: 
 sys acl number 2000 
 rule permit source 192.168.2.0 0.0.0.255 
 quit 
 int g0/0
//外网口 
 ip address 202.101.1.1 255.255.255.0 
 nat server protocol tcp global 202.101.1.1 www indise 192.168.2.251 www 
 nat outbound 2000 quit

数据流程分析

一. 外网用户通过域名或者公网IP地址应该可以访问服务器

  1. 外网用户发起到202.101.1.1的TCP 80端口的连接,IP报头结构如下:源IP:外网用户的公网IP,目的IP:202.101.1.1
  2. 数据经过路由,到企业边源路由器,由于外网口上有端口映射,则数据会匹配映射,将IP报头结构改变成:源IP:外网用户的公网IP,目的IP:192.168.2.251
  3. 数据经过内网路由,交到服务器,服务器回应用户数据,IP报头结构如下:源IP:192.168.2.251,目的IP:外网用户的IP
  4. 数据经过边界路由器出公司,由于NAT Server的优先级高于NAT Outbound,所以,数据到达路由器后会先匹配NAT Server记录的会话表项,将IP报头转换成:源IP:202.101.1.1,目的IP:外网用户的公网IP
  5. 数据最终通过公网路由到达访问用户,数据访问成功

二. 内网用户通过域名是不能访问服务器的

  1. 内网用户发起DNS请求,域名解地址为202.101.1.1,客户机发出请求,IP报头结构如下:源IP:192.168.2.2,目的IP:202.101.1.1
  2. 数据到达路由器后,由于路由器上有202.101.1.1的直连路由,数据直接交到外网口,由于外网口配置有NAT Server,目的IP被转换后发到服务器,IP报头结构如下:源IP:192.168.2.2,目的IP:192.168.2.251
  3. 服务器收到数据后,发现源IP就是一个本地IP地址,此时服务器就不会以202.101.1.1为ip回复,而是以192.168.2.251为源地址回复。此时的IP数据包结构为:源IP:192.168.2.251,目的IP:192.168.2.2
  4. 数据将到客户机后,客户机认为,自己请求的是202.101.1.1的数据,但是收到的是192.168.2.2发送的,则认为这个数据不是自己要的,此时会丢弃掉该数据,从而引起TCP等待超时,导致无法访问

三.未解决问题,可在内网口设置

  1. acl number 3000
  2. rule permit ip source 192.168.2.0 0.0.0.255 destination 192.168.2.251
  3. quit
  4. int g0/1
  5. //内网口   nat outbound 3000
  6. nat server protocol tcp global 202.101.1.1 www inside 192.168.2.251 www
  7. quit

四.再在内网域名访问服务器,查看数据流程

  1. 内网用户发起DNS请求,域名解析为202.101.1.1地址,客户机发出请求,IP报头结构如下:源IP:192.168.2.2,目的IP:202.101.1.1
  2. 数据交到路由器的内网口,首先匹配端口映射,将目的IP更换掉,此时IP报头结构如下:源IP:192.168.2.2,目的IP:192.168.2.251
  3. 路由器发现该数据为内网数据,会再从内网口发出去,此时再匹配nat outbound,将源IP换掉,此时IP报头结构为:源IP:192.168.2.1,目的IP:192.168.2.251
  4. 服务器收到数据后响应请求,回复数据包IP报头结构为:源IP:192.168.2.251,目的IP:192.168.2.1
  5. 数据到达路由器后,根据NAT Outbound和NAT Server的记录表项,将源IP和目的IP替换掉,此时IP报头结构为:源IP:202.101.1.1,目的IP为192.168.2.2
  6. 数据到达客户,目的IP和源IP正确,访问成功

五.如果有一个假设

现在我们假设没有
nat server protocol tcp global 202.101.1.1 www inside 192.168.2.251 www,
来看一下数据报文是否能完整地走完:(目前MSR路由器上的端口映射配置全局有效,不需要再在内网口配置该命令了。)

  1. 内网用户发起DNS请求,域名解析为202.101.1.1地址,客户机发出请求,IP报头结构如下:源IP:192.168.2.2,目的IP:202.101.1.1
  2. 数据将到路由器,由于外网口上有端口映射,则数据会匹配映射,将IP报文结构改变成: 源IP:192.168.2.2,目的IP:192.168.2.251
  3. 数据将到路由器内网口,匹配nat outbound,将源IP地址变掉,IP报文结构改变成:源IP:192.168.2.1,目的IP:192.168.2.251
  4. 数据交至服务器,服务器回复报文,IP报头为:源IP:192.168.2.251,目的IP:192.168.2.1
  5. 路由器收到后,匹配内网口NAT Outbound的记录表项,将其IP报头改为:源IP:192.168.2.251,目的IP:192.168.2.2
  6. 数据直接交给客户机,客户机依然认为不是自己请求的数据,丢弃,继续等待,超时,失败

第二个帖子

Add caption
最后的最后,我是这样解决自己路由器问题的,登录官网,发现自己路由器貌似不支持端口回流,然后在线咨询客服,得知在NAPT上添加一条规则即可,作用接口是LAN口





Popular posts from 产品随想的博客

黑客讲述渗透Hacking Team全过程

原文地址在 Freebuf ,后来已经被删除 Wayback Machine 备份 近期,黑客 Phineas Fisher在pastebin.com上讲述了入侵Hacking Team的过程,以下为其讲述的原文情况,文中附带有相关文档、工具及网站的链接,请在安全环境下进行打开,并合理合法使用。作者部分思想较为激进,也请以辩证的观点看待之。 1、序言 在这里,可能你会注意到相比于前面的一个版本,这个版本的内容及语言有了一些变化,因为这将是最后一个版本了 [1] 。对于黑客技术,英语世界中已经有了许多书籍,讲座,指南以及关于黑客攻击的知识。在那个世界,有许多黑客比我优秀,但他们埋没了他们的天赋,而为所谓的“防护”服务商(如Hacking Team之流的),情报机构服务工作。黑客文化作为一项非主流文化诞生于美国,但它现在只保留了它本质的魅力,其他均被同化了。从黑客的本质出发,至少他们可以穿着一件T恤,把头发染成蓝色,用自己的黑客的名字,随意 洒脱 地做着自己喜欢的事件,而当他们为别人(前文所指的 Hacking Team及情报机构 )工作的时候,会感觉自己像个反抗者。 如果按照传统的方式,你不得不潜入办公室偷偷拿到文件[2],或者你不得不持枪抢劫银行。但现在你仅仅需要一台笔记本,躺在床上动动手指便可做得这一切[3][4]。像CNT在入侵伽玛集团(Gamma Group)之后说的,“让我们以一种新的斗争方式向前迈进吧”[5]。 [ 1 ] http: / /pastebin.com/raw .php?i=cRYvK4jb [ 2 ] https: / /en.wikipedia.org/wiki /Citizens%27_Commission_to_Investigate_the_FBI [3] http:/ /www.aljazeera.com/news /2015/ 09/algerian-hacker-hero-hoodlum- 15092108 3914167 .html [ 4 ] https: / /securelist.com/files /2015/ 02 /Carbanak_APT_eng.pdf  [ 5 ] http: / /madrid.cnt.es/noticia /consideraci...

360T7 刷机步骤及固件

https://cmi.hanwckf.top/p/360t7-firmware/   360T7的固件支持由immortalwrt-mt798x项目提供支持,请参考: https://cmi.hanwckf.top/p/immortalwrt-mt798x https://github.com/hanwckf/immortalwrt-mt798x 刷机步骤 参考 此处 的办法开启原厂固件的UART和telnet功能 在以下链接下载360T7测试固件(纯净版,无任何插件) https://wwd.lanzout.com/b0bt9idwd 密码:ezex (此固件已过时,请选择其它更新的固件) 接下来将刷入修改版uboot。修改版uboot的优点有: 固件分区可达108MB,原厂uboot只能使用36M 自带一个简单的webui恢复页面 到以下仓库的Release页面下载uboot,目前暂时仅支持360T7,后续将支持更多mt798x路由器。 推荐使用 mt7981_360t7-fip-fixed-parts.bin , fixed-parts 代表uboot分区表在编译期间固定,不会随着uboot环境变量变化。 https://github.com/hanwckf/bl-mt798x/releases/latest 将 mt7981_360t7-fip-fixed-parts.bin 通过HFS等方式上传到路由器,使用以下命令刷入uboot mtd write mt7981_360t7-fip-fixed-parts.bin fip 确认刷入完毕后,拔掉路由器电源。然后将电脑的IP地址设置为固定的 192.168.1.2 ,接着按住路由器的RESET按钮后通电开机,等待8s后用浏览器进入 192.168.1.1 在uboot恢复页面选择要刷入的固件。immortalwrt-mt798x目前编译两个版本的360T7固件。 建议修改版uboot直接使用 immortalwrt-mediatek-mt7981-mt7981-360-t7-108M-squashfs-factory.bin ,两种固件区别如下: mt7981-360-t7-108M 为108M固件分区,原厂uboot不可启动,需要修改版u...

产品爱好者周刊 第26期:PRISM, XKeyscore, Trust No One

  Products Gitea - Git with a cup of tea   https://gitea.io/en-us/ A painless self-hosted Git service. 自建Git服务,避免GitHub隐私侵犯 https://github.com/objective-see/LuLu LuLu is the free macOS firewall 监视Mac的出站流量,且阻断 OverSight   https://github.com/objective-see/OverSight OverSight monitors a mac's mic and webcam, alerting the user when the internal mic is activated, or whenever a process accesses the webcam. 监视是否有应用调用Mac的麦克风、摄像头 Mozilla Hubs   https://github.com/mozilla/hubs The client-side code for Mozilla Hubs, an online 3D collaboration platform that works for desktop, mobile, and VR platforms. 开源的多人虚拟空间,Mozilla打造,企业级VR诉求 数字移民   https://shuziyimin.org 关于内容源、工具的推荐,适合刚接入国际的新人 SimpleLogin   https://simplelogin.io/ 匿名邮箱工具,转发用,Michael Bazzell推荐 Telegram 群组、频道、机器人 - 汇总分享   https://congcong0806.github.io/2018/04/24/Telegram/#机器人-bot https://archive.ph/iJMBj 献给那些将来到Telegram的朋友 Design Patrick Wardle   https://www.instagram.com/patrickwardle/?hl=en 他的IG,摄影也精彩,审美...

UNstudio实习经验分享

再过一周,我就将离开UNstudio阿姆斯特丹总部,到其上海分部了,鉴于上海分部目前还不承担设计任务,因此可以视为我UNstudio参与设计的体验即将告一段落。这个实习,原定3个月,后来被要求延长到了6个月,后来又延长到9个月,现在看来最终大概有11个月——那天一问,发现我的合同已经到了9月份了,赶紧声明不能这么长,我8月得回学校了。

文明、现代化、价值投资与中国 By 李录

 价值投资的概念/框架: 1)股票是对公司的所有权,而不仅仅是一张纸; 2)安全边际;(预测未来,但要留好安全边际) 3)市场先生;(让市场来服务你,而不是被指导) 4)能力圈;(建立属于自己的能力圈) 公司的来源: 欧洲扩张,从国王到贵族,到有钱人,到平民 《价值线》-几千家公司过去10年的财务情况

Interview at the All Things Digital D5 Conference, Steve and Bill Gates spoke with journalists Kara Swisher and Walt Mossberg onstage in May 2007.

Kara Swisher: The first question I was interested in asking is what you think each has contributed to the computer and technology industry— starting with you, Steve, for Bill, and vice versa. Steve Jobs: Well, Bill built the first software company in the industry. And I think he built the first software company before anybody really in our industry knew what a software company was, except for these guys. And that was huge. That was really huge. And the business model that they ended up pursuing turned out to be the one that worked really well for the industry. I think the biggest thing was, Bill was really focused on software before almost anybody else had a clue that it was really the software that— KS: Was important? SJ: That’s what I see. I mean, a lot of other things you could say, but that’s the high-order bit. And I think building a company’s really hard, and it requires your greatest persuasive abilities to hire the best ...

产品爱好者周刊 第10期:乔布斯逝世10年

  产品爱好者周刊 第10期: 2021.10.14 Products 经济学人、卫报、Wired等电子周刊: https://github.com/hehonghui/the-economist-ebooks 每周均更新 Immersed: https://immersed.com/ 桌面端软件,可以虚拟出5个VR桌面,能模拟出在海滩、宇宙等地方,工作 它的员工写了篇自己工作流,非常酷 Working From Orbit: https://blog.immersed.team/working-from-orbit-39bf95a6d385 bilibili视频下载工具(开源) 哔哩下载姬 downkyi: https://github.com/leiurayer/downkyi Windows Only BilibiliVideoDownload: https://github.com/blogwy/BilibiliVideoDownload 多平台 BiliDuang:  https://github.com/kengwang/BiliDuang Versus: https://versus.com/cn 万物皆可比较 官网的范例,基本都是数码产品,可能是标准化产品有具体参数,容易比较些? News Jony Ive on What He Misses Most About Steve Jobs:  https://www.wsj.com/articles/jony-ive-steve-jobs-memories-10th-anniversary-11633354769 中文译本: https://archive.ph/EZihd Ideas Weather Spark:  https://weatherspark.com 全球城市的全年气候,用于去陌生城市、旅行规划了解城市天气,会有帮助 Long Now Foundation:  https://twitter.com/longnow 以10000年的跨度,去思考未来的可能性,真是一件很浪漫的事情 Outside interests Notion会私自查看用户的内容

A Sister’s Eulogy for Steve Jobs

I grew up as an only child, with a single mother. Because we were poor and because I knew my father had emigrated from Syria, I imagined he looked like Omar Sharif. I hoped he would be rich and kind and would come into our lives (and our not yet furnished apartment) and help us. Later, after I’d met my father, I tried to believe he’d changed his number and left no forwarding address because he was an idealistic revolutionary, plotting a new world for the Arab people. Even as a feminist, my whole life I’d been waiting for a man to love, who could love me. For decades, I’d thought that man would be my father. When I was 25, I met that man and he was my brother. By then, I lived in New York, where I was trying to write my first novel. I had a job at a small magazine in an office the size of a closet, with three other aspiring writers. When one day a lawyer called me — me, the middle-class girl from California who hassled the boss to buy us health insurance — and said his cl...

《Becoming Steve Jobs》Chapter 16 Blind Spots, Grudges, and Sharp Elbows

Steve could be pretty thin-skinned when someone prominent criticized the aesthetics of his products. He took great umbrage that Neil would, as Steve put it, “pop off in public like that without coming to talk to us about his technical concerns first.” From that point on he had rebuffed all of Neil’s attempts to smoke the peace pipe. 有趣 He had blind spots, grating behavioral habits, and a tendency to give in to emotional impulse that persisted his entire life. These characteristics are often used to make the case that Steve was an “asshole” or a “jerk,” or perhaps simply “binary”—that odd adjective often used to convey the sense that he was half asshole/half genius from birth to death. These aren’t useful, interesting, or enlightening descriptions. What’s more illuminating is to take a look at the specific ways in which Steve failed to do an effective job of tempering some of his weaknesses and antisocial traits, and to consider how, when, and why some of them continued to flare up even...