1、安装前的准备工作: [root@data ~]# yum -y install openssl openssl-devel gcc
[root@data ~]# wget http://swupdate.openvpn.org/community/releases/openvpn-2.2.2.tar.gz [root@data ~]# wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.03.tar.gz 2、安装lzo软件包:
lzo软件包用于压缩隧道通信数据以加快传输速度,操作步骤如下 :
[root@data ~]# tar zxvf lzo-2.03.tar.gz
[root@data ~]# cd lzo-2.03
[root@data lzo-2.03]# ./configure --prefix=/usr/ && make && make install
4、安装openvn:
[root@data ~]# tar zxvf openvpn-2.2.2.tar.gz
[root@data ~]# cd openvpn-2.2.2
[root@data openvpn-2.2.2]# ./configure --with-lzo-lib=/usr/ && make && make install
(1、)建立CA的详细信息
5、OpenVPN 服务器的配置
[root@data ~]# cd openvpn-2.2.2/easy-rsa/2.0/
[root@data 2.0]# vim vars export KEY_COUNTRY="CN" 你所在的国家,两个字符为限 export KEY_PROVINCE="HN" 你所在的省份 export KEY_CITY="changsha" 你所在的城市 export KEY_ORG="cn6677" 你所在的组织 export KEY_EMAIL="1250052800@qq.com" 你的电子邮件 export KEY_OU=cn6677.com 你所在的单位 [root@data 2.0]# source vars //此命令输入后会显示如下信息
NOTE: If you run ./clean-all, I will be doing a rm -rf on /root/openvpn-2.2.2/easy-rsa/2.0/keys
接着输入下面的命令:
[root@data 2.0]# cp openssl-1.0.0.cnf openssl.cnf
[root@data 2.0]# ./clean-all
[root@data 2.0]# ./build-ca //一路回车即可会生成 root CA证书
为服务器生成Diffie-Hellman文件,后面配置OpenVPN Server时所需要用到的文件命令如下:
(2)、为服务器生成证书和密钥,命令如下:
[root@data 2.0]# ./build-key-server server
还是与上一步类似,
[root@data 2.0]# ./build-key-server server
Generating a 1024 bit RSA private key .....++++++ ...........++++++ writing new private key to 'server.key' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [CN]: State or Province Name (full name) [HN]: Locality Name (eg, city) [Hunan]: Organization Name (eg, company) [cn6677]: Organizational Unit Name (eg, section) [cn6677.com]: Common Name (eg, your name or your server's hostname) [server]: Name [changeme]: Email Address [mail@host.domain]: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []:123456 An optional company name []:cn6677.com Using configuration from /root/openvpn-2.2.2/easy-rsa/2.0/openssl.cnf Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows countryName :PRINTABLE:'CN' stateOrProvinceName :PRINTABLE:'HN' localityName :PRINTABLE:'Hunan' organizationName :PRINTABLE:'cn6677' organizationalUnitName:PRINTABLE:'cn6677.com' commonName :PRINTABLE:'server' name :PRINTABLE:'changeme' emailAddress :IA5STRING:'mail@host.domain' Certificate is to be certified until Nov 27 22:02:42 2022 GMT (3650 days) Sign the certificate? [y/n]:y 1 out of 1 certificate requests certified, commit? [y/n]y Write out database with 1 new entries Data Base Updated [root@data 2.0]# ./build-key yonghu
[root@data 2.0]# ll keys/
总用量 68 -rw-r--r--. 1 root root 4038 11月 30 06:02 01.pem -rw-r--r--. 1 root root 3917 11月 30 06:07 02.pem -rw-r--r--. 1 root root 1338 11月 30 05:55 ca.crt -rw-------. 1 root root 912 11月 30 05:55 ca.key -rw-r--r--. 1 root root 245 11月 30 05:58 dh1024.pem -rw-r--r--. 1 root root 250 11月 30 06:07 index.txt -rw-r--r--. 1 root root 21 11月 30 06:07 index.txt.attr -rw-r--r--. 1 root root 21 11月 30 06:02 index.txt.attr.old -rw-r--r--. 1 root root 125 11月 30 06:02 index.txt.old -rw-r--r--. 1 root root 3 11月 30 06:07 serial -rw-r--r--. 1 root root 3 11月 30 06:02 serial.old -rw-r--r--. 1 root root 4038 11月 30 06:02 server.crt -rw-r--r--. 1 root root 781 11月 30 06:02 server.csr -rw-------. 1 root root 916 11月 30 06:02 server.key -rw-r--r--. 1 root root 3917 11月 30 06:07 yonghu.crt -rw-r--r--. 1 root root 781 11月 30 06:07 yonghu.csr -rw-------. 1 root root 912 11月 30 06:07 yonghu.key (3、)修改OpenVPN的配置文件/etc/server.conf
1)、复制示例文件到/etc目录下,然后再在其基础下进行更改,命令如下:
[root@data 2.0]# cp /root/openvpn-2.2.2/sample-config-files/server.conf /etc/server.conf
2、)编辑/etc/server.conf,注意以下几个重点:
一是将proto udp 改为proto tcp ,即服务启动用TCP 1194端口。
二是将ca那4行内容改成如下所示的形式(记得写绝对路径):
ca /root/openvpn-2.2.2/easy-rsa/2.0/keys/ca.crt
ca后面接的是 root CA 它使用的是buid-ca生成的,用于验证客户端证书是否合法的。
cert /root/openvpn-2.2.2/easy-rsa/2.0/keys/server.crt
key /root/openvpn-2.2.2/easy-rsa/2.0/keys/server.key
上面是服务器对应的证书等相关文件
dh /root/openvpn-2.2.2/easy-rsa/2.0/keys/dh1024.pem
三是将server那行改为如下内容:
server 10.8.0.0 255.255.255.0 //这是OpenVPN服务器启动时为VPN网络分配的网段,注意不要与公网中的IP发生冲突。
四是将verb3改为verb4
3、)启动OpenVPN
1、关闭iptables和selinux,以免对OpenVPN造成不必要的干扰
2、开启系统中自带的IP转发功能,命令如下:
[root@data keys]# echo "1" >/proc/sys/net/ipv4/ip_forward
3、用命令启动OpenVPN,命令如下:
[root@data keys]# /usr/local/sbin/openvpn --config /etc/server.conf
如果看到 Initialization Sequence Completed 表示启动成功
用lsof -i:1194来验证一下2、)编辑/etc/server.conf,注意以下几个重点:
一是将proto udp 改为proto tcp ,即服务启动用TCP 1194端口。
二是将ca那4行内容改成如下所示的形式(记得写绝对路径):
ca /root/openvpn-2.2.2/easy-rsa/2.0/keys/ca.crt
ca后面接的是 root CA 它使用的是buid-ca生成的,用于验证客户端证书是否合法的。
cert /root/openvpn-2.2.2/easy-rsa/2.0/keys/server.crt
key /root/openvpn-2.2.2/easy-rsa/2.0/keys/server.key
上面是服务器对应的证书等相关文件
dh /root/openvpn-2.2.2/easy-rsa/2.0/keys/dh1024.pem
三是将server那行改为如下内容:
server 10.8.0.0 255.255.255.0 //这是OpenVPN服务器启动时为VPN网络分配的网段,注意不要与公网中的IP发生冲突。
四是将verb3改为verb4
3、)启动OpenVPN
1、关闭iptables和selinux,以免对OpenVPN造成不必要的干扰
2、开启系统中自带的IP转发功能,命令如下:
[root@data keys]# echo "1" >/proc/sys/net/ipv4/ip_forward
3、用命令启动OpenVPN,命令如下:
[root@data keys]# /usr/local/sbin/openvpn --config /etc/server.conf
如果看到 Initialization Sequence Completed 表示启动成功
用lsof -i:1194来验证一下
[root@data keys]# lsof -i:1194
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME openvpn 20074 root 5u IPv4 94836 0t0 TCP *:openvpn (LISTEN) 注:本实验部分内容收集于网上。
|
不良信息举报Q:2000617|Archiver|ROS软路由论坛 ROSABC.com 网络方案网络工程交流
GMT+8, 2024-5-14 12:14 , Processed in 0.070985 second(s), 15 queries .
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.