一键搭建VPN服务器

经常要在外网之间折腾的朋友,势必会想尽办法利用各种翻墙工具(如google自带的翻墙、psiphon、lantern、shadowsocksX....)。

其实这些工具本人都一一用过,感觉就是各种不稳定,而起速度还很慢。shadowsocksX相对还算好些,毕竟是要花钱买的,但也是遭到国内封杀,有时也连不上。考虑到经常需要,所以我就在亚太新加坡节点弄了一台做VPN代理服务器。用来翻墙。速度和稳定程度都还不错。

以前搭建VPN都要手工配置各种文件,相当麻烦。现在我推荐一个脚本给大家,vpn_centos.sh,一键搭建,省去之前的各种配置,而且还相当稳定。

兼容CentOS6、7,安装步骤如下:

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

脚本代码如下:

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

# 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
printf "
#######################################################################
#    LNMP/LAMP/LANMP for CentOS/RadHat 5+ Debian 6+ and Ubuntu 12+    #
#            Installs a PPTP VPN-only system for CentOS               #
# For more information please visit https://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 [ -f /etc/redhat-release -a -n "`grep ‘ 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 [ -f /etc/redhat-release -a -n "`grep ‘ 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 ‘[email protected]_forward.*@net.ipv4.ip_forward = [email protected]‘ /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
[ -z "`grep ‘^stimeout‘ /etc/pptpd.conf`" ] && echo "stimeout 172800" >> /etc/pptpd.conf

if [ -z "`grep ‘^ms-dns‘ /etc/ppp/options.pptpd`" ];then
     cat >> /etc/ppp/options.pptpd << EOF
ms-dns 223.5.5.5 # Aliyun DNS Primary
ms-dns 114.114.114.114 # 114 DNS Primary
ms-dns 8.8.8.8 # Google DNS Primary
ms-dns 209.244.0.3 # Level3 Primary
ms-dns 208.67.222.222 # OpenDNS Primary
EOF
fi

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

ETH=`route | grep default | awk ‘{print $NF}‘`
[ -z "`grep ‘1723 -j ACCEPT‘ /etc/sysconfig/iptables`" ] && iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 1723 -j ACCEPT
[ -z "`grep ‘gre -j ACCEPT‘ /etc/sysconfig/iptables`" ] && iptables -I INPUT 5 -p gre -j ACCEPT 
iptables -t nat -A POSTROUTING -o $ETH -j MASQUERADE
iptables -I FORWARD -p tcp --syn -i ppp+ -j TCPMSS --set-mss 1356
service iptables save
sed -i ‘[email protected]^-A INPUT -j REJECT --reject-with [email protected]#-A INPUT -j REJECT --reject-with [email protected]‘ /etc/sysconfig/iptables 
sed -i ‘[email protected]^-A FORWARD -j REJECT --reject-with [email protected]#-A FORWARD -j REJECT --reject-with [email protected]‘ /etc/sysconfig/iptables 
service iptables restart
chkconfig iptables on

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"

附连接截图:

时间: 2024-08-02 06:53:44

一键搭建VPN服务器的相关文章

Linux下搭建VPN服务器(CentOS_6_x86+VPS+Shaowsocks)

#Linux下搭建VPN服务器(CentOS_6_x86+VPS+Shaowsocks)前面所搭建Linux下搭建VPN服务器(CentOS_5.9_x86_64.PPTP),因延迟过高,无法满足业务需求,因此公司决定采用CentOS_56_x86+VPS+Shaowsocks方案 公司供给翻译的使用VPN,正常访问境外的网站和观看视频,eg:欧盟经济体新闻发布会下面所介绍的服务器是香港服务器[必须是境外的服务器,或者国内能访问国外网站服务器] 搬瓦工bandwagonhost简单而且性能非常不

Ubuntu搭建VPN服务器

最近一段时间随着Google逐渐要退出香港,访问Google真是一件让人着急的事,同时很多源码包都无法安装.因此果断自己租一台服务器搭建一个VPN服务器,脱离墙内人士的苦海.因此将自己搭建VPN服务器的过程记录如下: 1. 服务器的租用:选取 BUDGETVM 最便宜的一款,一年的费用为90元人民币,同时支持支付宝付款,付款比较方便.经测试,延时为170ms,上网之类的还可以接受.如图所示: 2. ssh登录:租用成功后会有选择操作系统和其他一些选项,我取Ubuntu作为租用服务器的系统.同时最

