Centos7搭建pptp快速安裝指令碼,centos7搭建pptp
Centos7搭建pptp快速安裝指令碼
CentOS7-pptp-host1plus.sh
#!/bin/bash# Setup Simple PPTP VPN server for CentOS 7 on Host1plus# 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: ./CentOS7-pptp-host1plus.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: ./CentOS7-pptp-host1plus.sh -u myusr -p mypassUse without parameter [ ./CentOS7-pptp-host1plus.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[ $(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/binclearyum -y updateyum -y install epel-releaseyum -y install firewalld net-tools curl ppp pptpdecho 'net.ipv4.ip_forward = 1' >> /etc/sysctl.confsysctl -p#no liI10oO chars in passwordLEN=$(echo ${#PASS})if [ -z "$PASS" ] || [ $LEN -lt 8 ] || [ -z "$NAME"]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"fiif [ -z "$NAME" ]then NAME="vpn"ficat >> /etc/ppp/chap-secrets </etc/pptpd.conf </etc/ppp/options.pptpd < /etc/ppp/ip-up.local << END/sbin/ifconfig $1 mtu 1400ENDchmod +x /etc/ppp/ip-up.localsystemctl restart pptpd.servicesystemctl enable pptpd.serviceVPN_IP=`curl ipv4.icanhazip.com`clearecho -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"
chmod 777 CentOS7-pptp-host1plus.shsh CentOS7-pptp-host1plus.sh -u your_username -p your_password
可在-u、-p後隨意更改自己的登入使用者名稱和密碼。但密碼長度必須大於8個 ASCII字元,否則為了安全,指令碼將會隨機產生密碼。
註:
如果你無法訪問一些特定網站,建議你修改ppp介面的MTU(很多時候能串連vpn但是無法開啟某些網頁也可能跟這個有關係)
輸入vi /etc/ppp/ip-up
在倒數第二行加入如下內容:/sbin/ifconfig $1 mtu 1400
預設 MTU:1496
儲存後需要重啟PPTP伺服器,指令如下: systemctl restart pptpd
也可以不更改ip-up檔案,而是在/etc/ppp/下建立ip-up.local檔案。指令如下:
cat > /etc/ppp/ip-up.local << END/sbin/ifconfig $1 mtu 1400ENDchmod +x /etc/ppp/ip-up.local
該指令碼使用的是後者。
附上其他linux發行版的pptp vpn一鍵安裝指令碼的Github地址:pptp一鍵指令碼