Open×××服務器的搭建:http://qicheng0211.blog.51cto.com/3958621/1575273shell
CentOS下Open×××客戶端配置:http://qicheng0211.blog.51cto.com/3958621/1840055vim
應用一、點對點安全通道
安全
工做中可能會遇到這樣的場景:因爲業務須要,異地兩臺服務器須要安全的相互訪問,除了拉專線,比較經濟的方法就是經過公網創建加密隧道,open***是一個很好的選擇。bash
服務端:內網IP 192.168.20.220,***服務端口1194經過防火牆映射到公網。服務器
客戶端:內網IP 192.168.1.220。網絡
點對點網絡的配置主要在於服務端,客戶端無需特殊配置。app
編輯服務端配置文件server.conf:
運維
shell> vim /etc/open***/server.conf port 1194 proto tcp dev tun ca keys/ca.crt cert keys/server.crt key keys/server.key # This file should be kept secret dh keys/dh2048.pem server 10.8.0.0 255.255.255.0 # 虛擬局域網網段,不要和實際的局域網衝突 push "route 192.168.20.220 255.255.255.255" # 推送給客戶端的路由設置(服務端的IP/32) route 192.168.1.220 255.255.255.255 # 服務端到客戶端的路由(客戶端的IP/32) client-config-dir /etc/open***/ccd # 客戶端獨立配置文件目錄 keepalive 10 120 tls-auth keys/ta.key 0 # This file is secret comp-lzo persist-key persist-tun status open***-status.log log-append open***.log verb 5
在服務器上編輯client1的獨立配置文件:tcp
shell> mkdir /etc/open***/ccd shell> vim /etc/open***/ccd/client1 iroute 192.168.1.220 255.255.255.255
客戶端配置文件client.o***:
ide
client dev tun proto tcp remote xxx.xxx.xxx.xxx 1194 # open***服務端映射到公網的IP和端口 resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert client1.crt # 客戶端client1的證書文件 key client1.key # 客戶端client1的密鑰文件 remote-cert-tls server tls-auth ta.key 1 comp-lzo verb 3
open***服務端和客戶端都重啓一下。服務端增長的的路由:
客戶端增長的路由:
測試兩端互ping、互相登陸都沒問題。
應用二、客戶端安全接入服務器局域網
情景:IDC機房網絡有兩個網段(vlan20、40),各vlan互通,現須要一個運維跳板機,運維經過跳板機管理vlan20和vlan40服務器。
爲實現上述目的,咱們在機房內搭建一臺open***服務器,客戶端經過***服務器接入IDC機房內網。
服務端配置文件server.conf:
port 1194 proto tcp dev tun ca keys/ca.crt cert keys/server.crt key keys/server.key # This file should be kept secret dh keys/dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "route 192.168.20.0 255.255.254.0" # 推送給客戶端的路由設置(vlan20:192.168.20.0/23) push "route 192.168.40.0 255.255.254.0" # 推送給客戶端的路由設置(vlan40:192.168.40.0/23) keepalive 10 120 tls-auth keys/ta.key 0 # This file is secret comp-lzo persist-key persist-tun status open***-status.log log-append open***.log verb 5
服務端添加iptables規則使服務器能夠轉發數據包(對網段10.8.0.0/24的數據包作SNAT):
shell> iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE shell> service iptables save
客戶端配置文件跟上個案例同樣,無須更改配置。
客戶端啓動後,咱們看下路由,到服務器端局域網的路由已經設置好了:
應用三、客戶端經過服務器訪問Internet
爲啥這麼作你們都懂,省略1萬字。
服務端配置文件server.conf:
port 1194 proto tcp dev tun ca keys/ca.crt cert keys/server.crt key keys/server.key # This file should be kept secret dh keys/dh2048.pem server 10.8.0.0 255.255.255.0 ifconfig-pool-persist ipp.txt push "redirect-gateway def1 bypass-dhcp" # 改客戶端的默認網關 push "dhcp-option DNS 114.114.114.114" # 爲客戶端設置DNS服務器(對非win客戶端無效) push "dhcp-option DNS 8.8.8.8" keepalive 10 120 tls-auth keys/ta.key 0 # This file is secret comp-lzo persist-key persist-tun status open***-status.log log-append open***.log verb 5
服務端添加iptables規則使服務器能夠轉發數據包(對網段10.8.0.0/24的數據包作SNAT):
shell> iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE shell> service iptables save
客戶端配置文件無須更改。咱們再看一下客戶端的路由:
客戶端路由增長了一條走×××的默認路由,出口IP也變成了服務器端的出口IP了。