Open***搭建过程

Open×××简介
×××(virtual private network)是一种利用公共网络设设施创建的私有专线连接技术,也即是常说的“专线”。对于具有多个地区多个分支结构的大型企业,总部与各个地区分支需要使用专线共享数据,而电信企业的专线价格昂贵,×××技术借助公用线路打造私有专线,价格低廉,加密连接同样可以保证数据安全,×××专线是个企业应用的绝佳选择。
Open×××是基于GPL协议开源的×××实现,它可以使用密钥认证、证书认证、账户密码认证。使用openssl进行加密与证书管理可以有效保障专线的数据安全。下图展示了×××的拓扑结构,客户端可以在任意位置连接到×××服务器,***服务器接入公司内网网段,开启路由转发功能后,就可以实现外部客户端机器与内部机器的互联互通,也即可以实现各地区分支与总部的互联互通。

第1章 准备管理服务器
1.1 第一个里程碑——在管理服务器搭建open***
环境需求
管理服务器双网卡:eth0:10.0.0.20(外网)eth1:172.16.1.20(内网)
IDC机房内部局域网服务器只有内网网卡:eth0:172.16.1/24
环境:
管理服务器:eth0:10.0.0.20(外网IP)GW:10.0.0.254 dns:223.5.5.5
eth1:172.16.1.20(内网IP)
GW:不配(一个服务器只在一个网卡上配网关)
提示:检查是否可以ping通IDC局域网内其它服务器 eth0 ip。
IDC局域网内其它服务器
eth0:172.16.1.0/24
GW:管理服务器 eth1网卡IP 172.16.1.20
提示:检查是否可以ping通管理服务器 eth1 ip

我们搭建open***的目的:在远端通过***客户端拨号到管理服务器,然后在笔记本电脑上可以直接访问管理服务器所在局域网内的多个servers,进行管理维护。
第二个里程碑——测试管理服务器的网络连接
测试外网访问
[root@m02_cs7 ~]# ping www.baidu.com
PING www.a.shifen.com (111.13.100.91) 56(84) bytes of data.
64 bytes from 111.13.100.91: icmp_seq=1 ttl=128 time=12.2 ms
64 bytes from 111.13.100.91: icmp_seq=2 ttl=128 time=6.60 ms
64 bytes from 111.13.100.91: icmp_seq=3 ttl=128 time=6.19 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2007ms
rtt min/avg/max/mdev = 6.194/8.357/12.272/2.774 ms
测试内网访问
[root@m02_cs7 ~]# ping 172.16.1.51
PING 172.16.1.51 (172.16.1.51) 56(84) bytes of data.
64 bytes from 172.16.1.51: icmp_seq=1 ttl=64 time=0.561 ms
64 bytes from 172.16.1.51: icmp_seq=2 ttl=64 time=0.469 ms
64 bytes from 172.16.1.51: icmp_seq=3 ttl=64 time=0.903 ms
^C
--- 172.16.1.51 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.469/0.644/0.903/0.187 ms
1.2 第二个里程碑——配置管理服务器的时间同步
因为×××的使用对时间的同步要求还是比较严格的,所以我们提前部署一个时间同步服务。
[root@m02_cs7 ~]# yum install ntp.x86_64 -y
[root@m02_cs7 ~]# sed -i.ori '8s#restrict.*noquery#restrict default nomodify#;22,25d;21a server ntp1.aliyun.com\nserver time.nist.gov' /etc/ntp.conf
说明上面主要修改了配置文件的两个参数
restrict 控制时间服务器的同步权限
server 配置上级时间服务器
1.2.1 启动NTP
[root@m02_cs7 ~]# systemctl start ntpd.service
[root@m02_cs7 ~]# systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: active (running) since Thu 2017-11-23 05:50:57 CST; 7h left
Process: 1652 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 1653 (ntpd)
CGroup: /system.slice/ntpd.service
└─1653 /usr/sbin/ntpd -u ntp:ntp -g

