【rinetd】CentOS7.x上轻量级TCP转发工具rinetd的安装配置

https://www.jianshu.com/p/2605d247b944

这一个写的更加全面了. 
2019.07.08 22:04:38字数 1271阅读 219

一、实验背景

Linux下端口转发一般都使用iptables来实现,使用iptables可以很容易将TCP和UDP端口从防火墙转发到内部主机上。

如果需要将流量从专用地址转发到不在您当前网络上的机器上,可尝试另一个应用层端口转发程序rinetd,配置起来比iptables也简单很多。

Rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具。Rinetd是单一过程的服务器,它处理任何数量的连接到在配置文件etc/rinetd中指定的地址/端口对,尽管rinetd使用非闭锁I/O运行作为一个单一过程,它可能重定向很多连接而不对这台机器增加额外的负担。

虽然这些代码有点古老,版本很多年没有更新了,但很短小、高效,对于解决这种问题来说是非常完美的。

二、实验环境

操作系统: CentOS7.5 Minimal

rinted服务器: 192.168.1.103

Backend服务器: 192.168.1.107

三、安装rinetd

安装rinted方式主要有两种:rpm包安装和源码编译安装

rpm安装方式

网上有人用源码包编译了rpm安装包,联网的情况下我们可以直接配置yum源安装,离线的情况下我们可以将下载的rpm包拷贝到无网的服务器,因为主包没有依赖,安装显得异常简单方便。

配置yum仓库安装

#  vim /etc/yum.repos.d/nux-misc.repo

####################################################

[nux-misc]

name=Nux Misc

baseurl=http://li.nux.ro/download/nux/misc/el7/x86_64/

enabled=0

gpgcheck=1

gpgkey=http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

#######################################################

 

# yum  -y install  rinetd  --disablerepo="*"  --enablerepo=nux-misc

 

# wget  http://li.nux.ro/download/nux/misc/el7/x86_64//rinetd-0.62-9.el7.nux.x86_64.rpm

# rpm  -ivh  rinetd-0.62-9.el7.nux.x86_64.rpm

 
 
 

# rpm -ql  rinetd

# cat  /etc/rc.d/init.d/rinetd

# cat /etc/rinetd.conf

# /usr/sbin/rinetd  --help

#  /usr/sbin/rinetd  -v

 
 

# systemctl  status rinetd

 

源码编译安装

#  yum  -y install  gcc make

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

# cd rinetd

#  mkdir -p /usr/man/man8

# make && make install

 

# which rinetd

# /usr/sbin/rinetd --help

# /usr/sbin/rinetd -v

 

# man rinetd

# man rinetd  > rinetd.txt

 

四、将源码编译安装注册成系统服务

# mkdir /usr/local/rinetd

# mkdir /usr/local/rinetd/sbin

# mkdir /usr/local/rinetd/etc/

# mkdir /usr/local/rinetd/log

# mv  /usr/sbin/rinetd  /usr/local/rinetd/sbin

#  vim  mkdir /usr/local/rinetd/etc/rinetd.conf

#############################################################

# example configuration file for rinetd

# to forward connections to port 80 on 10.10.10.2 to port 80 on 192.168.0.2

#  10.10.10.2 80 192.168.0.2 80

# to forward connections to port 80 on all addresses to port 80 on 192.168.0.2

# 0.0.0.0 80 192.168.0.2 80

# access controls can be set with allow and deny rules

# allow and deny before the first forwarding rule are global

# allow and deny after a specific rule apply to it only

# this rule allows hosts from 172.16.32.0/24 netblock

# allow 172.16.32.*

# this rule denies the host 192.168.32.12

# deny 192.168.32.12

# rinetd supports logging - to enable, uncomment the following

# logfile /var/log/rinetd.log

# by default, logs are in a tab-delimited format. Web common-log format

# is available by uncommenting the following

# logcommon

#############################################################

 

编写Unit文件

#  vim  /etc/systemd/system/rinetd.service

##########################################################

[Unit]

Description=Rinetd Daemon

After=network.service

Wants=network.service

