Total Pageviews

Friday, 14 December 2012

使用 rinetd 进行端口转发

安装rinetd
wget http://www.boutell.com/rinetd/http/rinetd.tar.gz
tar -zxvf rinetd.tar.gz
cd rinetd
        mkdir -p /usr/man/man8
make
make install
配置文件
vi /etc/rinetd.conf
最简单的配置方式
192.168.1.100 80 192.168.1.200 80
这样就完成了
然后你所有对于 192.168.1.100 80端口的访问将转发到 192.168.1.200 的80端口上
但是有个前提就是 192.168.1.100这台机子上的没有启动任何占用80端口的进程,如apache等;否则将转发不成功。
PS:他只能转发TCP的端口,不能转发UDP以及其他协议的端口;
----------------------------------------------------

rinetd的详细配置教程

工具主页: http://www.boutell.com/rinetd/
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.
1. 解压  : tar zxvf rinetd.tar.gz
2. 建立文档目录 : mkdir -p /usr/man/man8
3.cd  rinetd
4. make && make install (默认安装到/usr/sbin/rinetd)
5. 创建配置文件 : touch /etc/rinetd.conf

配置文件
使非本地服务看上去像是来自本地端口正如我们在“iptables 的提示和诀窍”中所看到的那样,使用iptables 很容易将TCP 和UDP 端口从防火墙转发到内部主机上。但是如果您需要将流量从专用地址转发到甚至不在您当前网络上的机器上,又该怎么办呢?可尝试另一个应用层端口转发程序,如 rinetd。这些代码有点古老,但很短小、高效,对于解决这种问题来说是非常完美的。解压缩该档案文件并简单地运行make命令,您将看到一个 rinetd二进制数,允许您将TCP 端口转发到您期望的内容。不幸的是,rinetd不支持UDP 端口。
配置文件极为简单:
[Source Address] [Source Port] [Destination Address] [Destination Port]
在每一单独的行中指定每个要转发的端口。源地址和目的地址都可以是主机名或IP 地址,IP 地址0.0.0.0 将rinetd 绑定到任何可用的本地IP地址上:
0.0.0.0 80 some.othersite.gov 80
216.218.203.211 25 123.45.67.89 25
0.0.0.0 5353 my.shellserver.us 22
将该文件保存到/etc/rinetd.conf,并将rinetd复制到容易找到的位置(例如/usr/local/sbin/)。然后简单地运行rinetd 开始启动该命令。
第一个示例将所有去往任意本地地址的Web 流量转发到some.othersite.gov 上。注意,这只有在本地端口80 上未绑定其他进程(如Apache)时才有效。
下 一步将去往2 1 6 . 2 1 8 . 2 0 3 . 2 1 1 的入站S M T P 流量转发到位于123.45.67.89 的邮件服务器上(但其他本地IP 地址上未绑定任何SMTP代理)。最后的示例将端口5353 上的流量转发到myshellserver.us 的ssh网络服务器上。这些设置在没有NAT或任何特殊核心配置的情况下都能有效工作。简单地运行rinetd,rinetd将在后台运行并启动对指定端 口的监听。当你的服务器要重新编号或物理位置变化而改变IP地址时你就能切实感受到这个工具的好处了,因为服务看上去就像保留在原始IP 地址(即便它们实际上完全是来自其他网络)上。如果仅仅是绑定大于1024的端口,那么rinetd就不需要以root账户来运行。这种小工具很值得放在 身边,以便随时调用TCP 端口间接寻址。

rinetd的官网:http://www.boutell.com/rinetd/
相关帖子:http://briteming.blogspot.com/2013/04/rinetdlinux.html
教程:http://www.2cto.com/os/201109/103165.html
教程(已验证):http://blog.sina.com.cn/s/blog_695d0b300101bdan.html
教程:http://www.myhack58.com/Article/sort099/sort0102/2013/37175.htm
-----------------
介绍 rinetdplus 之前,先介绍 rinetd。rinetd 是 Linux 下的端口映射工具,实现端口映射/转发/重定向。简单好用。

“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 是用 select 来实现 多路I/O机制。

rinetdplus 所要做的,是在 rinetd 基础上,用 epoll 来替代 select。它使用的是 redis 封装的 一个简单库 ae.

rinetdplus

rinetd + ae from redis
1 what is rinetd? see http://www.boutell.com/rinetd/
2 ae is "A simple event-driven programming library" from redis
3 what rinetdplus do ?
rinetd use function "select", rinetdplus replace it with "epoll" (ae).
from https://github.com/rogerwangzy/rinetdplus
-----

Rinetd-Onekey

Copy the command to your vps & execute it:

apt-get install -y curl && curl -O https://raw.githubusercontent.com/1715173329/rinetd-onekey/master/rinetd-go.sh && bash rinetd-go.sh
from https://github.com/shell-script/rinetd-onekey
-----

rinetd-nocheckovz


from https://github.com/wangzhe12588/rinetd-nocheckovz
----

rinetd 端口转发

发现 linux 下面有一个很方便的端口转发和反向代理的工具 rinetd

安装后配置文件默认放在 etc 的 rinetd.conf

1
2
vim /etc/rinetd.conf
0.0.0.0 8080 192.168.1.2 8080

上述配置就是把访问将所有发往本机 8080 端口的请求转发到 192.168.1.2 的 8080 端口
修改好之后重启软件就可以了。

1
2
3
4
5
6
关闭进程
pkill rinetd
启动软件
rinetd -c /etc/rinetd.conf
查看端口监听状态
netstat -antup
-----

相关帖子:
https://briteming.blogspot.com/2013/04/rinetdlinux.html
https://briteming.blogspot.com/2017/11/linhuarinetdopenvz-vpsbbr.html