Skip to content

Instantly share code, notes, and snippets.

@grasses
Created August 24, 2017 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grasses/72e8c61c902caa151d057c438b9a4329 to your computer and use it in GitHub Desktop.
Save grasses/72e8c61c902caa151d057c438b9a4329 to your computer and use it in GitHub Desktop.
One command install vpn shell
#!/bin/bash
# Setup Simple PPTP VPN server for CentOS 7
# Copyright (C) 2015-2017 http://homeway.me 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 ;;
esac
done
# 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/bin
clear
yum -y update
yum -y install epel-release
yum -y install iptables-service
yum -y install firewalld net-tools curl ppp pptpd
systemctl enable iptables
echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf
sysctl -p
#no liI10oO chars in password
LEN=$(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 <<END
$NAME pptpd $PASS *
END
cat >/etc/pptpd.conf <<END
option /etc/ppp/options.pptpd
#logwtmp
localip 192.168.2.1
remoteip 192.168.2.10-100
END
cat >/etc/ppp/options.pptpd <<END
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
ms-dns 8.8.8.8
ms-dns 209.244.0.3
proxyarp
lock
nobsdcomp
novj
novjccomp
nologfd
END
ETH=`route | grep default | awk '{print $NF}'`
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT
iptables-save
systemctl restart iptables
cat > /etc/ppp/ip-up.local << END
/sbin/ifconfig $1 mtu 1400
END
chmod +x /etc/ppp/ip-up.local
systemctl restart pptpd.service
systemctl 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"
############################################
############# one command VPN ##############
# Usage example:
# $ chmod +x xvpn.sh
# $ ./xvpn.sh -u your_username -p your_password
############################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment