热爱生活,虽然她给你无尽的磨难;
珍惜所爱之人,因为她/他就是你所爱的人啊;
热爱技术,因为技术改变世界。
一 简介
1.1 本文适用人群
本文适合于那些想要快速实现端口(TCP)转发的技术人员,比如实现防火墙内SSH端口转发,MySql端口转发,以达到不更改防火墙配置的情况下实现相关的访问。
1.2 本文涉及到的技术
本文涉及到的技术有iptables、tcp协议等。
1.3 简介
rinetd软件是一种简单的tcp端口转发技术,安装和配置都十分简单。
二 具体说明
2.1 原理图
图1 架构图 [3]
2.2 技术细节
Redirects TCP connections from one IP address and port to another. rinetd is a single-process server which handles any number of connections to the address/port pairs specified in the file /etc/rinetd.conf
. Since rinetd runs as a single process using nonblocking I/O, it is able to redirect a large number of connections without a severe impact on the machine. This makes it practical to run TCP services on machines inside an IP masquerading firewall.[1]
rinetd软件实现的是将发往本机某个网口上的某个端口的访问传递到别的服务器的某个网口的某个端口,ip:prot >ip:port,端口为TCP协议的端口。
2.3 技术总结
三 例子
3.1 服务器环境
服务器环境:
网络环境:
3.2 软件环境
软件版本:
执行文件目录:
3.3 安装及配置
wget https://boutell.com/rinetd/http/rinetd.tar.gz
tar zxvf rinetd.tar.gz
cd rinetd/
mkdir -p /usr/man/man8
make
make install
配置文件:
启动:
配置后端服务器:
172.16.1.14
172.16.1.15
3.4 测试
3.5 问题总结
rinetd配置文件中可以限定访问来源的ip,但即使这样改软件的功能还是很有限。
其实rinetd的功能完全可以运用iptables来实现,就如本例子中的功能,完全可以由下面的防火墙配置实现:
iptables -t nat -I PREROUTING -p tcp --dport 10021 -j DNAT --to-destination 172.16.1.14:11021
iptables -t nat -I PREROUTING -p tcp --dport 10022 -j DNAT --to-destination 172.16.1.15:11022
iptables -t nat -I POSTROUTING -j MASQUERADE
四 参考文献
[1] https://boutell.com/rinetd/
[2] https://www.processon.com/support/question/527b22330cf276366b3508c1 processon编辑虚线
[3] https://www.processon.com/view/link/5b8557cbe4b0bd4db921215e
五 后记
5.1 文档总结
本文档简单介绍了rinetd的安装使用以及原理说明,软件的安装和使用比较简单,所以可以很方便的使用。
5.2 致谢
本人使用第一次使用该软件,完全是由三石磊在一次技术交流中提起引起的,在这里表达对他的感谢,预祝他能快乐的生活,别再继续胖下去了。
本文档难免有错误之处,请不吝指出,wusuoweide163@163.com是我的联系邮箱,同行们一起交流。
2018年8月26日 于北京昌平