Nov 23 05:50:57 m02_cs7 ntpd[1653]: Listen normally on 6 eth1 fe80::20c:29ff:fe96:59fb UDP 123
Nov 23 05:50:57 m02_cs7 ntpd[1653]: Listen normally on 7 eth0 fe80::20c:29ff:fe96:59f1 UDP 123
Nov 23 05:50:57 m02_cs7 ntpd[1653]: Listening on routing socket on fd #24 for interface updates
Nov 23 05:50:57 m02_cs7 systemd[1]: Started Network Time Service.
Nov 23 05:50:57 m02_cs7 ntpd[1653]: 0.0.0.0 c016 06 restart
Nov 23 05:50:57 m02_cs7 ntpd[1653]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Nov 23 05:50:57 m02_cs7 ntpd[1653]: 0.0.0.0 c011 01 freq_not_set
Nov 23 05:50:59 m02_cs7 ntpd[1653]: 0.0.0.0 c61c 0c clock_step -28658.253672 s
Nov 22 21:53:20 m02_cs7 ntpd[1653]: 0.0.0.0 c614 04 freq_mode
Nov 22 21:53:21 m02_cs7 ntpd[1653]: 0.0.0.0 c618 08 no_sys_peer
1.2.2 查看上级时间服务器的状态
[root@m02_cs7 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter

202.112.26.38 .STEP. 16 u - 64 0 0.000 0.000 0.000
+time5.aliyun.co 10.137.38.86 2 u 14 64 3 27.998 5.096 4.091
time-c-wwv.nist .NIST. 1 u 16 64 1 239.897 8.119 0.000
1.2.3 查看时间同步状态
[root@m02_cs7 ~]# ntpstat
unsynchronised
polling server every 64 s
将时间同步服务加入开机自启动
[root@m02_cs7 ~]# systemctl enable ntpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
1.2.4 管理客户端
管理端生成公钥并分发公钥(在sudo授权的普通用户下操作)
[oldboy@m02_cs7 .ssh]$ ssh-keygen -t dsa -f /home/oldboy/.ssh/id_dsa -P "" -q
[oldboy@m02_cs7 .ssh]$ ls -a
. .. id_dsa id_dsa.pub
[oldboy@m02_cs7 ~]$ sudo yum install sshpass -y
[oldboy@m02_cs7 ~]$ sshpass -p123456 ssh-copy-id -i /home/oldboy/.ssh/id_dsa.pub -p52113 oldboy@172.16.1.51
安装ansible
[oldboy@m02_cs7 ~]$ yum install ansible -y
[oldboy@m02_cs7 ~]$ ansible --version
ansible 2.3.1.0
config file = /etc/ansible/ansible.cfg
configured module search path = Default w/o overrides
python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
测试远程管理
[oldboy@m02_cs7 ~]$ ansible 172.16.1.51 -a 'ls -l /root' -s
172.16.1.51 | SUCCESS | rc=0 >>
total 40
-rw-------. 1 root root 1382 Sep 26 23:12 anaconda-ks.cfg
-rw-r--r--. 1 root root 21921 Sep 26 23:12 install.log
-rw-r--r--. 1 root root 5820 Sep 26 23:10 install.log.syslog
说明:ansible要使用普通用户实现sudo,有三点需要注意:1、ssh通 2、sudo配置了3、用户要有
然后如果不是默认22端口还需要做如下修改
我在/etc/ansible/ansible.cfg配置下面三个地方
sudo_user = oldboy
remote_port = 52113
sudo_exe = sudo
管理端为客户端配置时间同步定时任务
[oldboy@m02_cs7 ~]$ ansible 172.16.1.51 -m cron -a "name='sync time' minute=
/5 job='/usr/sbin/ntpdate 172.16.1.20 >/dev/null 2>&1' state=present" -s
172.16.1.51 | SUCCESS => {
"changed": true,
"envs": [],
"jobs": [
"sync time"
]
}
客户端查看
[oldboy@m02_cs7 ~]$ ansible 172.16.1.51 -m command -a "crontab -l" -s
172.16.1.51 | SUCCESS | rc=0 >>
#Ansible: sync time
/5 /usr/sbin/ntpdate 172.16.1.20 >/dev/null 2>&1
第2章 管理机***配置
检查管理机的网关
[oldboy@m02_cs7 ~]$ sudo route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.254 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.16.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
检查客户端的网关
[oldboy@m02_cs7 ~]$ ansible 172.16.1.51 -m command -a 'route -n' -s
172.16.1.51 | SUCCESS | rc=0 >>
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
说明:默认情况下客户端应该没有配网关才对,将来的网关是某一台出网机器的IP。
2.1 准备安装open***依赖软件
安装lzo压缩模块
mount -t cifs -o username=liqian,password=rwx700 //10.0.0.1/Documents /windows
tar xf lzo-2.06.tar.gz
cd lzo-2.06/
./configure
make && make install
确认系统已经安装openssl
[root@m02_cs7 windows]# rpm -qa|grep openssl
openssl-libs-1.0.1e-42.el7.9.x86_64
openssl-1.0.1e-42.el7.9.x86_64
openssl098e-0.9.8e-29.el7.centos.2.x86_64
还需要安装openssl-devel
yum install openssl-devel -y
说明:不确定的情况也可以使用yum install openssl
-y
2.2 安装open***
cd ../open***-2.2.2/
./configure --with-lzo-headers=/usr/local/include --with-lzo-lib=/usr/local/lib
make && make install
[root@m02_cs7 windows]# which open***
/usr/local/sbin/open***
配置open*** server建立客户端和服务端共用的CA(Certificate Authority)证书
初始化配置命令:
[root@m02_cs7 2.0]# sed -e 's#export KEY_COUNTRY="US"#export KEY_COUNTRY="CN"#g' -e 's#export KEY_PROVINCE="CA"#export KEY_PROVINCE="CA"#g' -e 's#export KEY_CITY="SanFrancisco"#export KEY_CITY="Beijing"#g' -e 's#export KEY_ORG="Fort-Funston"#export KEY_ORG="oldboy"#g' -e 's#export KEY_EMAIL="me@myhost.mydomain"#export KEY_EMAIL="49000448@qq.com"#g' -e 's#export KEY_EMAIL=mail@host.domain#export KEY_EMAIL=49000448@qq.com#g' -e 's#export KEY_CN=changeme#export KEY_CN=CN#g' -e 's#export KEY_NAME=changeme#export KEY_NAME=oldboy#g' -e 's#export KEY_PROVINCE="CA"#export KEY_PROVINCE="BJ"#g' -e 's#export KEY_OU=changeme#export KEY_OU=oldboy#g' vars -i.bak
source使配置文件生效
[root@m02_cs7 2.0]# source vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /windows/open***-2.2.2/easy-rsa/2.0/keys
清除所有原来的key重来
[root@m02_cs7 2.0]# ./clean-all
建立CA证书
[root@m02_cs7 2.0]# ./build-ca
Country Name (2 letter code) [CN]:
State or Province Name (full name) [BJ]:
Locality Name (eg, city) [Beijing]:
Organization Name (eg, company) [oldboy]:
Organizational Unit Name (eg, section) [oldboy]:
Common Name (eg, your name or your server's hostname) [CN]:oldboy
Name [oldboy]:
Email Address [49000448@qq.com]:
检查新生成的证书
[root@m02_cs7 2.0]# ll keys/
total 9
-rwxr-xr-x 1 root root 1310 Dec 5 09:39 ca.crt #ca证书
-rwxr-xr-x 1 root root 916 Dec 5 09:37 ca.key #rsa 私钥
-rwxr-xr-x 1 root root 0 Dec 5 09:36 index.txt
-rwxr-xr-x 1 root root 3 Dec 5 09:36 serial
生成服务器端证书和密钥key文件
[root@m02_cs7 2.0]# ./build-key-server server
Country Name (2 letter code) [CN]:
State or Province Name (full name) [BJ]:
Locality Name (eg, city) [Beijing]:
Organization Name (eg, company) [oldboy]:
Organizational Unit Name (eg, section) [oldboy]:
Common Name (eg, your name or your server's hostname) [server]:
Name [oldboy]:
Email Address [49000448@qq.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456 #客户端发送证书请求时要求的密码
An optional company name []:oldboy
Using configuration from /windows/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BJ'
localityName :PRINTABLE:'Beijing'
organizationName :PRINTABLE:'oldboy'
organizationalUnitName:PRINTABLE:'oldboy'
commonName :PRINTABLE:'server'
name :PRINTABLE:'oldboy'
emailAddress :IA5STRING:'49000448@qq.com'
Certificate is to be certified until Dec 3 01:46:09 2027 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
服务端证书生成后,我们检查keys目录下多了哪些文件
[root@m02_cs7 2.0]# ll keys/
total 26
-rwxr-xr-x 1 root root 3995 Dec 5 09:46 01.pem
-rwxr-xr-x 1 root root 1310 Dec 5 09:39 ca.crt
-rwxr-xr-x 1 root root 916 Dec 5 09:37 ca.key
-rwxr-xr-x 1 root root 120 Dec 5 09:46 index.txt
-rwxr-xr-x 1 root root 21 Dec 5 09:46 index.txt.attr
-rwxr-xr-x 1 root root 0 Dec 5 09:36 index.txt.old
-rwxr-xr-x 1 root root 3 Dec 5 09:46 serial
-rwxr-xr-x 1 root root 3 Dec 5 09:36 serial.old
-rwxr-xr-x 1 root root 3995 Dec 5 09:46 server.crt
-rwxr-xr-x 1 root root 769 Dec 5 09:46 server.csr
-rwxr-xr-x 1 root root 916 Dec 5 09:44 server.key
说明:主要生成的是server.crt server.csr server.key
2.3 生成客户端证书和key文件
生成client证书和key文件。若建立多个客户证书,则重复如下步骤即可。只需修改Comman Name项oldboy的名称。
服务端和客户端共用一个CA证书,服务端有自己的密钥,客户端也有自己的密钥,接下来我们来生成客户端的证书和key文件,类似钥匙的作用,哪个用户想访问***就得拿key访问。
./build-key test #此处我们用的test,生产环境中可以换成不同的人名,供不同的人用
Country Name (2 letter code) [CN]:
State or Province Name (full name) [BJ]:
Locality Name (eg, city) [Beijing]:
Organization Name (eg, company) [oldboy]:
Organizational Unit Name (eg, section) [oldboy]:
Common Name (eg, your name or your server's hostname) [test]:
Name [oldboy]:
Email Address [49000448@qq.com]:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456
An optional company name []:oldboy
Using configuration from /windows/open***-2.2.2/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BJ'
localityName :PRINTABLE:'Beijing'
organizationName :PRINTABLE:'oldboy'
organizationalUnitName:PRINTABLE:'oldboy'
commonName :PRINTABLE:'test'
name :PRINTABLE:'oldboy'
emailAddress :IA5STRING:'49000448@qq.com'
Certificate is to be certified until Dec 3 02:58:27 2027 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
查看生成的客户端证书和key
[root@m02_cs7 2.0]# ll keys/
total 43
-rwxr-xr-x 1 root root 3995 Dec 5 09:46 01.pem
-rwxr-xr-x 1 root root 3871 Dec 5 10:58 02.pem
-rwxr-xr-x 1 root root 1310 Dec 5 09:39 ca.crt
-rwxr-xr-x 1 root root 916 Dec 5 09:37 ca.key
-rwxr-xr-x 1 root root 238 Dec 5 10:58 index.txt
-rwxr-xr-x 1 root root 21 Dec 5 10:58 index.txt.attr
-rwxr-xr-x 1 root root 21 Dec 5 09:46 index.txt.attr.old
-rwxr-xr-x 1 root root 120 Dec 5 09:46 index.txt.old
-rwxr-xr-x 1 root root 3 Dec 5 10:58 serial
-rwxr-xr-x 1 root root 3 Dec 5 09:46 serial.old
-rwxr-xr-x 1 root root 3995 Dec 5 09:46 server.crt
-rwxr-xr-x 1 root root 769 Dec 5 09:46 server.csr
-rwxr-xr-x 1 root root 916 Dec 5 09:44 server.key
-rwxr-xr-x 1 root root 3871 Dec 5 10:58 test.crt
-rwxr-xr-x 1 root root 765 Dec 5 10:58 test.csr
-rwxr-xr-x 1 root root 916 Dec 5 10:56 test.key
如果要密码保护客户端的key,可以使用build-key-pass替代。我们使用这种方式再来创建一份客户端的证书和密钥
[root@m02_cs7 2.0]# ./build-key-pass ett
Generating a 1024 bit RSA private key
............++++++
..............++++++
writing new private key to 'ett.key'
Enter PEM pass phrase: #此处设置的是客户端***拨号时设置的密码
Verifying - Enter PEM pass phrase:

countryName :PRINTABLE:'CN'
stateOrProvinceName :PRINTABLE:'BJ'
localityName :PRINTABLE:'Beijing'
organizationName :PRINTABLE:'oldboy'
organizationalUnitName:PRINTABLE:'oldboy'
commonName :PRINTABLE:'ett'
name :PRINTABLE:'oldboy'
emailAddress :IA5STRING:'49000448@qq.com'
Certificate is to be certified until Dec 3 03:05:27 2027 GMT (3650 days)
Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
查看生成出来的文件
ll keys/
-rwxr-xr-x 1 root root 3870 Dec 5 11:05 ett.crt
-rwxr-xr-x 1 root root 765 Dec 5 11:05 ett.csr
-rwxr-xr-x 1 root root 1041 Dec 5 11:04 ett.key
说明:我们通常在公司里都是为每一个用户创建一个证书和key
2.4 生成generate diffie hellman parameters
生成传输进行密钥交换时用到的交换密钥协议文件,这个步骤是必须做的。
[root@m02_cs7 2.0]# ./build-dh
这个步骤生成的是下面这个文件
[root@m02_cs7 2.0]# ll keys/dh1024.pem
-rwxr-xr-x 1 root root 245 Dec 5 11:21 keys/dh1024.pem
说明:这个文件是一个密钥协议文件。
2.5 详解服务器及客户端的证书各文件用途
Filename Needed By Purpose Secret
ca.crt server + all clients Root CA certificate NO
ca.key key signing machine only Root CA key YES
dh{n}.pem server only Diffie Hellman parameters NO
server.crt server only Server Certificate NO
server.key server only Server Key YES
test.crt test only test Certificate NO
test.key test only test Key YES
ett.crt ett only ett Certificate NO
ett.key ett only ett Key YES
为防止恶意***(如DOS、UDP port flooding),我们生成一个“HMAC firewall”
[root@m02_cs7 2.0]# open*** --genkey --secret keys/ta.key
[root@m02_cs7 2.0]# ll keys/ta.key
-rwxr-xr-x 1 root root 636 Dec 5 19:04 keys/ta.key
至此,大部分服务端的工作已完成,接下来再详细了解服务端的几个常用命令
vars 脚本是用来创建环境变量,设置所需要要的变量的脚本
clean-all 脚本是创建生成ca证书及密钥文件所需要的文件及目录
build-ca 脚本生成ca证书(交互)
build-dh 脚本生成diffie hellman文件(交互)
build-key-server 脚本生成服务端密钥(交互)
build-key 脚本生成客户端密钥(交互)
build-key-pass 脚本生成客户端带密码的密钥(交互)
pkitool 脚本直接使用vars的环境变量设置,直接生成证书(非交互)
2.6 详解服务端××× server.conf重要参数
1) 拷贝keys及配置
把所有的keys和配置拷贝到/etc/open***目录下:
操作命令:
[root@m02_cs7 ~]# mkdir /etc/open***
[root@m02_cs7 ~]# cd /windows/
[root@m02_cs7 windows]# cd open***-2.2.2/easy-rsa/2.0/
[root@m02_cs7 2.0]# \cp -ap keys /etc/open***
[root@m02_cs7 2.0]# cd ../../sample-config-files/
[root@m02_cs7 sample-config-files]# \cp -ap server.conf client.conf /etc/open***/
[root@m02_cs7 sample-config-files]# tree /etc/open***/
/etc/open***/
├── client.conf
├── keys
│ ├── 01.pem
│ ├── 02.pem
│ ├── 03.pem
│ ├── ca.crt
│ ├── ca.key
│ ├── dh1024.pem
│ ├── ett.crt
│ ├── ett.csr
│ ├── ett.key
│ ├── index.txt
│ ├── index.txt.attr
│ ├── index.txt.attr.old
│ ├── index.txt.old
│ ├── serial
│ ├── serial.old
│ ├── server.crt
│ ├── server.csr
│ ├── server.key
│ ├── ta.key
│ ├── test.crt
│ ├── test.csr
│ └── test.key
└── server.conf

1 directory, 24 files
进入/etc/open***编辑服务端配置文件
[root@m02_cs7 open***]# grep -vE ';|^$|#' server.conf.bak > server.conf
配置参数 重要参数
local 10.0.0.20 哪一个本地地址要被Open×××进行监听
port 52115 监听的端口,默认是1194,这里为了安全起见,修改为52115
proto tcp 指定监听的协议,当并发访问多时,推荐tcp
dev tun *** server的模式采用路由模式。可选tap或tun
ca ca.crt ca证书,注意此文件和server.conf在一个目录下,否则要用绝对路径调用
cert server.crt
key server.key
dh dh1024.pem
server 10.8.0.0 255.255.255.0 这个是××× Server动态分配给××× CLIENT的地址池,一般不需要更改。这个段不要和任何网络地址段重复
ifconfig-pool-persist ipp.txt
push "route 172.16.1.0 255.255.255.0" 这是××× Server所在的内网网段,如果有多个可以写多个push,注意,此命令实际作用是在***客户端本地生成××× Server所在的内网网段路由,确保能够和××× Server所在的内网网段通信。路由条目类似 10.0.0.0 255.255.255.0 10.8.0.9 10.8.0.10 1
老男孩经验:如果想知道×××到底在本地加了哪些路由,可以在拨号前笔记本上命令行执行route print记录下所有路由条目,然后在拨号后记录下所有路由条目,然后用比较软件比较下即可知道变化。
client-to-client 允许拨号的多个*** client互相通信
duplicate-cn 允许多个客户端使用同一个帐号连接
keepalive 10 120 每10秒ping一次,若是120秒未收到包,即认定客户端断线
comp-lzo 开启压缩功能
persist-key 当***超时后,当重新启动×××后,保持上一次使用的私钥,而不重新读取私钥
persist-tun 通过keepalive检测***超时后,当重新启动×××后,保持tun或者tap设备自动连接状态
status open***-status.log open***日志状态信息
log /var/log/open***.log 日志文件
verb 3 指定日志文件冗余
提示:先执行export LANG="ZH_GB18030",然后编辑配置文件server.conf,清空所有内容,把上面内容拷贝进来。然后执行,dos2unix server.conf。
server.conf做如下修改:
[root@m02_cs7 open***]# less server.conf
local 10.0.0.200
port 52115
proto tcp
dev tun
ca /etc/open***/keys/ca.crt
cert /etc/open***/keys/server.crt
key /etc/open***/keys/server.key
dh /etc/open***/keys/dh1024.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
comp-lzo
persist-key
persist-tun
status open***-status.log
verb 3
client-to-client
duplicate-cn
log /var/log/open***.log
2.7 调试服务端×××服务启动环境
a) 取消服务器上防火墙iptables对Open***的拦截,以及允许服务进行转发。
[root@m02_cs7 open***]# iptables -A INPUT -p tcp --dport 52115 -j ACCEPT
[root@m02_cs7 /]# iptables -A FORWARD -p tcp --dport 52115 -j ACCEPT
[root@m02_cs7 open***]# iptables -nL
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:52115

Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:52115

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@m02_cs7 open***]# iptables-save > /etc/sysconfig/iptables
b) 开启内核转发功能。
[root@m02_cs7 open***]# sed '$a net.ipv4.ip_forward = 1' /etc/sysctl.conf -i.bak
[root@m02_cs7 open***]# sysctl -p
net.ipv4.ip_forward = 1
当然我们最好先把防火墙停掉,把open***配置好后,再配置防火墙,否则一旦出现什么问题很难判断是***配置问题还是防火墙配置问题。
[root@m02_cs7 /]# systemctl stop iptables
2.8 启动服务端的×××服务并检查
c) 启动×××服务
/usr/local/sbin/open*** --config /etc/open***/server.conf &
netstat -ltunp|grep ***
tcp 0 0 10.0.0.200:52115 0.0.0.0:* LISTEN 1848/open***
如果看到端口,说明***启动成功
放到rc.local中,以便开机启动
如果起不来,也可以通过查看日志
tail -100 /var/log/open***.log
排查问题
***启动以后本地会多一个虚拟网卡
ip a s
4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
link/none
inet 10.8.0.1 peer 10.8.0.2/32 scope global tun0
valid_lft forever preferred_lft forever
第3章 安装Windows ×××客户端配置
3.1 下载并安装open***客户端
从http://build.open***.net/downloads/releases/ 上下载与open***服务器版本一致的Windows客户端“Open××× GUI For Windows”(在国内下载需要先“×××”)
windows客户端的安装步骤很简单,默认下一步即可,唯一要注意的是如下图选择信任并安装

