rinetd可较haproxy可实现UDP/TCP转发,haproxy仅能转发TCP。(以下为Centos7环境)
Github链接:https://github.com/samhocevar/rinetd
安装依赖,编译工具
gcc是GCC中的GUN C Compiler(C 编译器)
g++是GCC中的GUN C++ Compiler(C++编译器)
以CentOS为例,安装后是没有C语言和C++编译环境的,需要手动安装
| #安装依赖 | |
| yum -y install gcc gcc-c++ make automake | |
| #下载rinetd,无法链接可看文章:https://maobuni.com/2022/06/01/linux-shell-proxy/ | |
| #或先下载后上传 | |
| wget https://github.com/samhocevar/rinetd/releases/download/v0.73/rinetd-0.73.tar.gz | |
| #解压 | |
| tar -zxvf rinetd-0.73.tar.gz | |
| #进入目录 | |
| cd rinetd-0.73 | |
| #编译安装 | |
| ./bootstrap | |
| ./configure | |
| make && make install |
rinetd配置文件的格式如下:
0.0.0.0:源IP2018:源端口192.168.1.2:目标IP2019:目标端口TCP转发文件编写格式
| #新建rinetd配置文件 | |
| vi /etc/rinetd.conf | |
| #填写如下内容,意为监听本地2022端口并转发至192.168.1.2的2023端口 | |
| 0.0.0.0 2022 192.168.1.2 2023 | |
| #以配置文件启动rinetd | |
| rinetd -c /etc/rinetd.conf |
UDP转发文件编写格式
127.0.0.1 8000/udp 192.168.1.2 8000/udp意为监听本地8000UDP端口,并转发至192.168.1.2的8000端口
| #创建rinetd服务 | |
| vi /etc/systemd/system/rinetd.service | |
| #写入以下内容 | |
| [Unit] | |
| Description=rinetd | |
| After=network.target | |
| [Service] | |
| Type=forking | |
| ExecStart=/usr/local/sbin/rinetd -c /etc/rinetd.conf | |
| [Install] | |
| WantedBy=multi-user.target |
systemctl daemon-reload重载daemon使其生效,以下为rinetd服务管理命令
| #启动rinetd | |
| systemctl start rinetd | |
| #设置开机启动 | |
| systemctl enable rinetd | |
| #停止rinetd | |
| systemctl stop rinetd | |
| #重启 | |
| systemctl restart rinetd |
rinetd支持转发到域名,rinetd会提前解析域名,并将解析出的IP缓存到内存中,域名解析IP发生了变化必须重启rinetd才会生效更改,域名IP经常发生变化的情况下需要自己写个shell重启rinetd。
需要UDP且需要携带原始IP地址(haproxy的proxy参数),可考虑混用。可用于转发Windows remote desk。