centos7下PPTP脚本+添加用户脚本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7下PPTP脚本+添加用户脚本相关的知识,希望对你有一定的参考价值。

需要输入你网卡名字,本地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


本文出自 “网管运维” 博客,请务必保留此出处http://justforfunny.blog.51cto.com/3916511/1854233

以上是关于centos7下PPTP脚本+添加用户脚本的主要内容,如果未能解决你的问题,请参考以下文章

centos7添加开机启动服务/脚本

centos7 创建普通用户,添加sudo权限,禁止root远程登录和公钥登录脚本

如何让pptp连接后自动添加策略路由

Centos7下添加开机自启动服务和脚本

如何在没有注销/登录的情况下将用户添加到组 - Bash 脚本

linux下利用脚本添加ftp虚拟用户并赋予权限