Open***应用案例

    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***服务端和客户端都重启一下。服务端增长的的路由:

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了。

相关文章
相关标签/搜索