[Service]

Type=forking

PIDFile=/var/run/rinetd.pid

ExecStart=/usr/local/rinetd/sbin/rinetd -c /usr/local/rinetd/etc/rinetd.conf

Restart=on-failure

[Install]

WantedBy=multi-user.target

###############################################################

 

#  systemctl  daemon-reload

# systemctl  start    rinetd.service

# systemctl  enable  rinetd.service

# systemctl  status  rinetd.service

 

rinetd  用于网络端口转发,运行用户只能是root

五、关于rinetd 的配置文件的配置

rpm安装的配置文件默认路径是/etc/rinetd.conf,本实验中我们将编译安装的配置文件  /usr/local/rinetd/etc/rinetd.conf

 

注意:源端口转发到目标端口时,源端口要是空闲端口,否则会报端口已被占用

关于配置文件的更多其他配置,见参考文档

六、端口转发测试

实验:将rinted服务器(192.168.1.103)的6033端口转到Backend服务器(192.168.1.107)的3306

在Backend服务器(192.168.1.107)

# systemctl  status mysqld

# ss  -tan | grep 3306

 

# firewall-cmd --zone=public--add-port=3306/tcp --permanent

# firewall-cmd --reload

在rinted服务器(192.168.1.103)

# firewall-cmd --zone=public--add-port=6033/tcp --permanent

# firewall-cmd --reload

# vim  /usr/local/rinetd/etc/rinetd.conf

#############################################

192.168.1.103 6033  192.168.1.107 3306

allow 192.168.1.*

logfile /usr/local/rinetd/log/rinetd.log

#############################################

# systemctl  restart  rinetd.service

# systemctl  status  rinetd.service

 

# echo  >  /dev/tcp/192.168.1.103/6033

# echo  >  /dev/tcp/192.168.1.107/3306

 
 

# tail  /usr/local/rinetd/log/rinetd.log

 

七、参考

Linux下使用 Rinetd 来实现端口转发

https://www.hi-linux.com/posts/29683.html

RINETD(8) Unix System Manager's Manual

https://www.boutell.com/rinetd

生产环境中谨慎使用rinetd

https://blog.csdn.net/woshiaotian/article/details/78133195

Linux安装rinetd实现TCP端口转发

https://www.xiaoz.me/archives/10175

rinetd-0.62-9.el7.nux.x86_64.rpm

https://centos.pkgs.org/7/nux-misc-x86_64/rinetd-0.62-9.el7.nux.x86_64.rpm.html

Port-Forwarding With rinetd

https://www.howtoforge.com/port-forwarding-with-rinetd-on-debian-etch

Comprehensive Guide to Port Redirection using Rinetd

https://www.hackingarticles.in/comprehensive-guide-to-port-redirection-using-rinetd

