[Centos]openvpn 服務端的安裝(easy-rsa3),centosopenvpn

來源:互聯網
上載者:User

[Centos]openvpn 服務端的安裝(easy-rsa3),centosopenvpn
VPN在辦公和fan牆領域有著廣泛的應用,  我們小辦公網最近可能會用到,先學學來著
vpn的server需要有公網ip,用戶端可以在多種環境下使用
概念
PKI:Public Key Infrastructure 公開金鑰基礎設施CA: Certificate Authority  pki的核心
https://github.com/OpenVPN/easy-rsa/tree/master/doc  這裡有些簡單的概念介紹

實驗環境虛擬機器環境下 centos6.6
網卡

eth0      Link encap:Ethernet  HWaddr 00:50:56:35:E7:EC            inet addr:192.168.37.129  Bcast:192.168.37.255  Mask:255.255.255.0          inet6 addr: fe80::250:56ff:fe35:e7ec/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:108531 errors:0 dropped:0 overruns:0 frame:0          TX packets:89610 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:82324349 (78.5 MiB)  TX bytes:10389968 (9.9 MiB)

目的: openvpn服務搭建,並可以正常運行(這裡沒有對iptables設定)
安裝依賴包
yum install -y openssl openssl-devel lzo lzo-devel pam pam-devel automake pkgconfigyum install openvpn#openvpn 版本是2.3.6  easy-rsa3

產生認證
#設定檔的目錄一般都在類似的目錄cp /usr/share/doc/openvpn-2.3.6/sample/sample-config-files/server.conf /etc/openvpn/#2.3版本需要獨立下載個easy-rsa,該包用來製作ca認證,服務端認證,用戶端認證wget -c https://github.com/OpenVPN/easy-rsa/archive/master.zipunzip master.zip mv easy-rsa-master easy-rsacp -rf  easy-rsa /etc/openvpneasy-rsa根據github上的文檔來操作cd /etc/openvpn/easy-rsa/easyrsa3cp vars.example vars  #一般情況下,預設的配置可以滿足需求,也可以根據需要修改./easyrsa init-pki   #建立一個空的pki結構,產生一系列的檔案和目錄./easyrsa build-ca   #建立ca  密碼 和 cn那麼需要記住./easyrsa gen-req server nopass  #建立服務端認證  common name 最好不要跟前面的cn那麼一樣./easyrsa sign server server   #簽約服務端認證./easyrsa gen-dh  #建立Diffie-Hellman#下面是用戶端的認證#首先建立一個工作的目錄cd /home/mkdir client && cd clientcp -R ~/easy-rsa/ ./   #這是解壓過的easy-rsa 而不是產生了服務端認證的easy-rsacd easy-rsa/easyrsa3/cp vars.example vars#開始產生./easyrsa init-pki./easyrsa gen-req orangleliu #用自己的名字,需要建立一個密碼  和 cn name,自己用的 需要記住#現在用戶端的認證要跟服務端的互動,也就是簽約,這樣這個使用者才能使用此vpn#切換到server認證目錄下cd /etc/openvpn/easy-rsa/easyrsa3/ ./easyrsa import-req /home/client/easy-rsa/easyrsa3/pki/reqs/orangleliu.req orangleliu  #匯入req./easyrsa sign client orangleliu #使用者簽約,根據提示輸入服務端的ca密碼

看看 /etc/openvpn/easy-rsa/easyrsa3 產生的東西
[root@localhost easyrsa3]# tree pkipki├── ca.crt├── certs_by_serial│   ├── 01.pem│   └── 02.pem├── dh.pem├── index.txt├── index.txt.attr├── index.txt.attr.old├── index.txt.old├── issued│   ├── orangleliu.crt│   └── server.crt├── private│   ├── ca.key│   └── server.key├── reqs│   ├── orangleliu.req│   └── server.req├── serial└── serial.old


再看看用戶端  /home/client/easy-rsa/easyrsa3
pki├── private│   └── orangleliu.key└── reqs    └── orangleliu.req


把這些檔案放到對應的一些目錄下服務端認證(放到設定檔一個目錄,便於配置和尋找)
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/

client認證(只是集中到一個檔案夾下,給vpn使用者使用)
mkdir /home/myclientcp /etc/openvpn/easy-rsa/easyrsa3/pki/ca.crt /home/myclient/cp /etc/openvpn/easy-rsa/easyrsa3/pki/issued/orangleliu.crt  /home/myclient/cp /home/client/easy-rsa/easyrsa3/pki/private/orangleliu.key /home/myclient/

最難的部分已經過去了,下面就是佈建服務,看看效果了佈建服務vim /etc/openvpn/server.conf   具體每個配置的含義,設定檔中都有詳細的解釋

local 192.168.37.129port 1194proto udpdev tunca /etc/openvpn/ca.crtcert /etc/openvpn/server.crtkey /etc/openvpn/server.key  # This file should be kept secretdh /etc/openvpn/dh.pemserver 10.8.0.0 255.255.255.0ifconfig-pool-persist ipp.txtpush "redirect-gateway def1 bypass-dhcp"push "dhcp-option DNS 114.114.114.114"comp-lzomax-clients 100keepalive 10 120persist-keypersist-tunstatus openvpn-status.logverb 3


啟動服務
[root@localhost easyrsa3]# service openvpn startStarting openvpn:                                          [FAILED]


查看開機記錄Options error: Unrecognized option or missing parameter(s) in server.conf:35: kcomp-lzo (2.3.6)
配置中寫錯了。。應該是  comp-lzo
重新啟動
[root@localhost easyrsa3]# service openvpn startStarting openvpn:                                          [  OK  ]


ok了。
ifconfig查看網卡資訊tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00            inet addr:10.8.0.1  P-t-P:10.8.0.2  Mask:255.255.255.255          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1          RX packets:0 errors:0 dropped:0 overruns:0 frame:0          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:100           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

增加了一個10網段
linux下使用openvpn https://openvpn.net/index.php/access-server/docs/admin-guides/182-how-to-connect-to-access-server-with-linux-clients.html ,win7下用戶端有驅動問題,在linux測試vpn服務正常。
參考http://ju.outofmemory.cn/entry/71676http://www.raspberrypi.org/forums/viewtopic.php?p=535351&t=70594



本文出自 “orangleliu筆記本” 部落格,轉載請務必保留此出處http://blog.csdn.net/orangleliu/article/details/43157955

作者orangleliu 採用署名-非商業性使用-相同方式共用協議

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.