CentOS下编译安装OpenVPN2.1.4

自渡
2017-09-27 / 0 评论 / 2,178 阅读

安装依赖

yum install openssl openssl-devel gcc wget -y

下载OpenVPN2.1.4源码包和LZO2.05

wget http://downloads.openwrt.org.cn/sources/openvpn-2.1.4.tar.gz

wget http://downloads.openwrt.org.cn/sources/lzo-2.05.tar.gz

tar -zxvf openvpn-2.1.4.tar.gz && tar -zxvf lzo-2.05.tar.gz

cd lzo-2.05.tar.gz/

先编译安装lzo2.05

./configure

make && make install

编译安装openvpn2.1.4

cd openvpn-2.1.4/

./configure

make && make install

使用easyrsa2.0生成证书

cd easyrsa2.0/

vi vars填写末尾六行

eg:

export KEY_SIZE=2048

export KEY_COUNTRY="US"

export KEY_PROVINCE="CA"

export KEY_CITY="LosAngeles"

export KEY_ORG="Lonelyboy Networks"

export KEY_EMAIL="lonelyboyzavier@gmail.com"

保存后

chmod +x vars

source ./vars

清空keys中的内容

./clean-all

生成2048位RSA服务器CA证书

./build-ca

生成服务器证书

./build-key-server openvpnserver

生成客户端证书

./build-key clientname(自定义名)

生成dh2048.pem文件

./build-dh

一个客户端连接需要三个文件ca.crt ,client.crt,client.key

拷贝至客户端即可

mkdir /etc/openvpn && cd /etc/openvpn

touch server.conf

mkdir cert (将ca.crt ,dh2048.pem,openvpnserver.crt,openvpnserver.key拷贝到cert文件夹)

服务器端配置server.conf参考

自定义协议)

proto #端口号定义

port XXX

VPS使用tun需要母鸡支持

dev tun

topology subnet

server 10.8.0.0 255.255.255.0

自定义需要走VPN的IP路由

push "route 172.31.9.0 255.255.255.0"

auth SHA256

cipher AES-256-CBC

comp-lzo adaptive

push "comp-lzo adaptive"

通过服务端转发所有流量,默认不启用

push "redirect-gateway def1 bypass-dhcp"

向客户端通告DNS,可自定义

push "dhcp-option DNS 114.114.114.114"

push "dhcp-option DNS 8.8.8.8"

配置证书文件路径

ca /etc/openvpn/cert/ca.crt

dh /etc/openvpn/cert/dh2048.pem

cert /etc/openvpn/cert/openvpnserver.crt

key /etc/openvpn/cert/openvpnserver.key

persist-key

persist-tun

user nobody

生成openvpn日志,verb为日志等级,默认为3

log /var/log/openvpn.log

log-append /var/log/openvpn.log

max-clients 10

client-to-client

keepalive 10 60

nice 3

verb 4

mute 10

iptables配置转发

iptables -t nat -A POSTROUTING -s 10.8.0.0/255.255.255.0 -o eth0 -j MASQUERADE

vi /etc/sysctl.conf net.ipv4.ip_forward=1

openvpn启动命令

openvpn --config /etc/openvpn/server.conf

0

评论

博主关闭了当前页面的评论