如何为动态 IP 设置 1:1 NAT

2018-01-14 10:47:53 +08:00
 xiaofami
家里的网络可以通过 PPPoe 拨号获取多个外网 IP 地址。现在我想通过 1:1 NAT 将其中一个 IP 地址分配给内网中某台设备,使其完全暴露在外部网络。设置 1:1 NAT 一切顺利,经测试能得到 FullCone NAT 类型。不过 1:1 NAT 必须指定一个固定的 External IP,而通过 PPPoe 获取的地址是动态的,每次发生变化后都要重新设置规则。有没有办法绕过这种限制,比如说执行一个 cron 任务定期检查对应 WAN 口 IP,如果变化就自动更新规则,还是说有更好的解决办法?在设备上直接 PPPoe 拨号是可行的,但是为了管理方便我不想这么做 。。。 路由使用的是 pfSense。
5088 次点击
所在节点    宽带症候群
22 条回复
boywhp
2018-01-14 11:18:47 +08:00
感觉就是设置 DMZ 区,找找看有没有对应的设置项?
10467106
2018-01-14 11:47:18 +08:00
dmz 或 dnat
LGA1150
2018-01-14 13:02:59 +08:00
允许多拨?让终端再拨一次
mooncakejs
2018-01-14 13:45:32 +08:00
如果是 OP 之类,if up 脚本
lewiseek
2018-01-14 14:42:21 +08:00
能多线多拨吗,能的话上个交换机要单独获取 IP 的设备独立拨号不就行了
Tink
2018-01-14 14:51:54 +08:00
dmz
xiaofami
2018-01-14 17:45:43 +08:00
@boywhp @10467106 @Tink
DMZ 貌似不行,我读到的文档说设置 DMZ 需要第三张网卡,我的 ESXI Host 机只有 2 张物理网卡,DMZ 即便设置好其他物理机也无法加入
@LGA1150 @mooncakejs
能多拨,终端也能独立拨号,不过感觉不如在路由端统一管理方便
LGA1150
2018-01-14 18:27:41 +08:00
@xiaofami
SNAT 换成 MASQUERADE
qwvy2g
2018-01-14 18:36:21 +08:00
一对一 nat。
bazingaterry
2018-01-14 18:43:41 +08:00
利用 pppoe 的 hook ?
flynaj
2018-01-14 21:44:56 +08:00
ros 是有这个设置,你这个是不是已经没有更新的系统
bao3
2018-01-15 01:11:27 +08:00
应该是只要你有 **3** 个 interface 就可以,而不是三个物理网上。多数系统(*BSD/*linux)只是利用 interface 作逻辑区分用,而不是要求你有 **3** NIC。

你再看一下你的文档,是 inteface 还是 NIC。
bao3
2018-01-15 01:11:56 +08:00
我 X,传说中 V2EX 说支持 markdown 呢,为毛我用的都不显示。。。
580a388da131
2018-01-15 03:09:24 +08:00
@bao3 回复不支持
terrancesiu
2018-01-15 09:11:26 +08:00
ros 容易,你说的 pfSense 没设置过。
msg7086
2018-01-16 04:54:00 +08:00
pfsense 本质上是 pf 编辑,你可以看看怎么写个脚本在拿到 ip 以后写 pf。
而且你都走 ESXi 了,难道你的网卡是 pass through 的么,如果不是,那虚拟机上开虚拟的物理网卡不是分分钟。
skylancer
2018-01-16 09:31:47 +08:00
@xiaofami interface 和 adapter 分清楚好点...
xiaofami
2018-01-16 19:28:43 +08:00
@msg7086 我可能混淆了 DMZ 和 exposed host 的概念。一般家用路由器提供的“ DMZ ”功能,其实都是 exposed host ?如果没理解错,DMZ 的子网和 LAN 应该是不同的,而一般路由器提供的“ DMZ ”显然没有做到。
另外对 DMZ 还有 2 点疑惑之处。一是如何加入 DMZ 区域。我的物理 NIC 没有直通,新建虚拟 NIC 没有问题,不过 ESXI Host 机外的物理设备貌似没办法接入。二是 DMZ 并没有解决 NAT 问题,还是需要做 1:1 map,于是又回到了问题的起点…
msg7086
2018-01-16 21:51:49 +08:00
@xiaofami 正好昨天在 tg 群里谈到这个问题。
我查下来的资料是 DMZ 就是用 1:1NAT 实现的。
也就是说,DMZ 是描述内网主机的,说的是电脑;而 1:1NAT 是描述网络连接方案的,说的是路由器。
不知道我有没有理解错。

你说的暴露主机,可能是 routing / bridge 到对应的主机吧,但是家庭网络也不支持 VLAN,应该是做不到的。
xiaofami
2018-01-16 22:23:41 +08:00
@msg7086 DMZ 是安全措施,NAT 是为了能够被公共访问到,两者经常一起使用,但并不能说 DMZ 是用 1:1 NAT 实现的。某论坛上看到的这段话解释得很清楚:

The idea of a DMZ is that you have servers that need to be accessed from the internet, as we all know. The DMZ is a separate subnet that's logically outside of your inside LAN by applying security policies to what traffic can reach it. The bigger issue is servers get hacked. Now, if that server is in a DMZ, logic would indicate that you've also created rules in your firewall (which has DMZ and inside facing interfaces) NOT to allow any traffic to originate from that DMZ server and make connections to your inside LAN, protecting your inside LAN if that DMZ server gets compromised. If you put that server on your internal LAN and then NAT a public internet IP to it, people are connecting from the internet to that server in your LAN, and if they crack it they will have access to everything else on your inside LAN from that box. If it were in a DMZ and gets hacked, the firewall will block the hacker from making connections to the inside LAN from it.

What Sosipater is saying about how you'll probably use NAT in your DMZ anyway because many people create a separate DMZ subnet and assign private, non-internet-routable IPs like 192.168.x.x to the servers in the DMZ. You then have to "NAT" whatever public internet IP, from your ISP, to that private IP assigned to the server. In this case, you're using BOTH a DMZ and NAT.

Either way, if the server is going to be accessed from the Web, use a DMZ! Its a best practice and just the smart way to go. You already have a firewall. The only cost associated should be if you get payed OT or not... ;-)

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/422744

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX