V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
mingl0280
V2EX  ›  Linux

[搞晕了] Ubuntu 下用 iptables 配置端口转发莫名其妙无效,求正确做法……

  •  
  •   mingl0280 ·
    mingl0280 · Feb 11, 2017 · 4983 views
    This topic created in 3362 days ago, the information mentioned may be changed or developed.
    近日遇到个坑爹问题要把 70 端口的访问转到 1433 上去,然后在 VPS 上折腾了两个小时的 iptables ,还是没搞定……
    (gopher 就是 70 端口)
    目前 iptables 的状态如下:
    FORWARD
    target prot opt source destination
    ACCEPT tcp -- anywhere anywhere tcp dpt:gopher
    NAT 表:
    Chain PREROUTING (policy ACCEPT)
    target prot opt source destination
    DNAT tcp -- anywhere server.dns.com tcp dpt:27016 to:10.8.0.2
    DNAT tcp -- anywhere server.dns.com tcp dpt:7777 to:10.8.0.2
    DNAT tcp -- anywhere anywhere tcp dpt:gopher to:10.8.0.2:1433

    Chain POSTROUTING (policy ACCEPT)
    target prot opt source destination
    MASQUERADE all -- 10.8.0.0/24 anywhere
    MASQUERADE all -- anywhere anywhere
    ipv4 转发已开启(不然 VPN 也没法运行……)

    但是现在拿 nmap 自己扫一发发现 70 端口依旧是 filtered 状态……完全无法使用……
    求教是什么原因?应该如何解决?
    3 replies    2017-02-12 09:24:14 +08:00
    zen9073
        1
    zen9073  
       Feb 11, 2017
    sysctl 有开启转发吗
    mmmyc
        2
    mmmyc  
       Feb 12, 2017 via Android
    原来 iptables 还可以写成这样,太高深了。
    和我之前看过的都不一样啊。
    zzlyzq
        3
    zzlyzq  
       Feb 12, 2017 via iPhone
    加上 nat masquerade 试试。 你这个 redirect 到另外的机器了。

    另外, nmap 的地点也有关系。 如果 nat 服务器本地测试,不会走 prerouting ,而是 output 。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6142 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 06:14 · PVG 14:14 · LAX 23:14 · JFK 02:14
    ♥ Do have faith in what you're doing.