[转帖]【rinetd】CentOS7.x上轻量级TCP转发工具rinetd的安装配置的更多相关文章

  1. CentOS7.x上轻量级TCP转发工具rinetd的安装配置

    一.实验背景 Linux下端口转发一般都使用iptables来实现,使用iptables可以很容易将TCP和UDP端口从防火墙转发到内部主机上. 如果需要将流量从专用地址转发到不在您当前网络上的机器上 ...

  2. 全平台正向tcp端口转发工具rinetd的使用

    Linux下做地址NAT有很多种方法.比如haproxy.nginx的4层代理,linux自带的iptables等都能实现.其实,Linux下有一个叫rinetd的工具,安装简单,配置也不复杂. 下载 ...

  3. 代理端口转发工具rinetd

    转载: https://my.oschina.net/wuweixiang/blog/2983280 rinetd 前言 iptables 的功能当然强大,但理解与设置却有点抽象,便通过google认 ...

  4. 端口转发工具rinetd的安装与配置

    端口映射和转发在实际应用中非常常见,比如一个局域网只有一台服务器可以被互联网访问到,那么如果想通过互联网访问局域网中其他的服务,最常用的方式就是在这一台机器上开放端口,然后转发至局域网中其他主机的端口 ...

  5. linux下简单好用的端口映射转发工具rinetd 转

    linux下简单好用的工具rinetd,实现端口映射/转发/重定向 官网地址http://www.boutell.com/rinetd 软件下载 wget http://www.boutell.com ...

  6. linux下简单好用的端口映射转发工具rinetd

    linux下简单好用的工具rinetd,实现端口映射/转发/重定向官网地址http://www.boutell.com/rinetd 软件下载wget http://www.boutell.com/r ...

  7. rinetd 一个linux下的端口转发工具

    inux下使用iptables实现端口转发,配置较为复杂,使用rinetd工具可以实现快速配置和修改端口转发. 例:本机ip:1.1.1.1 需要实现访问本机的8080端口,自动转发到2.2.2.2 ...

  8. Linux端口转发工具rinetd

    介绍:Rinetd是为在一个Unix和Linux操作系统中为重定向传输控制协议(TCP)连接的一个工具.Rinetd是单一过程的服务器,它处理任何数量的连接到在配置文件etc/rinetd中指定的地址 ...

  9. windows上SVN服务器以及客户端TortoiseSVN的安装配置

    (1)svn的安装 1. 下载软件:Setup-Subversion-1.7.5.msi,安装就很容易了,一路NEXT 2. 把SVN的bin文件夹路径添加到环境变量中 把svn安装目录下的bin路径 ...

随机推荐

  1. Django2.0版本以上与pymsql 不匹配问题以及解决方法

    Django2.0版本以上与pymsql 不匹配问题以及解决方法 Django 2.0 以上 如果使用pymysql0.93,需要一下两步操作: # 1 第一次报错信息: File "D:\ ...

  2. RabbitMQ如何实现高可用

    RabbitMQ一共具有三种模式:单机.普通集群.镜像集群 单机模式 单机模式,就是我们平常玩的demo,生产上肯定不能用.具体安装部署过程可以参考我的这篇文章:CentsOS原生RabbitMQ安装 ...

  3. CRM产品主数据在行业解决方案industry solution中的应用

    AG3, choose this role: Create a new Acquisition Contracts: Here our product advances search will be ...

  4. Spring面试专题之aop

    1.背景 aop是编程中非常非常重要的一种思想,在spring项目中用的场景也非常广 2.面试问题 2.1.简单的面试问题 1.什么是aop,aop的作用是什么? 面向切面编程(AOP)提供另外一种角 ...

  5. 如果再聘请一位会css的美工,那要你还有什么用?

    老板正为网站不好看而烦恼. 会议结束后. 我对我的前辈说:要是能找个会css美工就好了! 前辈说:如果再聘请一位会css的美工,那要你还有什么用? 我一时语塞. 后来回答:我可以专心后端代码,可以写 ...

  6. Ubuntu拒绝root用户ssh远程登录

    sudo vim /etc/ssh/sshd_config 找到并用#注释掉这行:PermitRootLogin prohibit-password 新建一行 添加:PermitRootLogin y ...

  7. 使用acme.sh申请&自动续期LetsEncrypt免费SSL证书(转)

    一.简介 LetsEncrypt是一个免费.自动.开放的证书颁发机构.acme.sh 实现了 acme 协议, 可以从 LetsEncrypt 生成免费的证书. 本文介绍如何使用acme.sh来签发并 ...

  8. C#进阶系列 ---- 《CLR via C#》

      [C#进阶系列]30 学习总结 [C#进阶系列]29 混合线程同步构造 [C#进阶系列]28 基元线程同步构造 [C#进阶系列]27 I/O限制的异步操作 [C#进阶系列]26 计算限制的异步操作 ...

  9. MySQL小测试

    <> 2.创建一个字符集为utf8的数据库,将数据库字符集修改为gbk create database db1 charset='utf8'; alter database db1 cha ...

  10. wordpress怎么用AMP加速器呢

    AMP项目(Accelerated Mobile Pages)是一个开放源代码计划,旨在为所有人打造更好的网络体验.借助该项目,用户可以打造出在各种设备和分发平台上都能始终如一地快速加载且效果出色的精 ...