Linux下简单的端口转发工具-rinetd
Rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具,用以实现端口映射、转发、重定向。Linux下端口转发一般都使用iptables来实现,使用iptables可以很容易将TCP和UDP端口从防火墙转发到内部主机上。但是如果需要将流量从专用地址转发到不在当前网络上的机器上,可尝试另一个应用层端口转发程序Rinetd。Rinetd短小、高效,配置起来比iptables也简单很多。
Rinetd是单一过程的服务器,它处理任何数量的连接到在配置文件/etc/rinetd.conf中指定的地址/端口对。尽管rinetd使用非闭锁I/O运行作为一个单一过程,它可能重定向很多连接而不对这台机器增加额外的负担。
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.
rinetd does not redirect FTP, because FTP requires more than one socket.
配置
配置端口转发的配置文件在/etc/rinetd.conf
配置文件格式
[bindaddress] [bindport] [connectaddress] [connectport]
绑定的地址 绑定的端口 连接的地址 连接的端口
[Source Address] [Source Port] [Destination Address] [Destination Port]
源地址 源端口 目的地址 目的端口
在每一单独的行中指定每个要转发的端口。源地址和目的地址都可以是主机名或IP地址,IP 地址0.0.0.0将rinetd绑定到任何可用的本地IP地址上。例如:0.0.0.0 8080 www.freeoa.net 80
配置规则
$ vim /etc/rinetd.conf
0.0.0.0 8080 172.19.94.1 8080
0.0.0.0 2222 192.168.0.113 3389
1.2.3.4 80 192.168.2.10 80
allow *.*.*.*
logfile /var/log/rinetd.log
说明
0.0.0.0表示本机绑定所有可用地址
将所有发往本机8080端口的请求转发到172.19.94.3的8080端口
将所有发往本机2222端口的请求转发到192.168.0.103的3389端口
将所有发往1.2.3.4的80端口请求转发到192.168.0.10的80端口
allow设置允许访问的ip地址信息,*.*.*.*表示所有IP地址
logfil设置打印的log的位置
注意:
1、rinetd.conf中绑定的本机端口必须没有被其它程序占用
2、运行rinetd的系统防火墙应该打开绑定的本机端口
3、不支持FTP的跳转
4、配置文件中可以对某个IP或者IP段进行允许/拒绝,藉此提高内网端口的安全性;如果二者冲突则拒绝优先。
最新版本:0.6
项目主页:http://www.boutell.com/rinetd