CentOS 6/7 安装配置 Rinetd 端口转发工具

前端之家收集整理的这篇文章主要介绍了CentOS 6/7 安装配置 Rinetd 端口转发工具前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS 6/7 安装配置 Rinetd 端口转发工具

安装

cat >> rinetd-installer.sh <<'EOF'
#!/bin/bash
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
EOF
chmod +x rinetd-installer.sh
./rinetd-installer.sh

配置

rm -f /etc/rinetd.conf
cat >> /etc/rinetd.conf <<EOF
# 设置允许访问的ip地址信息
allow 192.168.1.*

# 设置日志文件路径
# logfile /var/log/rinetd.log

# 例子: 将本机 8080 端口重定向至 www.aslibra.com 的 80 端口
# 0.0.0.0 8080 www.aslibra.com 80

# Docker Hub
0.0.0.0  5000  192.168.1.101  5000

# SSH
0.0.0.0  2201  192.168.1.101  22
0.0.0.0  2202  192.168.1.102  22
0.0.0.0  2203  192.168.1.103  22
0.0.0.0  2204  192.168.1.104  22
0.0.0.0  2205  192.168.1.105  22
0.0.0.0  2206  192.168.1.106  22
0.0.0.0  2207  192.168.1.107  22
0.0.0.0  2208  192.168.1.108  22

# MysqL
0.0.0.0  3301  192.168.1.101  3306
0.0.0.0  3302  192.168.1.102  3306
0.0.0.0  3303  192.168.1.103  3306
0.0.0.0  3304  192.168.1.104  3306

# Subversion
0.0.0.0  3690  192.168.1.101  3690
EOF

创建启动脚本

cat >> /etc/init.d/rinetd <<'EOF'
#!/bin/bash

EXEC=/usr/sbin/rinetd
CONF=/etc/rinetd.conf
PID_FILE=/var/run/rinetd.pid
NAME=Rinetd
DESC="Rinetd Server"

case "$1" in
    start)
        if [ -x "$PID_FILE" ]; then
            echo "$NAME is running ..."
            exit 0
        fi

        $EXEC -c $CONF

        echo -e "\e[1;32m$NAME is running\e[0m"
    ;;
    stop)
        if [ -f "$PID_FILE" ]; then
            kill `cat $PID_FILE`

            while [ -x "$PID_FILE" ]
            do
                echo "Waiting for $NAME to shutdown..."  
                sleep 1
            done

            rm -f $PID_FILE
        fi

        echo -e "\e[1;31m$NAME stopped.\e[0m"
    ;;
    restart)
        $0 stop
        $0 start
    ;;
    status)
        if [ -f $PID_FILE ]; then
            echo "$NAME is running ..."
        else
            echo "$NAME stopped."
        fi
    ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 2
    ;;
esac

exit 0
EOF

启动服务

/etc/init.d/rinetd start
原文链接:https://www.f2er.com/centos/375020.html

猜你在找的CentOS相关文章