• Linux下使用Rinetd来实现端口转发


    简介:

    Rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具。Rinetd是单一过程的服务器,它处理任何数量的连接到在配置文件etc/rinetd中指定的地址/端口对。尽管rinetd使用非闭锁I/O运行作为一个单一过程,它可能重定向很多连接而不对这台机器增加额外的负担。

    用途:

    使用iptables 很容易将TCP 和UDP 端口从防火墙转发到内部主机上。但是如果需要将流量从专用地址转发到甚至不在您当前网络上的机器上,可尝试另一个应用层端口转发程序,如rinetd。这些代码有点古老,但很短小、高效,对于解决这种问题来说是非常完美的。

    方法:

    1.从官网下载:http://www.boutell.com/rinetd/

    1
    [root@DaoBiDao tmp]# wget http://www.boutell.com/rinetd/http/rinetd.tar.gz

    2.解压下载的文件:

    1
    [root@DaoBiDao tmp]#tar -xvf rinetd.tar.gz

    3.修改rinetd.c 将查询到的65536修改为65535,创建/usr/man目录,在进行安装

    1
    2
    3
    4
    [root@DaoBiDao tmp]#cd rinetd
    [root@DaoBiDao rinetd]#sed -i 's/65536/65535/g' rinetd.c
    [root@DaoBiDao rinetd]# mkdir /usr/man/
    [root@DaoBiDao rinetd]#make && make install

    4.成功安装:

    1
    2
    3
    4
    5
    [root@DaoBiDao rinetd]# make && make install
    make: `rinetd' is up to date.
    install -m 700 rinetd /usr/sbin
    install -m 644 rinetd.8 /usr/man/man8
    ##安装在 /usr/sbin 目录下

    5.创建配置文件:

    /etc/rinetd.conf

    配置文件格式很简单:[Source Address] [Source Port] [Destination Address] [Destination Port]

    在每一单独的行中指定每个要转发的端口。源地址和目的地址都可以是主机名或IP 地址,IP 地址0.0.0.0 将rinetd 绑定到任何可用的本地IP地址上:

    例如:0.0.0.0 8080 www.aslibra.com 80

    实例配置文件:

    1
    2
    3
    4
    [root@DaoBiDao tmp]# cat /etc/rinetd.conf
    allow 192.168.1.*                 //设置允许访问的ip地址信息
    0.0.0.0 80 192.168.0.72 80        //设置端口转发
    logfile /var/log/rinetd.log       //设置打印的log

    6.启动、关闭程序:

    启动命令:

    1
    2
    3
    [root@DaoBiDao tmp]#/usr/sbin/rinetd
    或者
    [root@DaoBiDao tmp]#rinetd -c /etc/rinetd.conf

    关闭命令:

    1
    [root@DaoBiDao tmp]# killall rinetd

    查看是否启动:

    1
    2
    [root@DaoBiDao tmp]# netstat -tanulp|grep rinetd
    tcp  0  0 0.0.0.0:65534   0.0.0.0:*   LISTEN  20669/rinetd

    7.开机启动:

    在/etc/rc.local 文件中,添加/usr/sbin/rinetd 或者 /usr/sbin/rinetd -c /etc/rinetd.conf 启动命令即可。

    8.其他:

    不支持FTP的跳转。

  • 相关阅读:
    SpringCloud
    Linux
    SpringBoot
    秒杀系统设计
    设计模式
    数据库(mysql)
    Java web
    c#常用控件及简写
    C#常用的form窗体属性(最大化、最小化、窗体居中)
    C#中使用IndexOf()判断字符串在字符串数组中第一次出现的索引位置
  • 原文地址:https://www.cnblogs.com/zxci/p/6438107.html
Copyright © 2020-2023  润新知