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

来源:互联网 发布:java excel 日期格式 编辑:程序博客网 时间:2024/04/28 10:29

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

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

  1. wget http://mirrors.linuxeye.com/scripts/vpn_centos.sh
  2. chmod +x ./vpn_centos.sh
  3. ./vpn_centos.sh

脚本内容如下(vpn_centos.sh):

  1. #!/bin/bash
  2. #
  3. # Author:  yeho <lj2007331 AT gmail.com>
  4. # Blog:  //blog.linuxeye.com
  5. #
  6. # Installs a PPTP VPN-only system for CentOS
  7. # Check if user is root
  8. [ $(id -u) != "0" ] && { echo -e "\033[31mError: You must be root to run this script\033[0m"; exit 1; }
  9. export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  10. clear
  11. printf "
  12. #######################################################################
  13. #    LNMP/LAMP/LANMP for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+    #
  14. #            Installs a PPTP VPN-only system for CentOS               #
  15. # For more information please visit //blog.linuxeye.com/31.html  #
  16. #######################################################################
  17. "
  18. [ ! -e '/usr/bin/curl' ] && yum -y install curl
  19. VPN_IP=`curl ipv4.icanhazip.com`
  20. VPN_USER="linuxeye"
  21. VPN_PASS="linuxeye"
  22. VPN_LOCAL="192.168.0.150"
  23. VPN_REMOTE="192.168.0.151-200"
  24. while :; do echo
  25.     read -p "Please input username: " VPN_USER
  26.     [ -n "$VPN_USER" ] && break
  27. done
  28. while :; do echo
  29.     read -p "Please input password: " VPN_PASS
  30.     [ -n "$VPN_PASS" ] && break
  31. done
  32. clear
  33. if [ -f /etc/redhat-release -a -n "`grep ' 7\.' /etc/redhat-release`" ];then
  34.     #CentOS_REL=7
  35.     if [ ! -e /etc/yum.repos.d/epel.repo ];then
  36.         cat > /etc/yum.repos.d/epel.repo << EOF
  37. [epel]
  38. name=Extra Packages for Enterprise Linux 7 - \$basearch
  39. #baseurl=http://download.fedoraproject.org/pub/epel/7/\$basearch
  40. mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=\$basearch
  41. failovermethod=priority
  42. enabled=1
  43. gpgcheck=0
  44. EOF
  45.     fi
  46.     for Package in wget make openssl gcc-c++ ppp pptpd iptables iptables-services
  47.     do
  48.         yum -y install $Package
  49.     done
  50.     echo 'net.ipv4.ip_forward = 1>> /etc/sysctl.conf
  51. elif [ -f /etc/redhat-release -a -n "`grep ' 6\.' /etc/redhat-release`" ];then
  52.     #CentOS_REL=6
  53.     for Package in wget make openssl gcc-c++ iptables ppp
  54.     do
  55.         yum -y install $Package
  56.     done
  57.     sed -i 's@net.ipv4.ip_forward.*@net.ipv4.ip_forward = 1@g' /etc/sysctl.conf
  58.     rpm -Uvh http://poptop.sourceforge.net/yum/stable/rhel6/pptp-release-current.noarch.rpm
  59.     yum -y install pptpd
  60. else
  61.     echo -e "\033[31mDoes not support this OS, Please contact the author! \033[0m"
  62.     exit 1
  63. fi
  64. echo "1" > /proc/sys/net/ipv4/ip_forward
  65. sysctl -p /etc/sysctl.conf
  66. [ -z "`grep '^localip' /etc/pptpd.conf`" ] && echo "localip $VPN_LOCAL" >> /etc/pptpd.conf # Local IP address of your VPN server
  67. [ -z "`grep '^remoteip' /etc/pptpd.conf`" ] && echo "remoteip $VPN_REMOTE" >> /etc/pptpd.conf # Scope for your home network
  68. if [ -z "`grep '^ms-dns' /etc/ppp/options.pptpd`" ];then
  69.      cat >> /etc/ppp/options.pptpd << EOF
  70. ms-dns 223.5.5.5 # Aliyun DNS Primary
  71. ms-dns 114.114.114.114 # 114 DNS Primary
  72. ms-dns 8.8.8.8 # Google DNS Primary
  73. ms-dns 209.244.0.3 # Level3 Primary
  74. ms-dns 208.67.222.222 # OpenDNS Primary
  75. EOF
  76. fi
  77. echo "$VPN_USER pptpd $VPN_PASS *" >> /etc/ppp/chap-secrets
  78. ETH=`route | grep default | awk '{print $NF}'`
  79. [ -z "`grep '1723 -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT
  80. [ -z "`grep 'gre -j ACCEPT' /etc/sysconfig/iptables`" ] && iptables -I INPUT 5 -p gre -j ACCEPT
  81. iptables -t nat -A POSTROUTING -o $ETH -j MASQUERADE
  82. iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356
  83. service iptables save
  84. sed -i 's@^-A INPUT -j REJECT --reject-with icmp-host-prohibited@#-A INPUT -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables
  85. sed -i 's@^-A FORWARD -j REJECT --reject-with icmp-host-prohibited@#-A FORWARD -j REJECT --reject-with icmp-host-prohibited@' /etc/sysconfig/iptables
  86. service iptables restart
  87. chkconfig iptables on
  88. service pptpd restart
  89. chkconfig pptpd on
  90. clear
  91. echo -e "You can now connect to your VPN via your external IP \033[32m${VPN_IP}\033[0m"
  92. echo -e "Username: \033[32m${VPN_USER}\033[0m"
  93. echo -e "Password: \033[32m${VPN_PASS}\033[0m"

参考:https://github.com/drewsymo/VPN


转载于:https://blog.linuxeye.com/412.html

0 0
原创粉丝点击