Open***應用案例

    Open***服務器的搭建:http://qicheng0211.blog.51cto.com/3958621/1575273

    CentOS下Open***客戶端配置:http://qicheng0211.blog.51cto.com/3958621/1840055

應用一、點對點安全通道

    工作中可能會遇到這樣的場景:由於業務需要,異地兩臺服務器需要安全的相互訪問,除了拉專線,比較經濟的方法就是通過公網建立加密隧道,open***是一個很好的選擇。

    服務端:內網IP 192.168.20.220,***服務端口1194通過防火牆映射到公網。

    客戶端:內網IP 192.168.1.220。

    點對點網絡的配置主要在於服務端,客戶端無需特殊配置。

    編輯服務端配置文件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的獨立配置文件:

shell> mkdir /etc/open***/ccd
shell> vim /etc/open***/ccd/client1
iroute 192.168.1.220 255.255.255.255

    客戶端配置文件client.o***:

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***服務端和客戶端都重啓一下。服務端增加的的路由:

wKioL1e1iGzAs0BJAAAl6BdH97s627.png

    客戶端增加的路由:

wKiom1e1iHSySg2KAAAch1mhToY894.png

    測試兩端互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

    客戶端配置文件跟上個案例一樣,無須更改配置。

    客戶端啓動後,我們看下路由,到服務器端局域網的路由已經設置好了:

wKiom1e2n-KQjpnmAAAaJaO_U1M754.png

應用、客戶端通過服務器訪問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

    客戶端配置文件無須更改。我們再看一下客戶端的路由:

wKiom1e2uD_wfbmjAAAwxbkghi8989.png

   客戶端路由增加了一條走***的默認路由,出口IP也變成了服務器端的出口IP了。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章