vpn服务器搭建vpn服务器多少钱国外的vpn服务器多少钱

vpn服务器搭建vpn服务器多少钱国外的vpn服务器多少钱服务器租用价格表:?没有性价比更高的配置:香港服务器 双核 4G内存 独享国际带宽5M 399元 L5640 12核 8G内存 独享国际带宽5M 899元 E5 2670 16核 8G内存 独享国际带宽5M 1200元 QQ: 2727453595借助VPN,企业外出人员可随时连到企业的VPN服务器,进而连接到企业内部网络.借助windows2003的“路由和远程访问” 服务,可以实现基于软件的VPN. VPN(Virtual Priva

Cisco网络设备搭建VPN服务器的全过程

Cisco网络设备搭建VPN服务器的全过程 环境:在公司的南京办事处与上海办事处之间建立VPN联接. 南京办事处网络设置: 内网IP 10.1.1.0/24 外网IP 202.102.1.5/24 上海办事处网络设置: 内网IP 10.1.2.0/24 外网IP 202.102.1.6/24 南京路由器配置 ! service timestamps debug uptime service timestamps log uptime no service password-encryption

Windows2008RT搭建VPN服务器

总结一下2008系统搭建VPN的步骤和过程,自己有个人网站和服务要通过互联网发布出来.服务器放在自己家里,宽带是民用的.也就产生了服务发布的一些问题.用无法映射出真实的公网IP,或是一些其他内部的问题.解决办法同样也很多. 搭建一个VPN服务器也是一种解决办法,主要是因为该服务是C/S架构的.所以VPN算是一种偷懒吧.也顺道熟悉一下VPN方面的知识. 关于2008搭建VPN的过程,网上资源一大推,在这里我亲手搭建并把过程截图和大家一起分享,不喜勿喷~ ----------------------

搭建VPN服务器或 出现733错误解决方法[验证]

搭建VPN服务器出现733错误解决方法[验证]   昨晚用Windows 2003单网卡用花生壳实现VPN,搭建好VPN服务器后(记得把防火墙和WINDOWS连接共享服务关掉哦,在WINDOWS 2003中服务名为:Windows Firewall/Internet Connection Sharing),注册好花生壳(这真是个好东本啊),尝试远程连接时出现错误信息:TCP/IP CP报告了错误733,不能完成到远程计算机的连接, 没有就ppp协议成功.怎么回事呢?百度了一下!原来VPN服务器不

Linux下搭建VPN服务器(CentOS、pptp)

本文介绍在安装CentOS操作系统的Xen VPS上,如何搭建PPTP VPN服务.包括PPTP的安装.配置,以及相应的iptables规则.本文暂时不涉及PPTP流量控制的部分,等抽空学明白了FreeRADIUS,再来写续篇.2011年7月20日更新:在安全建议这一部分,增加了使用不同的IP地址,分别提供VPN服务和Web等其他常规服务,以及使用不同IP地址时如何书写iptables规则的内容. 写在前面 在Godaddy一美元COM域名的怂恿下,这几天先是拿到了这个gnailuy.com,然

Linux下搭建VPN服务器(CentOS、pptp)转

先说我搭建过程中出现的问题吧: 按照 教程搭建好之后出现了619错误,查看日志:/var/log/messages: Nov 20 09:46:20 localhost pptpd[7498]: GRE: read(fd=6,buffer=8059680,len=8196) from PTY failed: status = -1 error = Input/output error, usually caused by unexpected termination of pppd, check

转载-Linux下搭建VPN服务器(CentOS、pptp)

转自:http://www.cnblogs.com/sixiweb/archive/2012/11/20/2778732.html 搭建过程参考这篇文章 先说我搭建过程中出现的问题吧: 按照 教程搭建好之后出现了619错误,查看日志:/var/log/messages: Nov 20 09:46:20 localhost pptpd[7498]: GRE: read(fd=6,buffer=8059680,len=8196) from PTY failed: status = -1 error