wildcat007
V2EX  ›  问与答

利用 nc 能否转发端口呀?好捉急.

  •  
  •   wildcat007 · Jan 16, 2017 · 2372 views
    This topic created in 3451 days ago, the information mentioned may be changed or developed.
    业务背景:
    在内网主机 centos , IP10.10.10.10 ,下载了一个软件 [就一个文件] ,启用服务后有个管理 web ,地址为 127.0.0.1:4040
    curl 127.0.0.1:4040 正常。

    实现一个小目标:
    但是我办公机想访问这个 4040 端口就为难了,然后想到了 nginx 代理可以做。那么想问下 nc 是否可以做呢?
    4 replies    2017-01-16 13:12:42 +08:00
    lhbc
        1
    lhbc  
       Jan 16, 2017 via iPhone   ❤️ 1
    nginx, iptables, nc 都可以。
    哪个熟悉就用哪个吧, iptables 最简单。
    Showfom
        2
    Showfom  
    PRO
       Jan 16, 2017   ❤️ 1
    iptables 最简单了 一条命令搞定

    tcp 协议的话 haproxy 也简单 你这个需求 nginx 也没问题

    nc 一般不是这么用的啦- - 临时用用的
    kaneg
        3
    kaneg  
       Jan 16, 2017   ❤️ 1
    如果你有 root 权限,可以用 iptables :
    iptables -t nat -I PREROUTING -i eth0 -p TCP --dport 4040 -j DNAT --to-destination :4040

    如果没有 root 权限,可以用 socat :
    socat TCP-LISTEN:4040,reuseaddr,fork TCP:localhost:4040
    wildcat007
        4
    wildcat007  
    OP
       Jan 16, 2017
    @lhbc
    @Showfom
    @kaneg
    感谢各位,以前知道 nc 可以反弹 shell ,端口监听,以为可以一条命令完成需求,后来百度了下,还是用的 socat 比较方便
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5157 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 09:41 · PVG 17:41 · LAX 02:41 · JFK 05:41
    ♥ Do have faith in what you're doing.