shell一键安装rinetd端口转发工具
使用阿里云服务器搭建了2台服务器,但都没有外网ip,所以需要使用rinetd来转发ssh端口来进行访问.
系统:centos 7(64位)
软件:rinetd
cat /root/soft_shell/auto_install_rinetd.sh
#!/bin/bash # Author rocdk890 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:~/bin export PATH # Check if user is root if [ $(id -u) != "0" ]; then echo "Error: You must be root to run this script, please use root to install" exit 1 fi # Check the network status NET_NUM=`ping -c 4 www.baidu.com |awk '/packet loss/{print $6}' |sed -e 's/%//'` if [ -z "$NET_NUM" ] || [ $NET_NUM -ne 0 ];then echo "Please check your internet" exit 1 fi # Check the OS if [ "$(awk '{if ( $3 >= 7.0 ) print "CentOS 7.x"}' /etc/redhat-release 2>/dev/null)" != "CentOS 7.x" ];then err_echo "This script is used for RHEL/CentOS 7.x only." exit 1 fi yum -y install gcc gcc-c++ make if [ -s rinetd.tar.gz ];then echo "rinetd.tar.gz [found]" else wget https://download.slogra.com/rinetd/rinetd.tar.gz fi tar zxf rinetd.tar.gz -C /usr/local/ cd /usr/local/rinetd/ sed -i 's/65536/65535/g' rinetd.c mkdir /usr/man make && make install read -p "Enter the local port:" lport read -p "Enter the remote port:" rport read -p "Enter the remote ip:" ip rm -f /etc/rinetd.conf cat >> /etc/rinetd.conf <<EOF # 设置允许访问的ip地址信息 # allow 192.168.2.* # 设置拒绝访问的ip地址信息 # deny 192.168.1.* # 设置日志文件路径 logfile /var/log/rinetd.log # 例子: 将本机 8080 端口重定向至 192.168.10.100 的 8080 端口 # 0.0.0.0 8080 192.168.10.100 8080 0.0.0.0 $lport $ip $rport EOF cat > /usr/lib/systemd/system/rinetd.service <<EOF [Unit] Description=rinetd After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/run/rinetd.pid ExecStart=/usr/sbin/rinetd -c /etc/rinetd.conf ExecStop=/bin/kill -s HUP $MAINPID [Install] WantedBy=multi-user.target EOF
最后记得在防火墙里打开你设置绑定在本机的端口.
评论: