Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
huangya
V2EX  ›  Linux

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

  •  
  •   huangya · Oct 22, 2023 · 1663 views
    This topic created in 934 days ago, the information mentioned may be changed or developed.

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

    5 replies    2023-10-23 10:29:32 +08:00
    aoizz
        1
    aoizz  
       Oct 22, 2023
    sudo iptables -t nat -A PREROUTING -i ethX -p tcp --dport 目标端口 -j DNAT --to 127.0.0.1:目标端口
    huangya
        2
    huangya  
    OP
       Oct 22, 2023
    @aoizz 似乎不行,我在 lo 接口抓不到对应的包
    yanqiyu
        3
    yanqiyu  
       Oct 23, 2023
    @huangya
    设置 net.ipv4.conf.all.route_localnet=1 顺便检查一下防火墙规则
    proxytoworld
        4
    proxytoworld  
       Oct 23, 2023
    frp
    proxytoworld
        5
    proxytoworld  
       Oct 23, 2023
    话说 nginx 不是可以吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   965 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 77ms · UTC 20:00 · PVG 04:00 · LAX 13:00 · JFK 16:00
    ♥ Do have faith in what you're doing.