搜索
您的当前位置:首页Centos7搭建pptp一键安装脚本

Centos7搭建pptp一键安装脚本

来源:飒榕旅游知识分享网
Centos7搭建pptp⼀键安装脚本

#!/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 mypass

Use 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/binclear

yum -y update

yum -y install epel-release

yum -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\"fi

if [ -z \"$NAME\" ]then

NAME=\"vpn\"fi

cat >> /etc/ppp/chap-secrets <cat >/etc/pptpd.conf <localip 192.168.2.1

remoteip 192.168.2.10-100END

cat >/etc/ppp/options.pptpd <refuse-chaprefuse-mschaprequire-mschap-v2require-mppe-128ms-dns 8.8.8.8

ms-dns 209.244.0.3proxyarplock

nobsdcompnovj

novjccompnologfdEND

ETH=`route | grep default | awk '{print $NF}'`

systemctl restart firewalld.servicesystemctl enable firewalld.servicefirewall-cmd --set-default-zone=publicfirewall-cmd --add-interface=$ETH

firewall-cmd --add-port=22/tcp --permanentfirewall-cmd --add-port=1723/tcp --permanentfirewall-cmd --add-masquerade --permanent

firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -i $ETH -p gre -j ACCEPTfirewall-cmd --reload

cat > /etc/ppp/ip-up.local << END/sbin/ifconfig $1 mtu 1400END

chmod +x /etc/ppp/ip-up.localsystemctl restart pptpd.servicesystemctl enable pptpd.service

VPN_IP=`curl ipv4.icanhazip.com`clear

echo -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\"

Centos7⼀键pptp

1. wget https://files.cnblogs.com/files/wangbin/vpn_centos.sh2. chmod +x ./vpn_centos.sh3. ./vpn_centos.sh

可在-u、-p后随意更改⾃⼰的登录⽤户名和密码。但密码长度必须⼤于8个 ASCII字符,否则为了安全,脚本将会随机⽣成密码。 注:

如果你⽆法访问⼀些特定⽹站,建议你修改ppp接⼝的MTU(很多时候能连接vpn但是⽆法打开某些⽹页也可能跟这个有关系)输⼊vi /etc/ppp/ip-up

在倒数第⼆⾏加⼊如下内容:/sbin/ifconfig $1 mtu 1400缺省 MTU:1496

保存后需要重启PPTP服务器,指令如下: systemctl restart pptpd

因篇幅问题不能全部显示,请点此查看更多更全内容

Top