#!/bin/bash echo "#########################################################" echo " ××× 安裝 修復 添加 轉發 " echo " BY:VER007 " echo " OS = Centos 6 32 " echo "#########################################################" function install×××(){ echo "開始安裝×××服務"; #check wether vps suppot ppp and tun yum remove -y pptpd ppp iptables --flush POSTROUTING --table nat iptables --flush FORWARD rm -rf /etc/pptpd.conf rm -rf /etc/ppp arch=`uname -m` wget http://www.hi-vps.com/downloads/dkms-2.0.17.5-1.noarch.rpm wget http://wty.name/linux/sources/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm wget http://www.hi-vps.com/downloads/kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm wget http://www.hi-vps.com/downloads/pptpd-1.3.4-2.el6.$arch.rpm wget http://www.hi-vps.com/downloads/ppp-2.4.5-17.0.rhel6.$arch.rpm yum -y install make libpcap iptables gcc-c++ logrotate tar cpio perl pam tcp_wrappers rpm -ivh dkms-2.0.17.5-1.noarch.rpm rpm -ivh kernel_ppp_mppe-1.0.2-3dkms.noarch.rpm rpm -qa kernel_ppp_mppe rpm -Uvh ppp-2.4.5-17.0.rhel6.$arch.rpm rpm -ivh pptpd-1.3.4-2.el6.$arch.rpm rm /dev/ppp mknod /dev/ppp c 108 0 echo 1 > /proc/sys/net/ipv4/ip_forward echo "mknod /dev/ppp c 108 0" >> /etc/rc.local echo "echo 1 > /proc/sys/net/ipv4/ip_forward" >> /etc/rc.local echo "localip 192.168.9.1" >> /etc/pptpd.conf echo "remoteip 192.168.9.2-254" >> /etc/pptpd.conf mkdir /etc/ppp/ chmod +x /etc/ppp/ echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd echo "ms-dns 8.8.4.4" >> /etc/ppp/options.pptpd #pass=`openssl rand 6 -base64` #if [ "$1" != "" ] #then pass=$1 #fi echo -n "請輸入要設置的帳號:" read username echo -n "請輸入要設置的密碼:" read password echo "${username} pptpd ${password} *" >> /etc/ppp/chap-secrets iptables -t nat -A POSTROUTING -s 192.168.9.0/255.255.255.0 -j SNAT --to-source `ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}'` service iptables save chkconfig iptables on chkconfig pptpd on service iptables start service pptpd start echo "裝×××服務,您的用戶名是${username},密碼 ${password}" echo "安裝完成 請重啓服務器!" } function repaire×××(){ echo "開始修復×××..."; mknod /dev/ppp c 108 0 service iptables restart service pptpd start echo "修復結束" exit } function porttoport(){ echo "" echo "----端口轉發設置----" echo "" echo "請輸入內網IP:" read neiwangip echo "請輸入外網IP(留空爲自動獲取):" read waiwangip if [ -z ${neiwangip} ] ;then waiwangip=$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk 'NR==1 { print $1}') fi echo "請輸入要轉發的端口:" read port if [ -z ${port} ] ;then echo "ERROR:沒有提供可用端口,將退出設置" exit else if [ -z ${neiwangip} ] ;then echo "ERROR: 沒有提供內網的IP,將退出設置" exit else if [ -z ${waiwangip} ] ;then echo "ERROR:未設置外網IP 將退出設置" exit else echo 外網IP是"${waiwangip}" 內網IP是"${neiwangip}" 轉發端口是"${port}" iptables -t nat -A PREROUTING -d ${waiwangip} -p tcp -m tcp --dport ${port} -j DNAT --to-destination ${neiwangip}:${port} iptables -t nat -A POSTROUTING -s 192.168.9.0/24 -d ${neiwangip} -p tcp -m tcp --dport ${port} -j SNAT --to-source 192.168.9.1 echo 轉發外網" ${waiwangip}":"${port} "端口\-\>內網" ${neiwangip}":"${port} " echo "是否保存轉發記錄 或者 臨時轉發(N)(Y/N)?" read ok if [[${ok}="Y"]]||[[${ok}="y"]] ;then service iptables save service iptables restart fi exit fi fi fi } function add×××user(){ echo "" echo "----新建帳號設置----" echo "" echo "請輸入帳號:" read username echo "請輸入密碼:" read userpassword echo "${username} pptpd ${userpassword} *" >> /etc/ppp/chap-secrets service iptables restart service pptpd start } function exiter(){ exit } echo "請輸入服務編號." echo "1. 安裝 ××× 服務" echo "2. 修復 ××× 服務" echo "3. 新建 ××× 帳號" echo "4. 內網端口轉發設置" echo "5. 退出安裝或設置" read num case "$num" in [1] ) (install×××);; [2] ) (repaire×××);; [3] ) (add×××user);; [4] ) (porttoport);; [5] ) (exiter);; *) echo "取消退出";; esac