网上对于国内VPN整顿也是热议不止的,在国内,除了付费购买VPN服务之外,其实也可以自己通过一台国外服务器来搭建VPN服务,从而实现翻墙访问国外网站。本文主要跟大家分享分享如何搭建VPN服务器用来翻墙国外网站的方法。
首先当然是需要有一个境外的服务器,作为VPN来讲,不需要太高的配置,系统这里建议选择linux,这里以centos为例来掩饰。
安装openvpn和easy-rsa软件包,因为系统默认yum源没有openvpn和easy-rsa软件包,所以这里就先修改源,然后安装软件。推荐阅读:《租用国外服务器的优势》
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm yum -y install openvpn easy-rsa
接着继续文件配置生产的操作:
切换到/usr/share/easy-rsa/2.0/目录
cd /usr/share/easy-rsa/2.0/
初始化环境变量
source vars
清除所有与证书相关的文件
https://cn.bluehost.com/blog/zsk/faq/clean-all
生成CA相关文件
https://cn.bluehost.com/blog/zsk/faq/build-ca
生成服务端相关文件
https://cn.bluehost.com/blog/zsk/faq/build-key-server server
生成客户端相关文件
https://cn.bluehost.com/blog/zsk/faq/build-key client
生成dh2048.pem文件
https://cn.bluehost.com/blog/zsk/faq/build-dh
生成ta.key文件(防DDos攻击)
openvpn –genkey –secret keys/ta.key
创建/etc/openvpn/server.conf文件,内容如下
port 1194 proto udp dev tun ca /usr/share/easy-rsa/2.0/keys/ca.crt cert /usr/share/easy-rsa/2.0/keys/server.crt key /usr/share/easy-rsa/2.0/keys/server.key # This file should be kept secret dh /usr/share/easy-rsa/2.0/keys/dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway def1 bypass-dhcp" push "dhcp-option DNS 8.8.8.8" keepalive 10 120 tls-auth /usr/share/easy-rsa/2.0/keys/ta.key 0 # This file is secret comp-lzo persist-key persist-tun status openvpn-status.log verb 3