V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaofami
V2EX  ›  宽带症候群

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

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

    你再看一下你的文档,是 inteface 还是 NIC。
    bao3
        13
    bao3  
       2018-01-15 01:11:56 +08:00
    我 X,传说中 V2EX 说支持 markdown 呢,为毛我用的都不显示。。。
    580a388da131
        14
    580a388da131  
       2018-01-15 03:09:24 +08:00
    @bao3 回复不支持
    terrancesiu
        15
    terrancesiu  
       2018-01-15 09:11:26 +08:00
    ros 容易,你说的 pfSense 没设置过。
    msg7086
        16
    msg7086  
       2018-01-16 04:54:00 +08:00
    pfsense 本质上是 pf 编辑,你可以看看怎么写个脚本在拿到 ip 以后写 pf。
    而且你都走 ESXi 了,难道你的网卡是 pass through 的么,如果不是,那虚拟机上开虚拟的物理网卡不是分分钟。
    skylancer
        17
    skylancer  
       2018-01-16 09:31:47 +08:00
    @xiaofami interface 和 adapter 分清楚好点...
    xiaofami
        18
    xiaofami  
    OP
       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
        19
    msg7086  
       2018-01-16 21:51:49 +08:00
    @xiaofami 正好昨天在 tg 群里谈到这个问题。
    我查下来的资料是 DMZ 就是用 1:1NAT 实现的。
    也就是说,DMZ 是描述内网主机的,说的是电脑;而 1:1NAT 是描述网络连接方案的,说的是路由器。
    不知道我有没有理解错。

    你说的暴露主机,可能是 routing / bridge 到对应的主机吧,但是家庭网络也不支持 VLAN,应该是做不到的。
    xiaofami
        20
    xiaofami  
    OP
       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... ;-)
    flyfishcn
        21
    flyfishcn  
       2018-01-18 19:49:28 +08:00
    @xiaofami #20 如果是家用路由器,就不需要区分的那么清楚,你可以认为他们是同一个。区域的划分主要是靠安全等级。 当高安全级别区域访问低安全级别区域的时候,安全策略是默认允许的,低安全级别区域访问高安全级别区域则需要靠 ACL 放行。实际上 DMZ 并不是 interface 或者 adapter,而是类似于别名映射的关系。
    chinawrj
        22
    chinawrj  
       2018-01-19 09:17:27 +08:00
    OpenWRT 弄得话就是搞定了。你这个不会啊。iptables 可以轻松搞定。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1184 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 23:09 · PVG 07:09 · LAX 16:09 · JFK 19:09
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.