Linux端口转发-rinted工具部署、配置、使用

编者按:

 

    近期由于公司开启定制项目规划,对于每个项目都会开启一个测试服务器,实施方会用到测试服务器的ssh端口、mysql端口、web端口,为了节省资源(公网IP、服务器资源复用),基于rinted工具搭建一个端口转发的服务器。下面的流程图将更好的表达本文即将实现的功能!

rinted端口转发示意图.jpg

 

1、源码安装rinted:

    下载和解压源码包:

cd /usr/local/src && wget https://boutell.com/rinetd/http/rinetd.tar.gz && tar xf rinetd.tar.gz && cd rinetd
 

    修改编译配置:

sed -i 's/65536/65535/g' rinetd.c# 修改端口范围,否则会报错
 

    编译安装:

mkdir -p /usr/man/man8 && make && make install
 

    编辑配置文件:/etc/rinetd.conf

#自定义mysql端口:3001/3100
#自定义ssh端口:2001/2500
#自定义web端口:801/899
#端口转发:[Source Address] [Source Port] [Destination Address] [Destination Port]
0.0.0.0 8080 10.124.162.114 8080
0.0.0.0 443 10.124.162.114 8080
0.0.0.0 3001 10.124.162.114 33080
#端口映射: bindaddress bindport connectaddress connectport

logfile /var/log/rinetd.log
 

    启动与关闭:

#启动
/usr/sbin/rinetd -c /etc/rinetd.conf 
#关闭
pkill rinetd
 

   启动脚本:/home/shell/rinetd  使用方法:sh /home/shell/rinetd start|stop|restart|reload

#!/bin/bash
#
# Startup script for Rinetd - this script starts and stops the rinetd daemon
#
# chkconfig: - 85 15
# description: Rinetd is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: rinetd
# config: /etc/rinetd.conf
# pidfile: /var/lock/subsys/rinetd
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
rinetd="/usr/sbin/rinetd"
prog=$(basename $rinetd)
 
RINETD_CONF_FILE="/etc/rinetd.conf"
 
#[ -f /etc/sysconfig/rinetd ] && . /etc/sysconfig/rinetd
 
lockfile=/var/lock/subsys/rinetd
 
start() {
    [ -x $rinetd ] || exit 5
    [ -f $RINETD_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $rinetd -c $RINETD_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    #killproc $rinetd -HUP
    daemon pkill $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    stop
    sleep 1
    start
}
 
reload() {
    echo -n $"Reloading $prog: "
    killproc $rinetd -HUP
    RETVAL=$?
    echo
}
 
rh_status() {
    status $prog
}
rh_status_q() {
    rh_status >/dev/null 2>&1
}
 
case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    status)
        rh_status
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|reload}"
        exit 2
esac

 

 

posted on 2018-11-06 20:02 cn三少<script></script> 阅读(...) 评论(...) 编辑 收藏

导航

公告