然后在桌面可以看到客户端的快捷方式,双击后,会在电脑右下角出现类似的小电脑图标

3.2 为客户端配置***的证书和key
cp ../client.conf ../client.conf.bak
[root@m02_cs7 keys]# egrep -v '^;|^#|^$' ../client.conf.bak > ../client.conf
[root@m02_cs7 keys]# vim ../client.conf
client
dev tun
proto tcp
remote 10.0.0.200 52115
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert test.crt
key test.key
ns-cert-type server
comp-lzo
verb 3
[root@m02_cs7 keys]# \cp ../client.conf test.o***
[root@m02_cs7 keys]# mkdir -p /windows/test && \cp ca.crt test.crt test.key test.o*** /windows/test/
在windows客户端查看

当然上面这些文件最终需要放到C:\Program Files (x86)\Open×××\config目录下
3.3 在win 7上拨号远程连接open***服务
在右下角图标选择Connect

连上后出现如下提示,即表示连接成功并分配了一个IP地址10.8.0.6

拨号的过程也可以查看日志

在服务端也能看到客户端的连接情况:
tail /var/log/open***.log
Wed Dec 6 10:25:13 2017 10.0.0.1:51213 [test] Peer Connection Initiated with 10.0.0.1:51213
Wed Dec 6 10:25:13 2017 test/10.0.0.1:51213 MULTI: Learn: 10.8.0.6 -> test/10.0.0.1:51213
Wed Dec 6 10:25:13 2017 test/10.0.0.1:51213 MULTI: primary virtual IP for test/10.0.0.1:51213: 10.8.0.6
Wed Dec 6 10:25:16 2017 test/10.0.0.1:51213 PUSH: Received control message: 'PUSH_REQUEST'
Wed Dec 6 10:25:16 2017 test/10.0.0.1:51213 SENT CONTROL [test]: 'PUSH_REPLY,route 172.16.1.0 255.255.255.0,route 10.8.0.0 255.255.255.0,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5' (status=1)

转载于:https://blog.51cto.com/102060321/2047635

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值