Linux:rinetd的安装部署以及端口转发

rinetd的安装部署以及端口转发

rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具。Rinetd是单一过程的服务器,它处理任何数量的连接到在配置文件etc/rinetd中指定的地址/端口对。尽管rinetd使用非闭锁I/O运行作为一个单一过程,它可能重定向很多连接而不对这台机器增加额外的负担。使用iptables 很容易将TCP 和UDP 端口从防火墙转发到内部主机上。但是如果您需要将流量从专用地址转发到甚至不在您当前网络上的机器上,又该怎么办呢?可尝试另一个应用层端口转发程序,如rinetd。
摘自:https://www.zhuguodong.com/?id=457

安装部署

[root@localhost ~]# mkdir /rinted/
[root@localhost ~]# cd /rinted/
[root@localhost rinted]# yum -y install gcc gcc-c++ make automake
[root@localhost rinted]# wget https://github.com/samhocevar/rinetd/releases/download/v0.70/rinetd-0.70.tar.gz
[root@localhost rinted]# tar xfv rinetd-0.70.tar.gz
[root@localhost rinted]# cd rinetd-0.70/
[root@localhost rinetd-0.70]# ./bootstrap
[root@localhost rinetd-0.70]# ./configure
[root@localhost rinetd-0.70]# make && make install

创建systemd服务

[root@localhost rinetd-0.70]# vim /etc/systemd/system/rinetd.service
[Unit]
Description=rinetd
After=network.target

[Service]
Type=forking
ExecStart=/rinted/rinetd-0.70/rinetd -c /etc/rinetd.conf

[Install]
WantedBy=multi-user.target
[root@localhost rinetd-0.70]# systemctl daemon-reload

创建配置文件

#创建配置文件
[root@localhost rinetd-0.70]# vim /etc/rinetd.conf
0.0.0.0 9998 192.168.186.200 80
#解释:将所有发往本机9998端口的请求转发到192.168.186.200的80端口
#配置文件格式很简单:
[Source Address] [Source Port] [Destination Address] [Destination Port]

功能测试

[root@localhost rinetd-0.70]# yum -y install nginx
[root@localhost rinetd-0.70]# echo nginx > /usr/share/nginx/html/index.html
[root@localhost rinetd-0.70]# systemctl start nginx
[root@localhost rinetd-0.70]# systemctl start rinetd.service
[root@localhost rinetd-0.70]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:9998            0.0.0.0:*               LISTEN      122753/rinetd
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      663/rpcbind
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11999/nginx: master
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1351/dnsmasq
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      902/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1159/master
tcp        0      0 127.0.0.1:6011          0.0.0.0:*               LISTEN      79221/sshd: root@pt
tcp6       0      0 :::111                  :::*                    LISTEN      663/rpcbind
tcp6       0      0 :::80                   :::*                    LISTEN      11999/nginx: master
tcp6       0      0 :::22                   :::*                    LISTEN      902/sshd
tcp6       0      0 :::8088                 :::*                    LISTEN      59878/httpd
tcp6       0      0 ::1:25                  :::*                    LISTEN      1159/master
tcp6       0      0 ::1:6011                :::*                    LISTEN      79221/sshd: root@pt
#可以看到,rinetd已经开始监听9998端口
[root@localhost rinetd-0.70]# curl 192.168.186.200:9998
nginx
#端口转发成功!

注意事项:
1.rinetd.conf中绑定的本机端口必须没有被其它程序占用;
2.运行rinetd的系统防火墙应该打开绑定的本机端口;
3.每次修改配置文件之后都要重新启动服务。

猜你喜欢

转载自blog.csdn.net/rookie23rook/article/details/110084074