(转载)CentOS一键安装pptpd服务脚本
来源:互联网 发布:四川大学软件学院考研 编辑:程序博客网 时间:2024/06/05 14:27
(转载)一键安装pptpd服务
相关代码如下
#!/bin/bash# Setup Simple PPTP VPN server for CentOS# Copyright (C) 2015-2016 Danyl Zhang <1475811550@qq.com> and contributors## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.#定义帮助信息函数printhelp() {echo "Usage: ./CentOS-pptp-setup.sh [OPTION]If you are using custom password , Make sure its more than 8 characters. Otherwise it will generate random password for you. If you trying set password only. It will generate Default user with Random password. example: ./CentOS-pptp-setup.sh -u myusr -p mypassUse without parameter [ ./CentOS-pptp-setup.sh ] to use default username and Random password -u, --username Enter the Username -p, --password Enter the Password"}#对输入信息进行判断while [ "$1" != "" ]; do case "$1" in -u | --username ) NAME=$2; shift 2 ;; -p | --password ) PASS=$2; shift 2 ;; -h | --help ) echo "$(printhelp)"; exit; shift; break ;; esacdone# Check if user is root,脚本必须在root用户下执行[ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; } #定义路径,清空显示屏幕export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binclear#如果没有curl,就下载它[ ! -e '/usr/bin/curl' ] && yum -y install curl#定义相关变量,下面要用到VPN_IP=`curl ipv4.icanhazip.com` #通过curl这个地址,可以获取服务器的出口公网IPVPN_LOCAL="192.168.2.1" #pptp服务器端IP,可以设置为服务器上绑定的任意一个IP地址VPN_REMOTE="192.168.2.10-100" #客户端成功连接VPN后获取的IP地址范围(可以和pptp服务器在同一内网段内,但是建议不要设置和PPTP服务器内网一样的网段)clear#下面要下载一下安装包,在epel源中,需要先确认epel源的配置if [ -f /etc/redhat-release -a -n "`grep ' 7\.' /etc/redhat-release`" ];then #判断系统是否为centos7 #CentOS_REL=7 if [ ! -e /etc/yum.repos.d/epel.repo ];then cat > /etc/yum.repos.d/epel.repo << EOF[epel]name=Extra Packages for Enterprise Linux 7 - \$basearch#baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearchmirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearchfailovermethod=priorityenabled=1gpgcheck=0EOFfi for Package in wget make openssl gcc-c++ ppp pptpd iptables iptables-services #下载指定安装包 do yum -y install $Package done echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf #修改转发设置elif [ -f /etc/redhat-release -a -n "`grep ' 6\.' /etc/redhat-release`" ];then #如果系统是centos6 #CentOS_REL=6 for Package in wget make openssl gcc-c++ iptables ppp do yum -y install $Package done sed -i 's@net.ipv4.ip_forward.*@net.ipv4.ip_forward = 1@g' /etc/sysctl.conf rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm yum -y install pptpdelse echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m" #如果是其他系统就提醒并退出 exit 1fisysctl -p #使转发设置生效#-z检查/etc/pptpf.conf中相关参数是否已经设置了,然后把设置的相关参数导入到/etc/pptpd.conf中[ -z "`grep '^localip' /etc/pptpd.conf`" ] && echo "localip $VPN_LOCAL" >> /etc/pptpd.conf # Local IP address of your VPN server[ -z "`grep '^remoteip' /etc/pptpd.conf`" ] && echo "remoteip $VPN_REMOTE" >> /etc/pptpd.conf # Scope for your home network#检查并设置dns服务器if [ -z "`grep '^ms-dns' /etc/ppp/options.pptpd`" ];then echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd echo "ms-dns 209.244.0.3" >> /etc/ppp/options.pptpdfi#no liI10oO chars in passwordLEN=$(echo ${#PASS}) #检查密码是否设置if [ -z "$PASS" ] || [ $LEN -lt 8 ] || [ -z "$NAME"] #如果密码字符串为0(就是没有设置)或小于8位或跟要设置的用户名相同,那么就重新设置then P1=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` P2=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` P3=`cat /dev/urandom | tr -cd abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 | head -c 3` PASS="$P1-$P2-$P3" #生成一个11位的随机密码fiif [ -z "$NAME" ]then NAME="vpn" #如果用户名没有设置,就默认为vpnficat >> /etc/ppp/chap-secrets <<END #将账号密码导出到/etc/ppp/chap-secrets中$NAME pptpd $PASS *ENDETH=`route | grep default | awk '{print $NF}'` #获取默认的出口网卡名#设置iptables规则[ -z "`grep '1723 -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT #打开1723端口[ -z "`grep 'gre -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 5 -p gre -j ACCEPT #放行gre隧道连接iptables -t nat -A POSTROUTING -o $ETH -j MASQUERADEiptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356#保存刚才设置的iptables规则,注释掉(删除)相关规则service iptables savesed -i 's@^-A INPUT -j REJECT --reject-with icmp-host-prohibited@#-A INPUT -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables sed -i 's@^-A FORWARD -j REJECT --reject-with icmp-host-prohibited@#-A FORWARD -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables #设置iptables服务重启,开机运行service iptables restartchkconfig iptables on#设置pptpd服务重启,开机运行service pptpd restartchkconfig pptpd onclearecho -e "You can now connect to your VPN via your external IP \033[32m${VPN_IP}\033[0m"echo -e "Username: \033[32m${NAME}\033[0m"echo -e "Password: \033[32m${PASS}\033[0m"
脚本里面的注释内容有一些是我自己加进去的,方便理解。在使用的时候可以直接用wget下载,或者直接去原地址copy
参考地址:
- Centos7搭建pptp VPN一键安装脚本
- CentOS 7 安装VPN Server 和 Client
- Centos下PPTP环境部署记录
- 如何在windows上配置连接pptpd
脚本在github上的地址:https://github.com/DanylZhang/VPS/blob/master/CentOS-pptp-setup.sh
亲测可用,可以放心用啊。
阅读全文
0 0
- (转载)CentOS一键安装pptpd服务脚本
- CentOS全系列 PPTPD VPN一键安装脚本
- 一键安装PPTPD VPN 脚本
- VPS服务器架设:CentOS PPTPD VPN一键安装包
- Linux 搭建VPN,PPTPD一键安装脚本
- aliyun centos vpn 配置(pptpd服务)
- centos 5.8安装pptpd
- centos安装pptpd(vpn)最详细的教程+一键安装包
- 服务器架设:PPTPD/L2TP/IPSec VPN一键安装包 For CentOS 6
- CentOS 6 上安装PPTPD
- CentOS 7 中 pptpd安装
- vps centos 搭建vpn服务pptpd
- Centos PPTP VPN 一键安装脚本
- centos上tensorflow一键安装脚本
- Centos pptp vpn 一键安装脚本
- centos 一键安装配置nginx脚本
- centos mongodb一键安装脚本
- Centos Nginx脚本一键安装
- 彻底解决pycharm输入法中文支持问题
- Vsiual Studio自动生成版本号的一种方法
- 基于httpclient的post json方法
- 【Boost】boost库中thread多线程详解4——谈谈recursive_mutex(递归式互斥量)
- 工具代码(一):MD5加密
- (转载)CentOS一键安装pptpd服务脚本
- 如何查看linux系统是否禁ping
- 云计算虚拟化实验(一)——虚拟机软件VMware的安装以及虚拟机系统的安装(Windows7+CentOS7)
- 从源码剖析一个Spark WordCount Job执行的全过程
- Java并发编程:Timer和TimerTask
- tortoisegit如何退回原来的版本及回退远端
- linux多线程调用同一个函数解析
- FileZilla Server 设置
- C++设计模式——外观模式