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 [email protected]
安裝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="[email protected]"#export KEY_EMAIL="[email protected]"#g' -e 's#export [email protected]#export [email protected]#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 [[email protected]]:
檢查新生成的證書
[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 [[email protected]]:

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:'[email protected]'
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 [[email protected]]:

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:'[email protected]'
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:'[email protected]'
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)

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