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

一、源码安装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 #编译过程中需要/usr/man/man8目录

编译配置文件:/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 192.168.117.131 8080
0.0.0.0 443 192.168.117.131 8080
0.0.0.0 3001 192.168.117.131 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
© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏
分享
评论 抢沙发