มีหลาย ๆ ท่านสอบถามมาเยอะเหลือเกินครับ ว่าจะทำ Linux เป็น VPN Server ได้หรือเปล่า ถ้าทำได้ ทำยังไง เพราะหลาย ๆ ท่านยังคงคุ้นเคยกับหน้ากราฟฟิคของระบบปฏิบัติการวินโดว์ พอมาเจอ Text Mode ถึงกับตกใจกันเป็นแถว
ตัวที่ใช้ทำ vpnserver ก็คือ openvpn นั่นเอง (พูดถึงเรื่องนี้แล้ว ผมเห็นแพ็คเก็จ openvpn-as เลยลองติดตั้งดู โอว มันเป็น vpn ที่บริหารจัดการผ่านเว็บได้เลย แต่เสียดาย ให้ใช้งานได้แค่ 2 user เท่านั้นเอง) ขั้นตอนการติดตั้งก็ไม่ยากเท่าไหร่ ซึ่งผมก็อาศัย rpmforge เป็นตัวช่วยในการติดตั้ง
ข้อมูลเบื้องต้นสำหรับการติดตั้งในครั้งนี้
1. Linux CentOS 5.5 amd 64 ติดตั้งเฉพาะกรุ๊ปแพ็คเก็จ Server เท่านั้น อื่น ๆ ไม่เอาทั้งสิ้น
2. IP Server 192.168.1.10
3. Client เป็น Windows 7 (32bit อืม ลืมบอกไปอย่างผมทดสอบกับ 64 bit ไม่ผ่านนะครับ) ไอพีอะไรก็ได้ ขอให้ Ping เจ้า Server นี่ให้เจอก็พอครับ
ที่เครื่อง Server
1. ดาวน์โหลด repo ได้จากที่นี่ครับ http://packages.sw.be/rpmforge-release/ เลือกให้ตรงกับ OS ของเรา
[root@vpn ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
2. ทำการติดตั้ง repo โดยใช้คำสั่ง rpm
[root@vpn ~]# ls
anaconda-ks.cfg install.log install.log.syslog mbox rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
[root@vpn ~]# rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
warning: rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing… ########################################### [100%]
1:rpmforge-release ########################################### [100%]
[root@vpn ~]#
3. ทำการทดลองค้นหาแพ็คเก็จโดยใช้คำสั่ง yum
[root@vpn ~]# yum search openvpn
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirror.issp.co.th
* base: mirror.issp.co.th
* extras: mirror.issp.co.th
* rpmforge: fr2.rpmfind.net
* updates: mirror.issp.co.th
=============================== Matched: openvpn ===============================
kvpnc.x86_64 : Frontend for various VPN clients
openvpn.x86_64 : secure tunneling daemon
4. เมื่อเจอแพ็คเก็จที่ต้องการแล้ว ก็ให้ทำการติดตั้งได้ทันที ซึ่งการใช้คำสั่ง yum นั้น นอกจากจะติดตั้งแพ็คเก็จที่เราต้องการแล้ว ตัว yum ยังสามารถไปดึงแพ็คเก็จอื่น ๆ ตามที่มันต้องการอีกด้วย ทำให้สะดวกอย่างมากในการติดตั้งซอฟแวร์ต่าง ๆ
[root@vpn ~]# yum -y install openvpn
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirror.issp.co.th
* base: mirror.issp.co.th
* extras: mirror.issp.co.th
* rpmforge: apt.sw.be
* updates: mirror.issp.co.th
rpmforge | 1.1 kB 00:00
rpmforge/primary | 2.1 MB 00:02
rpmforge 10272/10272
Setting up Install Process
Resolving Dependencies
–> Running transaction check
—> Package openvpn.x86_64 0:2.1.4-1.el5.rf set to be updated
–> Processing Dependency: lzo for package: openvpn
–> Processing Dependency: liblzo2.so.2()(64bit) for package: openvpn
–> Running transaction check
—> Package lzo.x86_64 0:2.04-1.el5.rf set to be updated
–> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================
Package Arch Version Repository Size
=====================================================================================
Installing:
openvpn x86_64 2.1.4-1.el5.rf rpmforge 442 k
Installing for dependencies:
lzo x86_64 2.04-1.el5.rf rpmforge 139 k
Transaction Summary
=====================================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 581 k
Downloading Packages:
(1/2): lzo-2.04-1.el5.rf.x86_64.rpm | 139 kB 00:01
(2/2): openvpn-2.1.4-1.el5.rf.x86_64.rpm | 442 kB 00:01
————————————————————————————————————————————————————
Total 187 kB/s | 581 kB 00:03
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : lzo 1/2
Installing : openvpn 2/2
Installed:
openvpn.x86_64 0:2.1.4-1.el5.rf
Dependency Installed:
lzo.x86_64 0:2.04-1.el5.rf
Complete!
[root@vpn ~]#
5. เมื่อติดตั้งเสร็จแล้วจะมีไฟล์ตัวอย่างคอนฟิกบางส่วนอยู่ที่ /usr/share/doc/openvpn-2.1.4/
[root@vpn ~]# cd /usr/share/doc/openvpn-2.1.4/
[root@vpn openvpn-2.1.4]# ls
AUTHORS COPYRIGHT.GPL PORTS README.plugins
ChangeLog easy-rsa README sample-config-files
contrib INSTALL README.auth-pam sample-keys
COPYING NEWS README.down-root sample-scripts
[root@vpn openvpn-2.1.4]#
6. OpenVPN มีความจำเป็นต้องใช้ Certificate ในการยืนยันความน่าเชื่อถือทั้ง Server และ Client ดังนั้นจึงต้องสร้าง Cert ขึ้นมาก่อน โดยทำตามขั้นตอนดังนี้
root@vpn openvpn-2.1.4]# cd easy-rsa/2.0/
[root@vpn 2.0]# ls
build-ca build-inter build-key-pass build-key-server build-req-pass inherit-inter Makefile openssl.cnf README sign-req whichoopensslcnf
build-dh build-key build-key-pkcs12 build-req clean-all list-crl openssl-0.9.6.cnf pkitool revoke-full vars
[root@vpn 2.0]# vi vars
7. แก้ไขไฟล์ vars สำหรับการสร้าง Cert (เฉพาะส่วนที่จำเป็น อยู่ล่างสุดของไฟล์) อาจจะใช้ vi ในการแก้ไข หรือ pico ก็แล้วแต่ถนัดครับ เมื่อแก้ไขเสร็จแล้ว ก็บันทึกแล้วออกจากไฟล์ครับ
# These are the default values for fields
# which will be placed in the certificate.
# Don’t leave any of these fields blank.
export KEY_COUNTRY=”TH”
export KEY_PROVINCE=”Chiangmai”
export KEY_CITY=”Chiangmai”
export KEY_ORG=”RMUTL”
export KEY_EMAIL=”teppap@rmutl.ac.th”
8. เปลี่ยนโหมดของไฟล์ให้สามารถรันได้ดังนี้
[root@vpn 2.0]# chmod +x *
9. สร้าง Cert โดยทำตามขั้นตอนดังต่อไปนี้ มันยาวไปหน่อย ผมจะไฮไลท์ สีแดงกับน้ำเงินให้นะครับ สีแดงคือคำสั่ง สีน้ำเงิน คือสิ่งที่ต้องกรอกครับ
[root@vpn 2.0]# source ./vars
NOTE: If you run ./clean-all, I will be doing a rm -rf on /usr/share/doc/openvpn-2.1.4/easy-rsa/2.0/keys
[root@vpn 2.0]# ./clean-all
[root@vpn 2.0]# ls -l keys/
total 4
-rw-r–r– 1 root root 0 Feb 10 13:21 index.txt
-rw-r–r– 1 root root 3 Feb 10 13:21 serial
[root@vpn 2.0]# ./build-ca
Generating a 1024 bit RSA private key
………………..++++++
……………………………………………………..++++++
writing new private key to ‘ca.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [TH]:
State or Province Name (full name) [Chiangmai]:
Locality Name (eg, city) [Chiangmai]:
Organization Name (eg, company) [RMUTL]:
Organizational Unit Name (eg, section) []:RMUTL
Common Name (eg, your name or your server’s hostname) [RMUTL CA]:vpn.rmutl.ac.th
Name []:vpn.rmutl.ac.th
Email Address [teppap@rmutl.ac.th]:
[root@vpn 2.0]# ls -l keys/
total 12
-rw-r–r– 1 root root 1424 Feb 10 13:22 ca.crt
-rw——- 1 root root 891 Feb 10 13:22 ca.key
-rw-r–r– 1 root root 0 Feb 10 13:21 index.txt
-rw-r–r– 1 root root 3 Feb 10 13:21 serial
[root@vpn 2.0]# ./build-key-server vpn.rmutl.ac.th
Generating a 1024 bit RSA private key
………………………………………………..++++++
………………………….++++++
writing new private key to ‘vpn.rmutl.ac.th.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [TH]:
State or Province Name (full name) [Chiangmai]:
Locality Name (eg, city) [Chiangmai]:
Organization Name (eg, company) [RMUTL]:
Organizational Unit Name (eg, section) []:RMUTL
Common Name (eg, your name or your server’s hostname) [vpn.rmutl.ac.th]:
Name []:vpn.rmutl.ac.th
Email Address [teppap@rmutl.ac.th]:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/share/doc/openvpn-2.1.4/easy-rsa/2.0/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows
countryName :PRINTABLE:’TH’
stateOrProvinceName :PRINTABLE:’Chiangmai’
localityName :PRINTABLE:’Chiangmai’
organizationName :PRINTABLE:’RMUTL’
organizationalUnitName:PRINTABLE:’RMUTL’
commonName :PRINTABLE:’vpn.rmutl.ac.th’
name :PRINTABLE:’vpn.rmutl.ac.th’
emailAddress :IA5STRING:’teppap@rmutl.ac.th’
Certificate is to be certified until Feb 7 06:23:57 2021 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
[root@vpn 2.0]#
[root@vpn 2.0]# ls -l keys/
total 48
-rw-r–r– 1 root root 4200 Feb 10 13:24 01.pem
-rw-r–r– 1 root root 1424 Feb 10 13:22 ca.crt
-rw——- 1 root root 891 Feb 10 13:22 ca.key
-rw-r–r– 1 root root 148 Feb 10 13:24 index.txt
-rw-r–r– 1 root root 21 Feb 10 13:24 index.txt.attr
-rw-r–r– 1 root root 0 Feb 10 13:21 index.txt.old
-rw-r–r– 1 root root 3 Feb 10 13:24 serial
-rw-r–r– 1 root root 3 Feb 10 13:21 serial.old
-rw-r–r– 1 root root 4200 Feb 10 13:24 vpn.rmutl.ac.th.crt
-rw-r–r– 1 root root 745 Feb 10 13:23 vpn.rmutl.ac.th.csr
-rw——- 1 root root 887 Feb 10 13:23 vpn.rmutl.ac.th.key
[root@vpn 2.0]# cat keys/vpn.rmutl.ac.th.key
—–BEGIN RSA PRIVATE KEY—–
MIICXQIBAAKBgQC3FvB9xhcMjFXl/H9cCA5fteVmHwu+BzioudyNMj33zRF11WGK
wYmtp1C2biSHtsm66y4JqE3t6/oNBhKHhtAwpYmDHuHXPo15VKmH/DkaeouROrbc
CYy/eF0dmKc0ugOj4WwjY7233611mKY5wM9acGyEfbVQJioF1mjGV13oTwIDAQAB
AoGAAzlSLsTILx5hfNU/YN17c0/+pBez2zrBUqdDLPFPigeAYTTKrOjPhdFGaI/z
8LfVQYdWnjDqfmADXStYNC65h7oh/Ll5n4jM9nVLPf3ROB1zqGeP7k1ZuzfrQNm0
yGsl870a3vDXUUiLs0A7GsQ4BvNnkb5acLCHjgnEY0oazgECQQDeHY4biDrwtaBJ
cHKNlDo80hl4RpV55pFB6kxtgi03XnixCjlwHEYM97Gklw37/MPoNfIs7gINLDKy
MK2BvaDPAkEA0wVHNkuh+lJ3YOsn1N080fZIdZvJKScp2oDYDfGJFBaNcz33U2gu
288ZmQb2rZNTqdEovP6Ico85VkKCw2oggQJBAJJ9XZcM7wqITzGARxzXEN3CF2g6
7SSbi1u0wjlLLLUiymjA/IbTLuQojHGn6mIyH6bLxXAafSHg74KUFirGPQMCQEWy
gpjOVkulnURnpxpJkGMQ41HlCIYNJ2fCEppYYpw97q5Xky77RC7Zsmy2vhcKiCGY
scnqkAq2f4ucIDCHBwECQQDIWxF7c4QIFdaf4ZWUZGOuo7LO/dsjPiUuyg0FBsA1
lOFAhiCH8ZRErTejC3mLB/HdYL43futnhvix/YEDqoxr
—–END RSA PRIVATE KEY—–
[root@vpn 2.0]# cat keys/vpn.rmutl.ac.th.crt
Certificate:
Data:
Version: 3 (0x2)
Serial Number: 1 (0x1)
Signature Algorithm: sha1WithRSAEncryption
Issuer: C=TH, ST=Chiangmai, L=Chiangmai, O=RMUTL, OU=RMUTL, CN=vpn.rmutl.ac.th/name=vpn.rmutl.ac.th/emailAddress=teppap@rmutl.ac.th
Validity
Not Before: Feb 10 06:23:57 2011 GMT
Not After : Feb 7 06:23:57 2021 GMT
Subject: C=TH, ST=Chiangmai, L=Chiangmai, O=RMUTL, OU=RMUTL, CN=vpn.rmutl.ac.th/name=vpn.rmutl.ac.th/emailAddress=teppap@rmutl.ac.th
Subject Public Key Info:
Public Key Algorithm: rsaEncryption
RSA Public Key: (1024 bit)
Modulus (1024 bit):
00:b7:16:f0:7d:c6:17:0c:8c:55:e5:fc:7f:5c:08:
0e:5f:b5:e5:66:1f:0b:be:07:38:a8:b9:dc:8d:32:
3d:f7:cd:11:75:d5:61:8a:c1:89:ad:a7:50:b6:6e:
24:87:b6:c9:ba:eb:2e:09:a8:4d:ed:eb:fa:0d:06:
12:87:86:d0:30:a5:89:83:1e:e1:d7:3e:8d:79:54:
a9:87:fc:39:1a:7a:8b:91:3a:b6:dc:09:8c:bf:78:
5d:1d:98:a7:34:ba:03:a3:e1:6c:23:63:bd:b7:df:
ad:75:98:a6:39:c0:cf:5a:70:6c:84:7d:b5:50:26:
2a:05:d6:68:c6:57:5d:e8:4f
Exponent: 65537 (0x10001)
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Cert Type:
SSL Server
Netscape Comment:
Easy-RSA Generated Server Certificate
X509v3 Subject Key Identifier:
9B:37:63:86:89:D8:F5:9A:D6:A4:5F:8A:50:3A:E2:67:25:0D:18:14
X509v3 Authority Key Identifier:
keyid:8A:E7:4E:11:35:25:94:5E:F8:D3:E9:62:8E:E4:7B:00:32:57:80:5F
DirName:/C=TH/ST=Chiangmai/L=Chiangmai/O=RMUTL/OU=RMUTL/CN=vpn.rmutl.ac.th/name=vpn.rmutl.ac.th/emailAddress=teppap@rmutl.ac.th
serial:FC:A0:4D:C7:BE:EB:70:EA
X509v3 Extended Key Usage:
TLS Web Server Authentication
X509v3 Key Usage:
Digital Signature, Key Encipherment
Signature Algorithm: sha1WithRSAEncryption
5a:13:d3:d6:95:8c:5e:38:0e:1c:7a:a2:5d:8f:e2:40:0d:ab:
5d:6f:6b:bc:09:fe:bb:97:fc:35:d0:e4:76:e2:1c:6c:c8:75:
60:3f:44:e9:c2:ce:27:08:e4:18:b2:b2:5b:63:9c:6d:c5:36:
7f:5a:5f:d4:b3:dd:5e:2f:35:04:09:c8:11:92:12:a7:64:50:
56:18:cb:4a:f2:8d:b5:6d:b0:11:db:b8:1d:bb:44:9b:ec:11:
99:27:3c:01:8e:b6:a6:b3:ba:26:d1:a9:69:cc:7d:31:2d:bc:
d4:57:10:89:3a:8a:02:a9:da:fc:ca:94:0e:b8:d4:ac:3c:00:
c3:ce
—–BEGIN CERTIFICATE—–
MIIETzCCA7igAwIBAgIBATANBgkqhkiG9w0BAQUFADCBrDELMAkGA1UEBhMCVEgx
EjAQBgNVBAgTCUNoaWFuZ21haTESMBAGA1UEBxMJQ2hpYW5nbWFpMQ4wDAYDVQQK
EwVSTVVUTDEOMAwGA1UECxMFUk1VVEwxGDAWBgNVBAMTD3Zwbi5ybXV0bC5hYy50
aDEYMBYGA1UEKRMPdnBuLnJtdXRsLmFjLnRoMSEwHwYJKoZIhvcNAQkBFhJ0ZXBw
YXBAcm11dGwuYWMudGgwHhcNMTEwMjEwMDYyMzU3WhcNMjEwMjA3MDYyMzU3WjCB
rDELMAkGA1UEBhMCVEgxEjAQBgNVBAgTCUNoaWFuZ21haTESMBAGA1UEBxMJQ2hp
YW5nbWFpMQ4wDAYDVQQKEwVSTVVUTDEOMAwGA1UECxMFUk1VVEwxGDAWBgNVBAMT
D3Zwbi5ybXV0bC5hYy50aDEYMBYGA1UEKRMPdnBuLnJtdXRsLmFjLnRoMSEwHwYJ
KoZIhvcNAQkBFhJ0ZXBwYXBAcm11dGwuYWMudGgwgZ8wDQYJKoZIhvcNAQEBBQAD
gY0AMIGJAoGBALcW8H3GFwyMVeX8f1wIDl+15WYfC74HOKi53I0yPffNEXXVYYrB
ia2nULZuJIe2ybrrLgmoTe3r+g0GEoeG0DCliYMe4dc+jXlUqYf8ORp6i5E6ttwJ
jL94XR2YpzS6A6PhbCNjvbffrXWYpjnAz1pwbIR9tVAmKgXWaMZXXehPAgMBAAGj
ggF9MIIBeTAJBgNVHRMEAjAAMBEGCWCGSAGG+EIBAQQEAwIGQDA0BglghkgBhvhC
AQ0EJxYlRWFzeS1SU0EgR2VuZXJhdGVkIFNlcnZlciBDZXJ0aWZpY2F0ZTAdBgNV
HQ4EFgQUmzdjhonY9ZrWpF+KUDriZyUNGBQwgeEGA1UdIwSB2TCB1oAUiudOETUl
lF740+lijuR7ADJXgF+hgbKkga8wgawxCzAJBgNVBAYTAlRIMRIwEAYDVQQIEwlD
aGlhbmdtYWkxEjAQBgNVBAcTCUNoaWFuZ21haTEOMAwGA1UEChMFUk1VVEwxDjAM
BgNVBAsTBVJNVVRMMRgwFgYDVQQDEw92cG4ucm11dGwuYWMudGgxGDAWBgNVBCkT
D3Zwbi5ybXV0bC5hYy50aDEhMB8GCSqGSIb3DQEJARYSdGVwcGFwQHJtdXRsLmFj
LnRoggkA/KBNx77rcOowEwYDVR0lBAwwCgYIKwYBBQUHAwEwCwYDVR0PBAQDAgWg
MA0GCSqGSIb3DQEBBQUAA4GBAFoT09aVjF44Dhx6ol2P4kANq11va7wJ/ruX/DXQ
5HbiHGzIdWA/ROnCzicI5BiysltjnG3FNn9aX9Sz3V4vNQQJyBGSEqdkUFYYy0ry
jbVtsBHbuB27RJvsEZknPAGOtqazuibRqWnMfTEtvNRXEIk6igKp2vzKlA641Kw8
AMPO
—–END CERTIFICATE—–
[root@vpn 2.0]#
[root@vpn 2.0]#
[root@vpn 2.0]#
[root@vpn 2.0]# ./build-dh
Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
………………………………………………………………++*++*++*
[root@vpn 2.0]#
[root@vpn 2.0]# ls -l keys/
total 52
-rw-r–r– 1 root root 4200 Feb 10 13:24 01.pem
-rw-r–r– 1 root root 1424 Feb 10 13:22 ca.crt
-rw——- 1 root root 891 Feb 10 13:22 ca.key
-rw-r–r– 1 root root 245 Feb 10 13:25 dh1024.pem
-rw-r–r– 1 root root 148 Feb 10 13:24 index.txt
-rw-r–r– 1 root root 21 Feb 10 13:24 index.txt.attr
-rw-r–r– 1 root root 0 Feb 10 13:21 index.txt.old
-rw-r–r– 1 root root 3 Feb 10 13:24 serial
-rw-r–r– 1 root root 3 Feb 10 13:21 serial.old
-rw-r–r– 1 root root 4200 Feb 10 13:24 vpn.rmutl.ac.th.crt
-rw-r–r– 1 root root 745 Feb 10 13:23 vpn.rmutl.ac.th.csr
-rw——- 1 root root 887 Feb 10 13:23 vpn.rmutl.ac.th.key
[root@vpn 2.0]#
[root@vpn 2.0]# ./build-key client
Generating a 1024 bit RSA private key
…………..++++++
………………………….++++++
writing new private key to ‘client.key’
—–
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
—–
Country Name (2 letter code) [TH]:
State or Province Name (full name) [Chiangmai]:
Locality Name (eg, city) [Chiangmai]:
Organization Name (eg, company) [RMUTL]:
Organizational Unit Name (eg, section) []:RMUTL
Common Name (eg, your name or your server’s hostname) [client]:
Name []:
Email Address [teppap@rmutl.ac.th]:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /usr/share/doc/openvpn-2.1.4/easy-rsa/2.0/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject’s Distinguished Name is as follows
countryName :PRINTABLE:’TH’
stateOrProvinceName :PRINTABLE:’Chiangmai’
localityName :PRINTABLE:’Chiangmai’
organizationName :PRINTABLE:’RMUTL’
organizationalUnitName:PRINTABLE:’RMUTL’
commonName :PRINTABLE:’client’
emailAddress :IA5STRING:’teppap@rmutl.ac.th’
Certificate is to be certified until Feb 7 06:27:42 2021 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
[root@vpn 2.0]#
10. ทำการคัดลอก Cert ที่สร้างเสร็จแล้วไปยัง /etc/openvpn/
[root@vpn 2.0]# cp -rf /usr/share/doc/openvpn-2.1.4/easy-rsa/2.0/keys/* /etc/openvpn/
11. ทำการคัดลอกไฟล์ตัวอย่างคอนฟิกของ Server ไปไว้ที่ /etc/openvpn/
[root@vpn 2.0]# cd /etc/openvpn/
[root@vpn openvpn]# cp /usr/share/doc/openvpn-2.1.4/sample-config-files/server.conf /etc/openvpn/
12. ทำการแก้ไขไฟล์ server.conf ที่คัดลอกมาให้เข้ากับเครื่องแม่ข่ายที่ตั้งไว้ (ในการทดสอบนี้ ของ่าย ๆ ก่อนนะครับ ดังนั้นจะแก้แค่ cert
เท่านั้น)
# Any X509 key manateppapgement system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see “pkcs12” directive in man page).
ca ca.crt
cert vpn.rmutl.ac.th.crt
key vpn.rmutl.ac.th.key # This file should be kept secret
# Diffie hellman parameters.
# Generate your own with:
# openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh dh1024.pem
13. สั่งให้ openvpn ทำงานโดยใช้คำสั่งดังนี้
[root@vpn openvpn]# service openvpn start
Starting openvpn: [ OK ]
[root@vpn openvpn]#
15. ตรวจสอบ Interface จะสังเกตุว่ามี Tun เพิ่มขึ้นมา
[root@vpn openvpn]# ifconfig
eth0 Link encap:Ethernet HWaddr C2:DE:48:D6:36:24
inet addr:192.168.1.10 Bcast:10.0.1.255 Mask:255.255.255.0
inet6 addr: fe80::c0de:48ff:fed6:3624/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:76748 errors:0 dropped:0 overruns:0 frame:0
TX packets:8380 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6582338 (6.2 MiB) TX bytes:997841 (974.4 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:560 (560.0 b) TX bytes:560 (560.0 b)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.1 P-t-P:10.8.0.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@vpn openvpn]#
16. ทำการเปิดไฟวอล UTP 1194 (หรือจะลองปิดไปก่อนด้วยคำสั่ง iptables -F สำหรับทดลองใช้งานก่อนก็ได้ครับ
ที่เครื่องลูกข่าย
1. ดาวน์โหลดซอฟแวร์ openvpn client ได้จากที่นี่ http://openvpn.se/download.html (เลือกตัว openvpn-2.0.9-gui-1.0.3-install.exe นะครับ)
2. ทำการติดตั้งตามขั้นตอนปกติ
3. เปิด windows explorer ไปที่ C:\Program Files\OpenVPN\sample-config
4. คัดลอกไฟล์ client.vpn ไปไว้ที่ C:\Program Files\OpenVPN\config
5. คัดลอกไฟล์ client.crt , client.key และ ca.crt ที่สร้างจากเครื่องแม่ข่ายไปไว้ยัง C:\Program Files\OpenVPN\config
6. ทำการแก้ไขไฟล์ C:\Program Files\OpenVPN\config\client.vpn โดยใช้ text editor และทำการแก้ไขดังนี้
.
.
.
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote 192.168.1.10 1194 หมายเหตุ 192.168.1.10 คือไอพีของเครื่องแม่ข่าย
;remote my-server-2 1194
.
.
.
# SSL/TLS parms.
# See the server config file for more
# description. It’s best to use
# a separate .crt/.key file pair
# for each client. A single ca
# file can be used for all clients.
ca ca.crt ชื่อของไฟล์ ทั้ง 3 ไฟล์ ต้องตรงกับที่คัดลอกมาจาก server
cert client.crt
key client.key
7. ที่ system tray จะมีไอคอนของ openvpn คลิ๊กขวาแล้วเลือก connect
8. ถ้าไม่มีข้อผิดพลาด จะปรากฏไอคอนของ openvpn กลายเป็นสีเขียว และแสดงไอพีที่ทำการเชื่อมต่อออกมา

