java中的接口是类吗
354
2022-10-28
Centos6.8编译安装openvpn
系统环境:
SYSTEM VERSION:Centos6.8 X64
××× SERVER:192.168.1.10
virtual network:172.16.10.0
客户端:Win7
部署环境:
Server端部署:
1. 检查selinux状态,并将它关闭
[root@localhost ~]# getenforce enforcing [root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' !$
2. 安装openvpn2.3.6
yum install -y openssl pam-devel openssl-devel lzo lzo-devel gcc gcc-c++ automake pkgconfig wget -c -P /usr/local/src http://swupdate.openvpn.org/community/releases/openvpn-2.3.6.tar.gz tar -zxvf openvpn-2.3.6.tar.gz cd openvpn-2.3.6 ./configure --prefix=/usr/local/openvpn make && make install # 拷贝模板到/etc/openvpn下 mkdir /etc/openvpn cp -Rf sample/ /etc/openvpn/ # 复制配置文件到主目录下 cp /etc/openvpn/sample/sample-config-files/server.conf /etc/openvpn/
3. 下载easy-rsa证书
wget -c -P /usr/local/src https://github.com/Open×××/easy-rsa/archive/master.zip cd /usr/local/src;unzip master.zip # 需要yum下载unzip命令 cp -Rf easy-rsa-master/ /etc/openvpn/easy-rsa cd /etc/openvpn/easy-rsa/easyrsa3/ cp vars.example vars vim vars # 修改如下信息,根据自己情况修改 set_var EASYRSA_REQ_COUNTRY "CN" set_var EASYRSA_REQ_PROVINCE "BeiJing" set_var EASYRSA_REQ_CITY "BeiJing" set_var EASYRSA_REQ_ORG "ShenWei" set_var EASYRSA_REQ_EMAIL "admin@deepoly.com" set_var EASYRSA_REQ_OU "Openvpn" # 目录初始化 ./easyrsa init-pki ----------------------- Note: using Easy-RSA configuration from: ./vars init-pki complete; you may now create a CA or requests. Your newly created PKI dir is: /etc/openvpn/easy-rsa/easyrsa3/pki ------------------------
4. 创建根证书
[root@localhost easyrsa3]# ./easyrsa build-ca --------------------------------------------------------------------------------------- Note: using Easy-RSA configuration from: ./vars Generating a 2048 bit RSA private key ......................................+++ ..........+++ writing new private key to '/etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key.g0rfYAaNlP' Enter PEM pass phrase: openvpn Verifying - Enter PEM pass phrase: openvpn ----- 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. ----- Common Name (eg: your user, host, or server name) [Easy-RSA CA]: admin CA creation complete and you may now import and sign cert requests. Your new CA certificate file for publishing is at: /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt --------------------------------------------------------------------------------------- # 注意:在上述部分需要输入PEM密码 PEM pass phrase,输入两次,此密码必须记住,不然以后不能为 证书签名。还需要输入common name 通用名,这个你自己随便设置个独一无二的.
5. 创建服务端证书
[root@localhost easyrsa3]# ./easyrsa gen-req server nopass -------------------------------------------------------------------------------------- Note: using Easy-RSA configuration from: ./vars Generating a 2048 bit RSA private key ......................................+++ .....+++ writing new private key to '/etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key.0CLk8l2K9O' ----- 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. ----- Common Name (eg: your user, host, or server name) [server]: # 此名称随意,也可以用默认的server Keypair and certificate request completed. Your files are: req: /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/server.req key: /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key --------------------------------------------------------------------------------------
6. 签约服务端证书:(将创建的服务端证书与CA证书签约)
[root@localhost easyrsa3]# ./easyrsa sign server server -------------------------------------------------------------------------------------- Note: using Easy-RSA configuration from: ./vars You are about to sign the following certificate. Please check over the details shown below for accuracy. Note that this request has not been cryptographically verified. Please be sure it came from a trusted source or that you have verified the request checksum with the sender. Request subject, to be signed as a server certificate for 3650 days: subject= commonName = admin Type the word 'yes' to continue, or any other input to abort. Confirm request details: yes Using configuration from /etc/openvpn/easy-rsa/easyrsa3/openssl-1.0.cnf Enter pass phrase for /etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key: openvpn # 输入你刚才创建根证书的密码 Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :PRINTABLE:'admin' Certificate is to be certified until Jun 5 18:07:19 2026 GMT (3650 days) Write out database with 1 new entries Data Base Updated Certificate created at: /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt --------------------------------------------------------------------------------------
7. 创建Diffie-Hellman,确保key穿越不安全网络的命令
[root@localhost easyrsa3]# /usr/local/openvpn/sbin/openvpn --genkey --secret /etc/openvpn/ta.key [root@localhost easyrsa3]# ./easyrsa gen-dh
8. 创建客户端证书
[root@localhost easyrsa3]# mkdir -p /mnt/client [root@localhost easyrsa3]# cp -Rf /usr/local/src/easy-rsa-master /mnt/client/easy-rsa # 初始化目录 [root@localhost easyrsa3]# cd /mnt/client/easy-rsa/easyrsa3 [root@localhost easyrsa3]# ./easyrsa init-pki init-pki complete; you may now create a CA or requests. Your newly created PKI dir is: /mnt/client/easy-rsa/easyrsa3/pki # 创建客户端的key和crt [root@localhost easyrsa3]# # ./easyrsa gen-req yasar # 名字自定义,与客户端ovpn文件对应即可 Generating a 2048 bit RSA private key ......................................................................+++ ......................................+++ writing new private key to '/mnt/client/easy-rsa/easyrsa3/pki/private/yasar.key.5R9rJtnZvM' Enter PEM pass phrase: 11111111 # 客户端在登录的时候需要输入此口令 Verifying - Enter PEM pass phrase: 11111111 # # 客户端在登录的时候需要输入此口令 ----- 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. ----- Common Name (eg: your user, host, or server name) [yasar]: Keypair and certificate request completed. Your files are: req: /mnt/client/easy-rsa/easyrsa3/pki/reqs/yasar.req key: /mnt/client/easy-rsa/easyrsa3/pki/private/yasar.key # 将得到的xlmeng.req导入 [root@localhost easyrsa3]# cd /etc/openvpn/easy-rsa/easyrsa3/ [root@localhost easyrsa3]# ./easyrsa import-req /mnt/client/easy-rsa/easyrsa3/pki/reqs/yasar.req yasar Note: using Easy-RSA configuration from: ./vars The request has been successfully imported with a short name of: yasar You may now use this name to perform signing operations on this request. # 签约证书 [root@localhost easyrsa3]# ./easyrsa sign client yasar Note: using Easy-RSA configuration from: ./vars You are about to sign the following certificate. Please check over the details shown below for accuracy. Note that this request has not been cryptographically verified. Please be sure it came from a trusted source or that you have verified the request checksum with the sender. Request subject, to be signed as a client certificate for 3650 days: subject= commonName = yasar Type the word 'yes' to continue, or any other input to abort. Confirm request details: yes Using configuration from /etc/openvpn/easy-rsa/easyrsa3/openssl-1.0.cnf Enter pass phrase for /etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key: Check that the request matches the signature Signature ok The Subject's Distinguished Name is as follows commonName :PRINTABLE:'yasar' Certificate is to be certified until Jan 10 12:49:56 2027 GMT (3650 days) Write out database with 1 new entries Data Base Updated Certificate created at: /etc/openvpn/easy-rsa/easyrsa3/pki/issued/yasar.crt
# 服务端生成的文件(/etc/openvpn/easy-rsa/easyrsa3) ------------------------------------------------------------------------- /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/server.req /etc/openvpn/easy-rsa/easyrsa3/pki/reqs/qingbo.req /etc/openvpn/easy-rsa/easyrsa3/pki/private/ca.key /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt /etc/openvpn/easy-rsa/easyrsa3/pki/issued/qingbo.cr ------------------------------------------------------------------------- # 客户端生成的文件() ------------------------------------------------------------------------- /mnt/client/easy-rsa/easyrsa3/pki/reqs/yasar.req /mnt/client/easy-rsa/easyrsa3/pki/private/yasar.key -------------------------------------------------------------------------
9. 复制服务端配置文件
cp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /etc/openvpn cp /etc/openvpn/easy-rsa/easyrsa3/pki/private/server.key /etc/openvpn cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/server.crt /etc/openvpn cp /etc/openvpn/easy-rsa/easyrsa3/pki/dh.pem /etc/openvpn
10. openvpn服务配置与启动
1.vim /etc/openvpn/ 2.修改server.conf ===================================== local 192.168.1.10 port 1194 proto tcp dev tun ca /etc/openvpn/ca.crt cert /etc/openvpn/server.crt key /etc/openvpn/server.key # This file should be kept secret dh /etc/openvpn/dh.pem server 172.16.10.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "route 192.168.1.0 255.255.255.0" # 推送一个默认路由,使vpn访问192.168.1.0网络通过×××访问 keepalive 30 120 client-to-client # vpn客户端之间可以互相访问 duplicate-cn # 多人使用相同的证书和密钥连接×××,否则只能一人使用 tls-auth /etc/openvpn/ta.key 0 # This file is secret comp-lzo max-clients 30 persist-key persist-tun status /var/log/openvpn-status.log log /var/log/openvpn.log verb 3 ===================================== 3. 启动openvpn服务 /usr/local/openvpn/sbin/openvpn --daemon --config /etc/openvpn/server.conf & 4. 开机启动 echo "/usr/local/openvpn/sbin/openvpn --daemon --config /etc/openvpn/server.conf > /dev/null 2>&1 &" >> /etc/rc.local 5. ps aux|grep openvpn 启动正常的话应该有这个进程
11. 编辑客户端配置文件
cp /usr/local/src/openvpn-2.3.6/sample/sample-config-files/client.conf /mnt/client/client.ovpn vim !$ ====================================== client dev tun proto tcp remote 123.123.x.x 1194 # 此为公网IP,也可以是域名 resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert yasar.crt # 创建的用户证书 key yasar.key # 创建的用户秘钥 remote-cert-tls server tls-auth ta.key 1 comp-lzo verb 3 ======================================
13. 复制客户端配置文件
# 此步骤可以忽略,直接将以下配置文件拷贝到客户端也可以。 mkdir -p /mnt/client/yasar cp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /mnt/client/yasar cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/yasar.crt /mnt/client/yasar cp /mnt/xlmeng/easy-rsa/easyrsa3/pki/private/yasar.key /mnt/client/yasar cp /etc/openvpn/ta.key /mnt/client/yasar/ cp /mnt/client/client.ovpn /mnt/client/yasar/
14. 配置防火墙
[root@localhost ~]# sed -i '/net.ipv4.ip_forward/s/0/1/' /etc/sysctl.conf [root@localhost ~]# sysctl -p # iptables -A FORWARD -i tun0 -o eth0 -j ACCEPT # iptables -A FORWARD -i tun+ -j ACCEPT iptables -A INPUT -i tun+ -j ACCEPT # iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT iptables -I INPUT -p tcp --dport 1194 -m comment --comment "openvpn" -j ACCEPT # iptables -A FORWARD -j REJECT --reject-with icmp-host-prohibited iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to-source 192.168.2.128 # iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE -A INPUT -i tun+ -p tcp --dport 5800:6500 -j ACCEPT -A INPUT -i tun+ -p tcp --dport 22 -j ACCEPT(# 此条可以删除) -A INPUT -p tcp -m tcp --dport 1194 -m comment --comment "openvpn" -j ACCEPT -A FORWARD -i tun+ -p tcp --dport 5800:6500 -j ACCEPT -A FORWARD -i tun+ -p tcp --dport 3389 -j ACCEPT -A FORWARD -i eth0 -p tcp -j ACCEPT -A FORWARD -j REJECT --reject-with icmp-host-prohibited -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
客户端配置:
下载客户端: Open××× 2.3.3 Windows 32位 安装文件: http://swupdate.openvpn.org/community/releases/openvpn-install-2.3.3-I002-i686.exe Open××× 2.3.3 Windows 64位 安装文件:默认安装即可(直接下一步安装)
配置客户端: 将客户端证书ca.crt,yasar.crt,yasar.key,client.ovpn拷贝到客户端C:\Program Files\Open×××\config (可通过windows服务共享文件,然后Centos mount.cifs挂载,此命令需要下载cifs-utils。) 启动openvpnGui程序: 安装完成后右键程序以管理员运行,要不然即使可以获取到IP也无法ping通隧道网关 需要密码的话输入在创建客户端证书输入的密码:11111111
认证方式,通过系统登录用户进行验证:
在server.conf添加三行
# 如果源码包下没有这个文件openvpn-plugin-auth-pam.so,需要在plugins/auth-pam目录下make生成 cp /tmp/openvpn-2.3.6/src/plugins/auth-pam/.libs/openvpn-plugin-auth-pam.so /etc/openvpn/ plugin /etc/openvpn/openvpn-plugin-auth-pam.so login client-cert-not-required username-as-common-name
在客户端修改client.ovpn
ca ca.crt ;cert yasar.crt # 不使用用户证书 ;key yasar.key # 不使用用户秘钥 auth-user-pass
现在打开openvpn客户端以管理员运行程序,输入系统的登录用户和密码就可以了(不能使用root)
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~