V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
huangya
V2EX  ›  Linux

怎么重定向在 localhost 监听的服务

  •  
  •   huangya · 188 天前 · 1037 次点击
    这是一个创建于 188 天前的主题,其中的信息可能已经有所发展或是发生改变。

    在 localhost ( 127.0.0.1 )有个服务在监听,另外有个 ethX 的物理网卡。现在想用 iptables 把从 ethX 过来的某些符合要求的包(比如特定 ip )重定向到那个服务,请问下大家怎么做呢?

    5 条回复    2023-10-23 10:29:32 +08:00
    aoizz
        1
    aoizz  
       188 天前
    sudo iptables -t nat -A PREROUTING -i ethX -p tcp --dport 目标端口 -j DNAT --to 127.0.0.1:目标端口
    huangya
        2
    huangya  
    OP
       188 天前
    @aoizz 似乎不行,我在 lo 接口抓不到对应的包
    yanqiyu
        3
    yanqiyu  
       187 天前
    @huangya
    设置 net.ipv4.conf.all.route_localnet=1 顺便检查一下防火墙规则
    proxytoworld
        4
    proxytoworld  
       187 天前
    frp
    proxytoworld
        5
    proxytoworld  
       187 天前
    话说 nginx 不是可以吗?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1010 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 18:58 · PVG 02:58 · LAX 11:58 · JFK 14:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.