本文共 2785 字,大约阅读时间需要 9 分钟。
#!/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 1fisleep 1if [ -c "/dev/net/tun" ];then echo "Info: Device is ready"else echo -e "\033[31mDevice is not available\033[0m" exit 1fisleep 1check_rpm pppif [ $? -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 fielse 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 fificheck_rpm pptpdif [ $? -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 fifiecho "Info: initialize successfully"sleep 1wanip_1=`ifconfig eth0 |grep 'inet addr' |awk '{print $2}' |awk -F ":" '{print $2}'`read -p "Please input your WAN IP[${wanip_1}]:" wanip_2read -p "Please input your username[***]:" usernameread -p "Please input your password[password]" passwordmv /etc/ppp/options.pptpd /etc/ppp/options.pptpd.bakcat > /etc/ppp/options.pptpd << EOFname pptpdrefuse-paprefuse-chaprefuse-mschaprequire-mschap-v2require-mppe-128proxyarplocknobsdcompnovjnovjccompnologfdidle 2592000ms-dns 8.8.8.8ms-dns 8.8.4.4EOFsleep 1cp /etc/ppp/chap-secrets /etc/ppp/chap-secrets.bakecho "${username:=***} pptpd ${password:=password} * " > /etc/ppp/chap-secretscp /etc/pptpd.conf /etc/pptpd.conf.bakcat > /etc/pptpd.conf << EOFoption /etc/ppp/options.pptpdlogwtmplocalip 192.168.1.1remoteip 192.168.1.11-30EOFsed -i 's/net\.ipv4\.ip\_forward\ =\ 0/net\.ipv4\.ip\_forward\ =\ 1/g' /etc/sysctl.conf sysctl -p 2>&1 > /dev/nulliptables -I INPUT -p tcp --dport 1723 -j ACCEPTiptables -t nat -A POSTROUTING -o eth0 -s 192.168.1.0/24 -j SNAT --to-source ${wanip_2:=${wanip_1}} 2>&1 > /dev/nullif [ $? -eq 0 ];then echo "Info: Looks great!"else echo -e "\033[31mSorry! You make a mistake\033[0m" exit 1fiservice iptables save > /dev/nullchkconfig pptpd onservice pptpd start
转载于:https://blog.51cto.com/lyondong/1750958