#!/bin/bash # function check_rpm() { rpm -q $1 2>&1 > /dev/null } modprobe ppp-compress-18 if [ $? -eq 0 ];then echo "Info: Module is loaded successfully" else echo -e "\033[31mFailed to load the module\033[0m" exit 1 fi sleep 1 if [ -c "/dev/net/tun" ];then echo "Info: Device is ready" else echo -e "\033[31mDevice is not available\033[0m" exit 1 fi sleep 1 check_rpm ppp if [ $? -eq 0 ];then result=`strings '/usr/sbin/pppd' | grep -i mppe | wc --lines` if [[ $result -ge 30 ]];then echo "Info: PPP is working" else echo -e "\033[31mPPP is not available\033[0m" exit 1 fi else yum install -y ppp 2>&1 > /dev/nulll if [ $? -eq 0 ];then echo "Info: PPP has been installed" else echo -e "\033[31mPPP install failed\033[0m" exit 1 fi fi check_rpm pptpd if [ $? -eq 0 ];then echo "Info: pptpd is working" else echo "Info: pptpd installing" curl -O ftp://rpmfind.net/linux/sourceforge/q/qi/qiaodahai/PPTP-×××-For-CentOS/pptpd-1.3.4-2.el6.x86_64.rpm 2>&1 > /dev/null if [ $? -eq 0 ];then rpm -ih pptpd-1.3.4-2.el6.x86_64.rpm 2>&1 > /dev/null && rm -f pptpd-1.3.4-2.el6.x86_64.rpm if [ $? -eq 0 ];then echo "Info: pptpd has been installed" sleep 1 else echo -e "\033[31mpptpd install failed\033[0m" exit 1 fi else echo -e "\033[31mpptpd download failed\033[0m" exit 1 fi fi echo "Info: initialize successfully" sleep 1 wanip_1=`ifconfig eth0 |grep 'inet addr' |awk '{print $2}' |awk -F ":" '{print $2}'` read -p "Please input your WAN IP[${wanip_1}]:" wanip_2 read -p "Please input your username[***]:" username read -p "Please input your password[password]" password mv /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bak cat > /etc/ppp/options.pptpd << EOF name pptpd refuse-pap refuse-chap refuse-mschap require-mschap-v2 require-mppe-128 proxyarp lock nobsdcomp novj novjccomp nologfd idle 2592000 ms-dns 8.8.8.8 ms-dns 8.8.4.4 EOF sleep 1 cp /etc/ppp/chap-secrets /etc/ppp/chap-secrets.bak echo "${username:=***} pptpd ${password:=password} * " > /etc/ppp/chap-secrets cp /etc/pptpd.conf /etc/pptpd.conf.bak cat > /etc/pptpd.conf << EOF option /etc/ppp/options.pptpd logwtmp localip 192.168.1.1 remoteip 192.168.1.11-30 EOF sed -i 's/net\.ipv4\.ip\_forward\ =\ 0/net\.ipv4\.ip\_forward\ =\ 1/g' /etc/sysctl.conf sysctl -p 2>&1 > /dev/null iptables -I INPUT -p tcp --dport 1723 -j ACCEPT iptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j SNAT --to-source ${wanip_2:=${wanip_1}} 2>&1 > /dev/null if [ $? -eq 0 ];then echo "Info: Looks great!" else echo -e "\033[31mSorry! You make a mistake\033[0m" exit 1 fi service iptables save > /dev/null chkconfig pptpd on service pptpd start
转载于:https://blog.51cto.com/lyondong/1750958