需要输入你网卡名字,本地ip,和pptpd拨号客户端使用的IP
================================服务器=================
作者:木子贤
QQ:2574271652
转载请保留出处--------------------
请支持老男孩培训
#!/bin/sh
. /etc/init.d/functions
read -p "input your intarfacename(ex:eth0):" d
while true
do
read -p "please input your vpnlocalip:" a
read -p "please input your vpnclient_ip_rang (ex 10.0.0.3-8):" b
read -p "please input your network(ex 10.0.0.0/24):" e
read -p "your input message confirm? y/n:" c
if [ "$c" = "y" ];then
break
fi
done
echo "初始化服务器环境"
sleep 2
if [ `modprobe ppp-compress-18 && echo 1` -ne 1 ]
then
echo ‘your server no support pptpd!‘
exit 1
fi
echo "更新国内yum"
sleep 1
if [ ! -f /var/vpn_flag ];then
/usr/bin/yum -y install wget
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
/usr/bin/yum clean all
/usr/bin/yum makecache
/usr/bin/yum update -y
/usr/bin/yum groupinstall base -y
touch /var/vpn_flag
fi
/usr/bin/hostnamectl set-hostname vpnserver
/usr/bin/hostname vpnserver
echo ‘start install vpn‘
/usr/bin/yum -y install ppp pptpd iptables
if [ `/usr/bin/grep "net.ipv4.ip_forward = 1" /etc/sysctl.conf|wc -l` -eq 0 ];then
echo "net.ipv4.ip_forward = 1">>/etc/sysctl.conf
/usr/sbin/sysctl -p
fi
sed -i ‘[email protected]#ppp /usr/sbin/[email protected] /usr/sbin/[email protected]‘ /etc/pptpd.conf
if [ `/usr/bin/grep "$a" /etc/pptpd.conf|wc -l` -ne 1 ];then
echo "localip $a">>/etc/pptpd.conf
fi
if [ `/usr/bin/grep "$b" /etc/pptpd.conf|wc -l` -ne 1 ];then
echo "remoteip $b">>/etc/pptpd.conf
fi
if [ `egrep "202.96.128.86|8.8.8.8" /etc/ppp/options.pptpd |wc -l` -lt 2 ];then
echo ms-dns 202.96.128.86>>/etc/ppp/options.pptpd
echo ms-dns 8.8.8.8>>/etc/ppp/options.pptpd
fi
forward(){
/usr/sbin/iptables -t nat -A POSTROUTING -o $d -j MASQUERADE
/usr/sbin/iptables -A FORWARD -p tcp --syn -s $e -j TCPMSS --set-mss 1356
/usr/libexec/iptables/iptables.init save
echo "/usr/bin/systemctl start iptables" >>/etc/rc.local
}
echo "/usr/bin/systemctl start pptpd" >>/etc/rc.local
iptablesstatus=`/usr/bin/systemctl status iptables|grep "Active"|awk ‘{print $2}‘`
if [ "$iptablesstatus" = "active" -a `grep -E "MASQUERADE|--set-mss" /etc/sysconfig/iptables|wc -l` -lt 2 ];then
forward
elif [ "$iptablesstatus" = "inactive" -a `grep -E "MASQUERADE|--set-mss" /etc/sysconfig/iptables|wc -l` -lt 2 ];then
/usr/bin/systemctl restart iptables
forward
else
echo ‘your server no support iptables forwarding!‘
fi
/usr/bin/systemctl restart pptpd
if [ `ss -lntup|grep "1723"|wc -l` -eq 1 ]
then
action "pptpd is start ok" /bin/true
else
action "pptpd is fail " /bin/false
fi
==========================添加拨号用户====================
#!/bin/sh
echo "input your username"
read -p "username:" a
echo "input your secret"
read -p "password:" b
if [ ` awk ‘{print $1}‘ /etc/ppp/chap-secrets |grep "li"|wc -l` -eq 0 ];then
echo "$a pptpd $b *" >>/etc/ppp/chap-secrets
fi