linux通过rinetd工具进行端口映射/转发/重定向

  • 发布时间:2018-01-19 来源:网络 上传者:用户

    关键字: 映射 定向 端口 转发 通过 进行 工具 rinetd Linux

    发表文章
  • 摘要:现在线上有个需求,访问某源的地址,需要通过一个固定的出口出去才行。那么这里想到的转发的几种方式:1.iptables对端口做转发,这种需要开启内核转发。配置几条iptables规则就好。2.rinetd对端口做转发,转发规则类似于反响代理,或者nat而且配置比较简单。配置出错也不会导致网络访问问题。下面就来介绍rinetd的端口转发参考官网地址:https://www.boutell.com/rinetd/下面直接是上干货#tar-zxvfrinetd.tar.gz-C/us
  •  

    现在线上有个需求,访问某源的地址,需要通过一个固定的出口出去才行。那么这里想到的转发的几种方式:1.iptables对端口做转发,这种需要开启内核转发。配置几条iptables规则就好。2.rinetd对端口做转发,转发规则类似于反响代理,或者nat 而且配置比较简单。配置出错也不会导致网络访问问题。下面就来介绍rinetd的端口转发参考官网地址: https://www.boutell.com/rinetd/下面直接是上干货

    #tar-zxvfrinetd.tar.gz  /usr/local 
    #cdrinetd 
    aliyunzixun@xxx.com]#make 
    cc-DLINUX-g-c-orinetd.orinetd.c 
    rinetd.c:176:warning:conflictingtypesforbuilt-infunction‘log’ 
    cc-DLINUX-g-c-omatch.omatch.c 
    gccrinetd.omatch.o-orinetd 
    aliyunzixun@xxx.com]#make install 
    install-m700rinetd/usr/sbin 
    install-m644rinetd.8/usr/man/man8 
    install:cannotcreateregularfile`/usr/man/man8':Nosuchfileordirectory 
    make:***[install]Error1 
    aliyunzixun@xxx.com]#mkdir -p /usr/man/ 
    aliyunzixun@xxx.com]#make clean 
    aliyunzixun@xxx.com]#make 
    cc-DLINUX-g-c-orinetd.orinetd.c 
    rinetd.c:176:warning:conflictingtypesforbuilt-infunction‘log’ 
    cc-DLINUX-g-c-omatch.omatch.c 
    gccrinetd.omatch.o-orinetd 
    aliyunzixun@xxx.com]#make install 
    install-m700rinetd/usr/sbin 
    install-m644rinetd.8/usr/man/man8 
    aliyunzixun@xxx.com]# 
    #成功后会提示文件路径 
    install-m700rinetd/usr/sbin 
    install-m644rinetd.8/usr/man/man8

    程序路径/usr/sbin/rinetd建立配置文件/etc/rinetd.conf,内容格式:源IP 源端口 要跳转的IP 要跳转的端口;在每一单独的行中指定每个要转发的端口。源地址和目的地址都可以是主机名或IP 地址,IP 地址0.0.0.0 将rinetd 绑定到任何可用的本地IP地址上:例如将所有发往本机81端口的请求转发到某地址的80端口

    aliyunzixun@xxx.com]#vim /etc/rinetd.conf 
    allow*.*.*.*//设置允许访问的ip地址信息 
    0.0.0.081目标IP80//设置端口转发 
    logfile/var/log/rinetd.log//设置打印的log 

    #启动程序并将rinetd加入开机启动 

    aliyunzixun@xxx.com]#/usr/sbin/rinetd 
    或者 
    aliyunzixun@xxx.com]#rinetd- c /etc/rinetd.conf 
    aliyunzixun@xxx.com]#netstat-antulp|grep-irinetd 
    tcp000.0.0.0:810.0.0.0:*LISTEN5849/rinetd 
    aliyunzixun@xxx.com]#killall-9rinetd或者pkill-9rinetd 
    aliyunzixun@xxx.com]#netstat-antulp|grep-irinetd 
    aliyunzixun@xxx.com]#rinetd 
    aliyunzixun@xxx.com]#netstat-antulp|grep-irinetd 
    tcp000.0.0.0:810.0.0.0:* 
    LISTEN5861/rinetd 

    启动程序 
    pkillrinetd##关闭进程 
    rinetd-c/etc/rinetd.conf##启动转发 
    把这条命令加到/etc/rc.local里面就可以开机自动运行 

    查看状态 
    netstat-antup 

    需要注意 
    1.rinetd.conf中绑定的本机端口必须没有被其它程序占用 
    2.运行rinetd的系统防火墙应该打开绑定的本机端口 
    例如: 
    -ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport1111-jACCEPT 
    -ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport2222-jACCEPT

    #至此就可以进行访问测试了!所有访问本机81端口的请求,都会转发到 目标IP 的 80端口

  • 以上是linux通过rinetd工具进行端口映射/转发/重定向的内容,更多 映射 定向 端口 转发 通过 进行 工具 rinetd Linux 的内容,请您使用右上方搜索功能获取相关信息。

 

----------------------------------------------------------------------------------------------

http://www.boutell.com/rinetd/http/rinetd.tar.gz

第一步
—————下载 rinetd  并解压安装——————————————
wget http://www.boutell.com/rinetd/http/rinetd.tar.gz

tar -zxvf rinetd.tar.gz

cd rinetd

make

make install
———————————————————————————————
PS: 遇到问题
1. make install 时报错。
install: 无法创建一般文件“/usr/man/man8”: 没有那个文件或目录
解决: makdir 就行了
makdir /usr/man/ ;
makdir /usr/man/man8 ;
————————————————————————————————



第二步
———————————配置 rinetd —————————————————————————
vi /etc/rinetd.conf

"——VI 内容——"

0.0.0.0 2228 ssh.nbvp.info 22

"——VI 内容——"
————————————————————————————————————————
PS:
0.0.0.0 2228 ssh.nbvp.info 22
将所有发往本机2228端口的请求转发到ssh.nbvp.info的22端口
命令格式是
bindaddress   bindport    connectaddress    connectport
绑定的地址      绑定的端口         连接的地址         连接的端口

[Source Address] [Source Port] [Destination Address] [Destination Port]
源地址                            源端口                目的地址                  目的端口
——————————————————————————————————————————————



第3步
—————配置iptables———————————————————————————————————
在 iptables 里面 追加 一条规则

vi /etc/sysconfg/iptables

"——VI 内容——"
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 2228 -j ACCEPT
"——VI 内容——"

重启IPTABLES
service iptables restart
————————————————————————————————————————————————
PS:注意是 追加 不是 直接 只剩一条规则。
而且 注意 这条 规则 要在 这种 屏蔽端口规则 之前
“-A RH-Firewall-1-INPUT -p gre -j ACCEPT”
否则会无效的。
一般你可以先 telnet 你服务ip 要连接端口
看一下你的iptables 规则是否 有效。如果连接 拒绝 ,那说明无效。
————————————————————————————————————————————————

最后 一步 启动 rinetd 服务。
————————————————————————————————————————————————
rinetd -c /etc/rinetd.conf
这个时候 rinetd 只会有错报错,成功 是 没有 提示的。
所以假如没有出现问题那就是启动并转发成功了的。
假如你不放心你可以 再次 rinetd -c /etc/rinetd.conf
如果 出现 rinetd: couldn't bind to address 0.0.0.0 port 2228
那说明已经转发成功了。
最后的 PS:----------------------------------------------------------------------------------------
1.rinetd.conf中绑定的本机端口必须没有被其它程序占用
2.运行rinetd的系统防火墙应该打开绑定的本机端口
3.把 “rinetd -c /etc/rinetd.conf” 加到/etc/rc.local里面就可以开机自动运行

pkill rinetd  ##关闭进程
rinetd -c /etc/rinetd.conf  ##启动转发

谢谢大家。感谢 粗音妹子和圈圈 。 转载记得出处。
可参考资料无数。
http://lvinie.iteye.com/blog/1167701
GG,百度,去吧。
这是官网:http://www.boutell.com/rinetd/

也可其他配置文件
 

运行方式:

新建配置文件:vim /etc/rinetd.conf

这里是定制转发的规则。

格式是:源IP 源端口 目标IP 目标端口

我的配置是:

192.168.0.189 21 123.123.123.123 21

allow *.*.*.*

logfile /var/log/rinetd.log

 

http://www.iwangyu.com/index.php/archives/573

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值