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

推荐 bindp,为 Linux 上运行的程序绑定 IP 地址和端口

  •  
  •   yongboy · Sep 9, 2016 · 4080 views
    This topic created in 3558 days ago, the information mentioned may be changed or developed.

    Github 地址: https://github.com/yongboy/bindp

    基于 LD_PRELOAD 机制,可以作用于:

    • 已有的网络程序客户端 /服务器程序,比如nccurlwgetnginx
    • 使用 Java 、 Python 等语言编写的网络 Server 或客户端 Client 程序

    特性如下:

    • 绑定制定 IP 地址和端口
    • 添加 SO_REUSEADDR 特性支持
    • 添加 SO_REUSEPORT 特性支持
    • 添加 IP_TRANSPARENT 特性支持

    下载编译:

    git clone https://github.com/yongboy/bindp.git
    cd bindp
    make
    

    使用方式:

    假设本地多个可用 IP 地址包含 10.10.10.10 ,并且假设端口 49999 没被占用,那么我们可以在作为客户端访问远程服务器时进行制定 IP 地址和端口:

    REUSE_PORT=1 BIND_ADDR="10.10.10.10" BIND_PORT=49999 LD_PRELOAD=/the_path/libindp.so nc 10.10.10.11 80
    

    假设 Nginx 配置监听 80 端口,不想修改配置文件的话而使之监听 9090 端口,我们可以这样做:

    BIND_PORT=9090 LD_PRELOAD=/your_path/libindp.so /usr/sbin/nginx -c /etc/nginx/nginx.conf
    

    更多用法,请直接参考文档: https://github.com/yongboy/bindp

    4 replies    2016-09-09 22:33:25 +08:00
    majinjing3
        1
    majinjing3  
       Sep 9, 2016 via Android
    支持一个~已 star
    holyzhou
        2
    holyzhou  
       Sep 9, 2016
    好像有点意思
    sopato
        3
    sopato  
       Sep 9, 2016
    是有点意思哦,已经 watch
    sparkssssssss
        4
    sparkssssssss  
       Sep 9, 2016 via Android
    马克找,感谢分享
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6006 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 66ms · UTC 03:24 · PVG 11:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.