不多解释,我的第一个bash脚本----Centos6.3下安装VPN(pptpd)服务器,看上去还是很笨的脚本,欢迎各位大侠进行有必要的指点。关于上一篇pptpd配置博文这里不再赘述,把代码粘贴出来晒干点~~~
进过多次测试,可以很正常运行vpn服务。如图所示:#!/bin/bashfunction installVPN(){yum remove -y pptpd pppiptables --flush POSTROUTING --table natiptables --flush FORWARDrm -rf /etc/pptpd.confrm -rf /etc/ppp*yum install -y ppp iptablesecho 1 > /proc/sys/net/ipv4/ip_forwardcd /tmpwget http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.3.4-2.el6.x86_64.rpmrpm -ivh pptpd-1.3.4-2.el6.x86_64.rpmcat >/etc/ppp/options.pptpd<<ENDname pptpdrefuse-paprefuse-chaprefuse-mschaprequire-mschap-v2require-mppe-128ms-dns 8.8.8.8ms-dns 8.8.4.4proxyarplocknobsdcompnovjnovjccompnologfdENDcat >/etc/pptpd.conf<<ENDoption /etc/ppp/options.pptpdlogwtmplocalip 10.10.10.1remoteip 10.10.10.205-254ENDiptables -t nat -A POSTROUTING -s 10.10.10/8 -o eth0 -j SNAT --to-source `ifconfig | grep 'inet addr:'| grep -v '127.0.0' | cut -d: -f2 | awk 'NR==2 { print $1}'`iptables -A FORWARD -s `ifconfig | grep 'inet addr:'| grep -v '127.0.0' | cut -d: -f2 | awk 'NR==2 { print $1}'`/32 -o eth0 -j ACCEPTservice pptpd startchkconfig --level pptpd 2345 onchkconfig pptpd onservice iptables savechkconfig iptables onservice iptables start}function addVPNuser(){echo "input user name:"read usernameecho "input password:"read userpasswordecho "${username} pptpd ${userpassword} *" >> /etc/ppp/chap-secretsservice pptpd restart-killservice pptpd startservice iptables restart}echo "which do you want to ? input the number."echo "1. install VPN service"echo "2. add VPN user"read numcase "$num" in[1] ) (installVPN);;[2] ) (addVPNuser);;*) echo "nothing,exit";;esacbash echo "Your VPN server configuration is complete,The default user password vpnuser as test123 Please run the script again to add custom user"