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
相關文章
相關標籤/搜索