1. 加密隧道服務概述
- 兩點如何傳輸數(shù)據(jù)最安全
- 方案1: 專線(成本高)
- 方案2: 硬件設備3層路由器 , 硬件vpn設備 vpn virtual private network 虛擬專有網(wǎng)絡 深信服VPN
- 方案3: 開源軟件
- pptp (不推薦) 使用最簡單,不是很穩(wěn)定,依賴于網(wǎng)絡設備的支持.
- OpenVPN 實現(xiàn)用戶/運維/開發(fā),訪問網(wǎng)站內網(wǎng).
2. openVPN應用場景
- 運營:通過OpenVPN實現(xiàn)網(wǎng)站安全登錄:(后臺管理地址,設置為只能能通過vpn訪問.)
- 開發(fā):通過OpenVPN讓開發(fā)與測試人員連接網(wǎng)站,進行開發(fā)測試(在家的時候)
- 運維:通過OpenVPN讓各種用戶(運維)連接網(wǎng)站內網(wǎng)服務器,或者是連接JMS
3. 虛擬機環(huán)境準備
3.0 準備知識
- LAN區(qū)段
- 沒有外網(wǎng)IP,可以理解為一個LAN區(qū)段,作為一個虛擬的交換機連接內內網(wǎng)的設備讓其進行通信
- 在堡壘機中作為內網(wǎng)IP與此同時此虛擬機也有外網(wǎng)IP
- 在配置好VPN之后,VPN客戶端就會訪問內網(wǎng)了
3.1 添加網(wǎng)卡
3.2 配置內網(wǎng)(LAN區(qū)段)
3.3 虛擬機選擇LAN區(qū)段
3.4 書寫eth1網(wǎng)卡配置文件
- 編輯與創(chuàng)建新的網(wǎng)卡配置文件
vim /etc/sysconfig/network-scripts/ifcfg-eth1 TYPE=Ethernet BOOTPROTO=none IPADDR=172.16.1.61 PREFIX=24 NAME=eth1 DEVICE=eth1 ONBOOT=yes
- 然后重啟network:
systemctl restart network
- 檢查ip:
ip a
(如果和配置文件中的IP一致就對了)
4. OpenVPN服務端配置
4.1 環(huán)境準備簡介
- m01 10.0.0.61
環(huán)境準備 | 說明 |
---|---|
oldboy-bao | openvpn server服務端 |
windows 筆記本 | openvpn 客戶端 |
4.2 證書準備流程
1??創(chuàng)建CA證書 ca.crt 公章
2??server密鑰 server.crt server.key服務端使用的畢業(yè)證書
3??client密鑰
4??OpenVPN服務端配置文件
4.2.1 安裝證書創(chuàng)建工具
- 檢查是否可以訪問網(wǎng)絡:
ping baidu.com 結果中只要有time表示可以鏈接
- openvpn 服務端安裝:
yum install -y openvpn easy-rsa
- 檢查是否完成安裝:
rpm -qa openvpn
4.2.2 創(chuàng)建ca證書
4.2.2.1 充當權威機構 修改vars文件
- 創(chuàng)建指令(學安全現(xiàn)階段沒必要弄懂)
#準備目錄 mkdir -p /opt/easy-rsa #已有的內容復制過去 cp -a /usr/share/easy-rsa/3.0.8/* /opt/easy-rsa/ #準備配置文件 cp /usr/share/doc/easy-rsa-3.0.8/vars.example /opt/easy-rsa/vars #書寫配置內容 cat >/opt/easy-rsa/vars<<'EOF' if [ -z "$EASYRSA_CALLER" ]; then echo "You appear to be sourcing an Easy-RSA 'vars' file." >&2 echo "This is no longer necessary and is disallowed. See the section called" >&2 echo "'How to use this file' near the top comments for more details." >&2 return 1 fi set_var EASYRSA_DN "cn_only" set_var EASYRSA_REQ_COUNTRY "CN" set_var EASYRSA_REQ_PROVINCE "Beijing" set_var EASYRSA_REQ_CITY "Beijing" set_var EASYRSA_REQ_ORG "oldboylinux" set_var EASYRSA_REQ_EMAIL "oldboy@qq.com" set_var EASYRSA_NS_SUPPORT "yes" EOF
- 檢查指令
##創(chuàng)建var后 檢查 權威機構信息 cd /opt/easy-rsa tree . ├── easyrsa ├── openssl-easyrsa.cnf ├── vars #var ca權威機構信息 └── x509-types ├── ca ├── client ├── code-signing ├── COMMON ├── email ├── kdc ├── server └── serverClient 1 directory, 11 files
4.2.2.2 充當權威機構 創(chuàng)建ca證書
- 初始化,在當前目錄創(chuàng)建PKI目錄,用于存儲證書
- 命令和結果
cd /opt/easy-rsa ./easyrsa init-pki #初始化,第1次的時候運行,后面不需要重復運行。
結果 Note: using Easy-RSA configuration from: /opt/easy-rsa/vars #正在使用來自于vars init-pki complete; you may now create a CA or requests. #初始化完成 顯示你可以嘗試創(chuàng)建 CA證書 Your newly created PKI dir is: /opt/easy-rsa/pki #初始化后的目錄在 pki下面
- 檢查是否成功:
tree
結果中多了個pki目錄即可。
- 命令和結果
- 創(chuàng)建根證書,會提示設置密碼,用于ca對之后生成的server和client證書簽名時使用,其他可默認
- 命令和結果
./easyrsa build-ca
結果 Note: using Easy-RSA configuration from: /opt/easy-rsa/vars Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017 Enter New CA Key Passphrase: #輸入密碼 并保存好 4-1023位 Re-Enter New CA Key Passphrase: #輸入密碼 并保存好 Generating RSA private key, 2048 bit long modulus .....................................+++ ................................+++ e is 65537 (0x10001) 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]:oldboylinux.cn #域名即可 CA creation complete and you may now import and sign cert requests. Your new CA certificate file for publishing is at: /opt/easy-rsa/pki/ca.crt
- 檢查是否成功:檢查是否有這個文件即可
/opt/easy-rsa/pki/ca.crt
- 命令和結果
4.2.3 創(chuàng)建server端證書和私鑰文件
- 請求蓋章命令和結果
./easyrsa gen-req server nopass
Note: using Easy-RSA configuration from: /opt/easy-rsa/vars Using SSL: openssl OpenSSL 1.0.2k-fips 26 Jan 2017 Generating a 2048 bit RSA private key ....................................+++ .................+++ writing new private key to '/opt/easy-rsa/pki/easy-rsa-2426.tjsuP4/tmp.wLJyRY' ----- 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]: Keypair and certificate request completed. Your files are: req: /opt/easy-rsa/pki/reqs/server.req #server.req 用于 創(chuàng)建證書(證書資料) key: /opt/easy-rsa/pki/private/server.key #server私鑰文件
- 給server端證書簽名,首先是對一些信息的確認,可以輸入yes,然后創(chuàng)建ca根證書時設置的密碼:
./easyrsa sign server server
- 檢查是否操作成功(有結果就成功了)
ll /opt/easy-rsa/pki/issued/server.crt ll /opt/easy-rsa/pki/private/server.key
4.2.4 創(chuàng)建dh-pem 算法文件和目錄匯總
- 創(chuàng)建Diffie-Hellman文件,秘鑰交換時的Diffie-Hellman算法:
/easyrsa gen-dh
(用于存放在服務端,生成一次即可) - 檢查結果:
/opt/easy-rsa/pki/dh.pem
4.2.5 創(chuàng)建client證書
- 創(chuàng)建client端證書和私鑰文件
- 創(chuàng)建client端證書和私鑰文件,nopass表示不加密私鑰文件,其他可默認:
./easyrsa gen-req client nopass
- 給client端證書簽名,首先是對一些信息的確認,可以輸入yes,然后創(chuàng)建ca根證書時設置的密碼:
./easyrsa sign client client
- 創(chuàng)建client端證書和私鑰文件,nopass表示不加密私鑰文件,其他可默認:
- 檢查是否成功:
ll /opt/easy-rsa/pki/private/client.key /opt/easy-rsa/pki/issued/client.crt
4.2.6 匯總
服務端使用的文件 | 客戶端使用的文件 |
---|---|
/opt/easy-rsa/pki/ca.crt | /opt/easy-rsa/pki/ca.crt |
/opt/easy-rsa/pki/dh.pem | |
/opt/easy-rsa/pki/issued/server.crt | /opt/easy-rsa/pki/issued/client.crt |
/opt/easy-rsa/pki/private/server.key | /opt/easy-rsa/pki/private/client.key |
服務端配置文件 | 客戶端配置文件 |
- 目錄匯總
[root@m01 /opt/easy-rsa]# tree . ├── easyrsa ├── openssl-easyrsa.cnf ├── pki │ ├── ca.crt #ca證書 │ ├── dh.pem #df算法文件 │ ├── certs_by_serial │ │ ├── 9F69296953C7B7F6DC39C539706A4CA5.pem │ │ └── C98F71084F5C70CCBFEEA9FCB5E94912.pem │ ├── index.txt │ ├── index.txt.attr │ ├── index.txt.attr.old │ ├── index.txt.old │ ├── issued │ │ ├── client.crt #client證書 │ │ └── server.crt #server證書 │ ├── openssl-easyrsa.cnf │ ├── private │ │ ├── ca.key │ │ ├── client.key #客戶端私鑰 │ │ └── server.key #服務端私鑰 │ ├── renewed │ │ ├── certs_by_serial │ │ ├── private_by_serial │ │ └── reqs_by_serial │ ├── reqs │ │ ├── client.req │ │ └── server.req │ ├── revoked │ │ ├── certs_by_serial │ │ ├── private_by_serial │ │ └── reqs_by_serial │ ├── safessl-easyrsa.cnf │ ├── serial │ └── serial.old ├── vars └── x509-types ├── ca ├── client ├── code-signing ├── COMMON ├── email ├── kdc ├── server └── serverClient 14 directories, 29 file
4.2.7 小結
- 創(chuàng)建vars文件創(chuàng)建ca證書 build-ca
- 創(chuàng)建server證書和私鑰
- gen-req server nopass
- sign server server
- dh.pem 文件
- 創(chuàng)建client證書和私鑰
- gen-req client nopass
- sign client client
4.3 服務端配置文件
#服務端配置文件
#配置文件中 各種路徑默認相對于 /etc/openvpn
4.3.1 書寫openvpn服務端配置文件
-
查看配置文件
[root@m01 ~] tree -F /etc/openvpn/ /etc/openvpn/ ├── client/ └── server/ 2 directories, 0 files
-
配置文件
vim /etc/openvpn/server/server.conf port 1194 proto udp dev tun ca ca.crt cert server/server.crt key server/server.key dh server/dh.pem server 10.8.0.0 255.255.255.0 push "route 172.16.1.0 255.255.255.0" #ifconfig-pool-persist ipp.txt keepalive 10 120 max-clients 100 status /var/log/openvpn-status.log log /var/log/openvpn.log verb 3 client-to-client persist-key persist-tun duplicate-cn
-
配置文件詳解
[root@web01 openvpn]# vim /etc/opnvpn/server/server.conf port 1194 #端口 proto udp #協(xié)議 dev tun #采用路由隧道模式tun ca ca.crt #ca證書文件位置 /etc/openvpn/ca.crt cert server/server.crt #服務端公鑰名稱 /etc/openvpn key server/server.key #服務端私鑰名稱 /etc/openvpn dh server/dh.pem #加密算法文件, 交換證書 校驗算法 #/etc/openvpn/server/dh.pem server 10.8.0.0 255.255.255.0 #給客戶端分配地址池(ip地址范圍),注意:不能和VPN服務器內網(wǎng)網(wǎng)段有相同 push "route 172.16.1.0 255.255.255.0" #客戶端連接后,推送給客戶端的路由規(guī)則 #客戶端想訪問 172.16.1.0/24 網(wǎng)段聯(lián)系openvpn服務端 #ifconfig-pool-persist ipp.txt #地址池記錄文件位置 未來讓openvpn 客戶端固定ip地址使用的. keepalive 10 120 #存活時間,10秒ping一次,120 如未收到響應則視為斷線 max-clients 100 #最多允許100個客戶端連接 status /var/log/openvpn-status.log #日志記錄位置 openvpn狀態(tài) log /var/log/openvpn.log #openvpn日志記錄位置 verb 3 #verbose 日志輸出級別 數(shù)字越大越詳細 最多11(debug) client-to-client #客戶端與客戶端之間支持通信 persist-key #通過keepalive檢測超時后,重新啟動VPN,不重新讀取keys,保留第一次使用的keys 對私鑰進行緩存. persist-tun #檢測超時后,重新啟動VPN,一直保持tun是linkup的。否則網(wǎng)絡會先linkdown然后再linkup duplicate-cn #客戶端密鑰(證書和私鑰)是否可以重復
4.3.2 準備服務端需要的文件
- 復制證書及密鑰
cd /opt/easy-rsa/pki/ \cp ca.crt /etc/openvpn/ \cp dh.pem /etc/openvpn/server/ \cp issued/server.crt private/server.key /etc/openvpn/server/
- 檢查是否操作成功
[root@oldboy-bao pki]# tree -F /etc/openvpn/ /etc/openvpn/ ├── ca.crt ├── client/ └── server/ ├── dh.pem ├── server.conf ├── server.crt └── server.key 2 directories, 5 files
4.3.3 修改systemctl配置文件
- 修改openvpn的systemctl配置文件
vim /usr/lib/systemd/system/openvpn@.service 修改ExecStart這行 在%i前面加上 %i/即可。 修改后的樣子 ExecStart=/usr/sbin/openvpn --cd /etc/openvpn/ --config %i/%i.conf %i表示 server或 client
- 讓linux系統(tǒng)重新加載systemctl配置文件:
systemctl daemon-reload
4.3.4 啟動
systemctl enable openvpn@server
systemctl start openvpn@server
4.3.5 檢查進程與端口
檢查端口
ss -lntup |grep 1194
檢查進程
ps -ef |grep openvpn
檢查ip
ip a s tun0
5. 排障流程
- 檢查配置文件書寫與相關的文件是否存在。
- 查看日志/var/log/openvpn.log.
- 如果不存在查看/var/log/messages
6. 客戶端配置文件
6.1 安裝客戶端
- 默認安裝到C:\Program Files\OpenVPN\
6.2 書寫配置文件
存到臨時目錄
client.ovpn
client
dev tun
proto udp
remote 10.0.0.61 1194
resolv-retry infinite
nobind
ca ca.crt
cert client.crt
key client.key
verb 3
persist-key
########配置說明###################################
client #指定當前VPN是客戶端
dev tun #使用tun隧道傳輸協(xié)議
proto udp #使用udp協(xié)議傳輸數(shù)據(jù)
remote 10.0.0.61 1194 #openvpn服務器IP地址端口號
resolv-retry infinite #斷線自動重新連接,在網(wǎng)絡不穩(wěn)定的情況下非常有用
nobind #不綁定本地特定的端口號
ca ca.crt #指定CA證書的文件路徑
cert client.crt #指定當前客戶端的證書文件路徑
key client.key #指定當前客戶端的私鑰文件路徑
verb 3 #指定日志文件的記錄詳細級別,可選0-9,等級越高日志內容越詳細
persist-key #通過keepalive檢測超時后,重新啟動VPN,不重新讀取keys,保留第一次使用的keys
6.3 準備配置文件需要的文件
sz /opt/easy-rsa/pki/ca.crt
sz /opt/easy-rsa/pki/issued/client.crt
sz /opt/easy-rsa/pki/private/client.key
上傳到windows桌面,避免直接上傳到c盤openvpn目錄。
文章來源:http://www.zghlxwxcb.cn/news/detail-643651.html
6.4 復制對應的文件到config目錄下
- C:\Program Files\OpenVPN
6.5 啟動客戶端
文章來源地址http://www.zghlxwxcb.cn/news/detail-643651.html
- 屏幕輸出,過一會會消失
到了這里,關于網(wǎng)絡安全 Day28-運維安全項目-加密隧道的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!