LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > 脚本编程 >

CentOS 6、7下pptp vpn一键安装脚本

时间:2015-03-04 11:26来源:Linux运维笔记 编辑:yeho 点击:
之前有折腾过《 CentOS 6、7下IPSEC/L2TP VPN一键安装脚本 》,不稳定、不支持IOS,因此换成pptp,并已经添加到《 lnmp一键安装包 》。这个脚本可以单独使用,直接复制或下载执行即可,不

之前有折腾过《CentOS 6、7下IPSEC/L2TP VPN一键安装脚本》,不稳定、不支持IOS,因此换成pptp,并已经添加到《lnmp一键安装包》。这个脚本可以单独使用,直接复制或下载执行即可,不用依赖安装包的其它脚本。

有任何问题请回帖:http://bbs.linuxeye.com/thread-197-1-1.html

CentOS 6、7下pptp vpn一键安装脚本,如下(vpn_centos.sh):

#!/bin/bash
#
# Author:  yeho <lj2007331 AT gmail.com>
# Blog:  http://blog.linuxeye.com
#
# Installs a PPTP VPN-only system for CentOS

# Check if user is root
[ $(id -u) != "0" ] && echo "Error: You must be root to run this script" && exit 1

export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
clear
printf "
#######################################################################
#    LNMP/LAMP/LANMP for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+    #
# For more information please visit http://blog.linuxeye.com/31.html  #
#######################################################################
"

[ ! -e '/usr/bin/curl' ] && yum -y install curl

VPN_IP=`curl ipv4.icanhazip.com`

VPN_USER="linuxeye"
VPN_PASS="linuxeye"

VPN_LOCAL="192.168.0.150"
VPN_REMOTE="192.168.0.151-200"

while :
do
        echo
        read -p "Please input username: " VPN_USER
        [ -n "$VPN_USER" ] && break
done

while :
do
        echo
        read -p "Please input password: " VPN_PASS
        [ -n "$VPN_PASS" ] && break
done
clear


if [ -n "`grep 'CentOS Linux release 7' /etc/redhat-release`" ];then
        #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/\$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
failovermethod=priority
enabled=1
gpgcheck=0
EOF
fi
        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 [ -n "`grep 'CentOS release 6' /etc/redhat-release`" ];then
        #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 pptpd
else
        echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m"
        exit 1
fi


echo "1" > /proc/sys/net/ipv4/ip_forward

sysctl -p /etc/sysctl.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

if [ -z "`grep '^ms-dns' /etc/ppp/options.pptpd`" ];then
        echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd # Google DNS Primary
        echo "ms-dns 209.244.0.3" >> /etc/ppp/options.pptpd # Level3 Primary
        echo "ms-dns 208.67.222.222" >> /etc/ppp/options.pptpd # OpenDNS Primary
fi

echo "$VPN_USER pptpd $VPN_PASS *" >> /etc/ppp/chap-secrets

ETH=`route | grep default | awk '{print $NF}'`
iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT
iptables -t nat -A POSTROUTING -o $ETH -j MASQUERADE
service iptables save
service iptables restart

service pptpd restart
chkconfig pptpd on
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${VPN_USER}\033[0m"
echo -e "Password: \033[32m${VPN_PASS}\033[0m"
原文:http://blog.linuxeye.com/412.html
------分隔线----------------------------
标签:centosVPNpptp
评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
栏目列表
推荐内容