<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaLinux.com - สปาลีนุกซ์ &#187; VPN</title>
	<atom:link href="http://spalinux.com/category/vpn/feed" rel="self" type="application/rss+xml" />
	<link>http://spalinux.com</link>
	<description>เพื่อชีวิตที่ผ่อนคลายของคนใช้ลีนุกซ์</description>
	<lastBuildDate>Sat, 12 May 2012 10:38:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>คอนฟิก OpenVPN แบบ Multiple Client – ตอนที่ 2</title>
		<link>http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_2</link>
		<comments>http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_2#comments</comments>
		<pubDate>Sat, 01 Nov 2008 14:46:50 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[VPN]]></category>
		<category><![CDATA[openvpn]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=326</guid>
		<description><![CDATA[ต่อจากบทความ คอนฟิก OpenVPN แบบ Multiple Client &#8211; ตอนที่ 1 ในตอนที่ 2 นี้จะอธิบายการแก้ไขไฟล์คอนฟิก เพื่อทำหน้าที่เป็น VPN Client และ Server คอนฟิก OpenVPN Server  (VPN Server) จากการติดตั้ง openvpn จะมีตัวอย่างไฟล์คอนฟิกเพื่อช่วยในการเริ่มต้นคอนฟิก โดยจะมีหลายไฟล์เหมาะกับการคอนฟิกแบบต่างๆ อยู่ในไดเร็คทอรี /usr/share/doc/openvpn-2.1/sample-config-files/ สำหรับ OpenVPN Server แบบ Multiple Client จะใช้ไฟล์คอนฟิกตัวอย่างคือ server.conf โดยต้อง copy ไฟล์ไปไว้ใน /etc/openvpn/ ตัวอย่างการสร้างไฟล์คอนฟิกของ OpenVPN Server ในที่นี้จะตั้งชื่อไฟล์เป็น vpn-server.conf [root@vpn-server ~]# cd /etc/openvpn/ [root@vpn-server openvpn]# cp /usr/share/doc/openvpn-2.1/sample-config-files/server.conf vpn-server.conf copy ไฟล์ [...]]]></description>
			<content:encoded><![CDATA[<p>ต่อจากบทความ <a href="http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_1">คอนฟิก OpenVPN แบบ Multiple Client &#8211; ตอนที่ 1</a> ในตอนที่ 2 นี้จะอธิบายการแก้ไขไฟล์คอนฟิก เพื่อทำหน้าที่เป็น VPN Client และ Server</p>
<p><span id="more-326"></span></p>
<h4>คอนฟิก OpenVPN Server  (VPN Server)</h4>
<p>จากการติดตั้ง openvpn จะมีตัวอย่างไฟล์คอนฟิกเพื่อช่วยในการเริ่มต้นคอนฟิก โดยจะมีหลายไฟล์เหมาะกับการคอนฟิกแบบต่างๆ อยู่ในไดเร็คทอรี  /usr/share/doc/openvpn-2.1/sample-config-files/</p>
<p>สำหรับ OpenVPN Server แบบ Multiple Client จะใช้ไฟล์คอนฟิกตัวอย่างคือ server.conf โดยต้อง copy ไฟล์ไปไว้ใน /etc/openvpn/</p>
<p>ตัวอย่างการสร้างไฟล์คอนฟิกของ OpenVPN Server ในที่นี้จะตั้งชื่อไฟล์เป็น vpn-server.conf</p>
<pre>[root@vpn-server ~]# <strong>cd /etc/openvpn/
</strong>[root@vpn-server openvpn]# <strong>cp /usr/share/doc/openvpn-2.1/sample-config-files/server.conf vpn-server.conf</strong></pre>
<p>copy ไฟล์ Certificate, Privte Key และไฟล์ dh1024.pem ที่สร้างสำหรับ OpenVPN Server จากเครื่อง CA มาวางไว้ใน /etc/openvpn/</p>
<pre>[root@vpn-server openvpn]# <strong>ls -l
</strong>-rw-r--r-- 1 root root 9998 2008-10-31 17:54 vpn-server.conf
-rw-r--r-- 1 root root 1245 2008-10-31 17:51 ca.crt
-rw-r--r-- 1 root root  245 2008-10-31 17:51 dh1024.pem
-rw-r--r-- 1 root root 3922 2008-10-31 17:52 vpn-server.crt
-rw------- 1 root root  887 2008-10-31 17:52 vpn-server.key</pre>
<p>แก้ไขไฟล์ vpn-server.conf  โดยส่วนที่ต้องแก้คือชื่อไฟล์สำหรับเก็บคีย์ต่างๆ และ IP Address สำหรับเน็ตเวิร์กที่ VPN ใช้  ในที่นี้จะเลือกใช้ 10.1.1.0</p>
<p>ตัวอย่างไฟล์ /etc/openvpn/vpn-server.conf</p>
<pre>#
# VPN Server Configuration
# /etc/openvpn/vpn-server.conf
#
port 1194
proto udp
dev tun</pre>
<pre>ca ca.crt
cert vpn-server.crt
key vpn-server.key
dh dh1024.pem</pre>
<pre>server 10.1.1.0 255.255.255.0
ifconfig-pool-persist ipp.txt
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb 3</pre>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส openvpn</p>
<pre>[root@vpn-server openvpn]# <strong>service openvpn start
</strong>Starting openvpn:                                          [  OK  ]</pre>
<p>สามารถตรวจสอบผลการรันเซอร์วิส openvpn หากมีปัญหาต่างๆ ได้จากไฟล์ /var/log/messages</p>
<p>ตัวอย่างไฟล์ /var/log/messages ถ้ารันเซอร์วิส openvpn เพื่อทำหน้าที่เป็น OpenVPN Server ได้อย่างถูกต้อง</p>
<pre>[root@vpn-server openvpn]# <strong>tail –f /var/log/messages
</strong>Oct 31 18:29:51 vpn-server openvpn[3509]: OpenVPN 2.1_rc8 i386-redhat-linux-gnu [SSL] [LZO2] [EPOLL] built on Jun 14 2008
Oct 31 18:29:51 vpn-server openvpn[3509]: Diffie-Hellman initialized with 1024 bit key
Oct 31 18:29:51 vpn-server openvpn[3509]: TLS-Auth MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Oct 31 18:29:51 vpn-server kernel: tun0: Disabled Privacy Extensions
Oct 31 18:29:51 vpn-server openvpn[3509]: TUN/TAP device tun0 opened
Oct 31 18:29:51 vpn-server openvpn[3509]: TUN/TAP TX queue length set to 100
Oct 31 18:29:51 vpn-server openvpn[3509]: /sbin/ip link set dev tun0 up mtu 1500
Oct 31 18:29:51 vpn-server openvpn[3509]: /sbin/ip addr add dev tun0 local 10.1.1.1 peer 10.1.1.2
Oct 31 18:29:51 vpn-server openvpn[3509]: /sbin/ip route add 10.1.1.0/24 via 10.1.1.2
Oct 31 18:29:51 vpn-server openvpn[3509]: Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Oct 31 18:29:51 vpn-server openvpn[3519]: Socket Buffers: R=[110592-&gt;131072] S=[110592-&gt;131072]
Oct 31 18:29:51 vpn-server openvpn[3519]: UDPv4 link local (bound): [undef]:1194
Oct 31 18:29:51 vpn-server openvpn[3519]: UDPv4 link remote: [undef]
Oct 31 18:29:51 vpn-server openvpn[3519]: MULTI: multi_init called, r=256 v=256
Oct 31 18:29:51 vpn-server openvpn[3519]: IFCONFIG POOL: base=10.1.1.4 size=62
Oct 31 18:29:51 vpn-server openvpn[3519]: IFCONFIG POOL LIST
Oct 31 18:29:51 vpn-server openvpn[3519]: Initialization Sequence Completed
Oct 31 18:29:52 vpn-server ntpd[2606]: Listening on interface #23 tun0, 10.1.1.1#123 Enabled</pre>
<p>เมื่อรันเซอร์วิส openvpn เรียบร้อย จะมีอินเตอร์เฟสใหม่ถูกสร้างขึ้นมา สามารถใช้คำสั่ง ifconfig และ netstat -rn เพื่อตรวจสอบได้</p>
<pre>[root@vpn-server openvpn]# <strong>ifconfig</strong>
...
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.1.1.1  P-t-P:10.1.1.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-server openvpn]# <strong>netstat -rn</strong>
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.1.2        *               255.255.255.255 UH    0      0        0 tun0
10.1.1.0        10.1.1.2        255.255.255.0   UG    0      0        0 tun0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     0      0        0 eth0</pre>
<p>นอกจากนี้จะมีไฟล์ชื่อ openvpn-status แสดงสถานะของ VPN ถูกเก็บอยู่ใน /etc/openvpn/</p>
<p>ตัวอย่างไฟล์ openvpn-status.log ตอนที่ยังไม่มีไคลเอนต์เครื่องใดเชื่อมต่อ VPN เข้ามา</p>
<pre>[root@vpn-server openvpn]# <strong>cat /etc/openvpn/openvpn-status.log
</strong>OpenVPN CLIENT LIST
Updated,Fri Oct 31 18:31:01 2008
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
GLOBAL STATS
Max bcast/mcast queue length,0
END</pre>
<h4>คอนฟิก OpenVPN Client (VPN Client)</h4>
<p>สำหรับ OpenVPN Client เครื่องต่างๆ จะใช้ไฟล์คอนฟิกตัวอย่างคือ client.conf โดยต้อง copy ไฟล์ไปไว้ใน /etc/openvpn/</p>
<p>ตัวอย่างการสร้างไฟล์คอนฟิกของ OpenVPN Client #1 ในที่นี้จะตั้งชื่อไฟล์เป็น vpn-client1.conf</p>
<pre>[root@vpn-server ~]# <strong>cd /etc/openvpn/
</strong>[root@vpn-server openvpn]# <strong>cp /usr/share/doc/openvpn-2.1/sample-config-files/server.conf vpn-client1.conf</strong></pre>
<p>copy ไฟล์ Certificate, Privte Key และไฟล์ dh1024.pem ที่สร้างสำหรับ OpenVPN Client #1 จากเครื่อง CA มาวางไว้ใน /etc/openvpn/ ด้วย</p>
<pre>[root@vpn-client1 openvpn]# <strong>ls -l
</strong>-rw-r--r-- 1 root root  262 2008-10-31 18:34 vpn-client1.conf
-rw-r--r-- 1 root root 1245 2008-10-31 17:53 ca.crt
-rw-r--r-- 1 root root 3805 2008-10-31 17:53 vpn-client1.crt
-rw------- 1 root root  887 2008-10-31 17:53 vpn-client1.key</pre>
<p>แก้ไขไฟล์ vpn-client1.conf  โดยส่วนที่ต้องแก้คือชื่อไฟล์สำหรับเก็บคีย์ต่างๆ และ IP Address จริง ของ OpenVPN Server ในที่นี้คือ 192.168.1.1</p>
<p>ตัวอย่างไฟล์ /etc/openvpn/vpn-client1.conf</p>
<pre>#
# OpenVPN Client #1 Configuration
# /etc/openvpn/vpn-client1.conf
#
client
dev tun</pre>
<pre>proto udp
remote 192.168.1.1 1194</pre>
<pre>resolv-retry infinite
nobind
persist-key
persist-tun</pre>
<pre>ca ca.crt
cert vpn-client1.crt
key vpn-client1.key</pre>
<pre>comp-lzo
verb 3</pre>
<p>ใช้คำสั่ง service เพื่อรันเซอร์วิส openvpn ทำหน้าที่เป็น OpenVPN Client เครื่องที่ 1</p>
<pre>[root@vpn-client1 openvpn]# <strong>service openvpn start
</strong>Starting openvpn:                                          [  OK  ]</pre>
<p>สามารถตรวจสอบไฟล์ /var/log/messages เพื่อดูผลการรัน openvpn ได้</p>
<p>ตัวอย่างไฟล์ /var/log/messages ในกรณีที่รัน openvpn เพื่อทำหน้าที่เป็น OpenVPN Client ได้อย่างถูกต้อง</p>
<pre>[root@vpn-client1 openvpn]# <strong>tail -f /var/log/messages
</strong>Oct 31 18:36:18 vpn-client1 openvpn[2705]: OpenVPN 2.1_rc8 i386-redhat-linux-gnu [SSL] [LZO2] [EPOLL] built on Jun 14 2008
Oct 31 18:36:18 vpn-client1 openvpn[2705]: WARNING: No server certificate verification method has been enabled.  See http://openvpn.net/howto.html#mitm for more info.
Oct 31 18:36:18 vpn-client1 openvpn[2705]: LZO compression initialized
Oct 31 18:36:18 vpn-client1 openvpn[2705]: Control Channel MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Oct 31 18:36:18 vpn-client1 openvpn[2705]: Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Oct 31 18:36:18 vpn-client1 openvpn[2705]: Local Options hash (VER=V4): '41690919'
Oct 31 18:36:18 vpn-client1 openvpn[2705]: Expected Remote Options hash (VER=V4): '530fdded'
Oct 31 18:36:18 vpn-client1 openvpn[2707]: Socket Buffers: R=[110592-&gt;131072] S=[110592-&gt;131072]
Oct 31 18:36:18 vpn-client1 openvpn[2707]: UDPv4 link local: [undef]
Oct 31 18:36:18 vpn-client1 openvpn[2707]: UDPv4 link remote: 192.168.1.1:1194
Oct 31 18:36:18 vpn-client1 openvpn[2707]: TLS: Initial packet from 192.168.1.1:1194, sid=06a517e0 1a81cb8b
Oct 31 18:36:18 vpn-client1 openvpn[2707]: VERIFY OK: depth=1, /C=TH/ST=Nonthaburi/L=Pak_Kret/O=My Company Name/CN=My Company Name_CA/emailAddress=info@my-vpn-network.com
Oct 31 18:36:18 vpn-client1 openvpn[2707]: VERIFY OK: depth=0, /C=TH/ST=Nonthaburi/L=Pak_Kret/O=My Company Name/CN=vpn-server/emailAddress=info@my-vpn-network.com
Oct 31 18:36:18 vpn-client1 openvpn[2707]: Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Oct 31 18:36:18 vpn-client1 openvpn[2707]: Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Oct 31 18:36:18 vpn-client1 openvpn[2707]: Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Oct 31 18:36:18 vpn-client1 openvpn[2707]: Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Oct 31 18:36:18 vpn-client1 openvpn[2707]: Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Oct 31 18:36:18 vpn-client1 openvpn[2707]: [vpn-server] Peer Connection Initiated with 192.168.1.1:1194
Oct 31 18:36:20 vpn-client1 openvpn[2707]: SENT CONTROL [vpn-server]: 'PUSH_REQUEST' (status=1)
Oct 31 18:36:20 vpn-client1 openvpn[2707]: PUSH: Received control message: 'PUSH_REPLY,route 10.1.1.1,topology net30,ping 10,ping-restart 120,ifconfig 10.1.1.6 10.1.1.5'
Oct 31 18:36:20 vpn-client1 openvpn[2707]: OPTIONS IMPORT: timers and/or timeouts modified
Oct 31 18:36:20 vpn-client1 openvpn[2707]: OPTIONS IMPORT: --ifconfig/up options modified
Oct 31 18:36:20 vpn-client1 openvpn[2707]: OPTIONS IMPORT: route options modified
Oct 31 18:36:20 vpn-client1 kernel: tun0: Disabled Privacy Extensions
Oct 31 18:36:20 vpn-client1 openvpn[2707]: TUN/TAP device tun0 opened
Oct 31 18:36:20 vpn-client1 openvpn[2707]: TUN/TAP TX queue length set to 100
Oct 31 18:36:20 vpn-client1 openvpn[2707]: /sbin/ip link set dev tun0 up mtu 1500
Oct 31 18:36:20 vpn-client1 openvpn[2707]: /sbin/ip addr add dev tun0 local 10.1.1.6 peer 10.1.1.5
Oct 31 18:36:20 vpn-client1 openvpn[2707]: /sbin/ip route add 10.1.1.1/32 via 10.1.1.5
Oct 31 18:36:20 vpn-client1 openvpn[2707]: Initialization Sequence Completed</pre>
<p>ถ้ารันไคลเอนต์ได้อย่างถูกต้อง จะมีอินเตอร์เฟส ใหม่ถูกสร้างขึ้นมา สามารถตรวจสอบได้จากคำสั่ง ifconfig และ netstat –rn</p>
<pre>[root@vpn-client1 openvpn]# <strong>ifconfig
</strong>…
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:10.1.1.6  P-t-P:10.1.1.5  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)</pre>
<pre>[root@vpn-client1 openvpn]# <strong>netstat -rn
</strong>Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.1.1.5        *               255.255.255.255 UH    0      0        0 tun0
10.1.1.1        10.1.1.5        255.255.255.255 UGH   0      0        0 tun0
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
link-local      *               255.255.0.0     U     0      0        0 eth0</pre>
<p>ใช้คำสั่ง ping เพื่อทดสอบการส่งข้อมูลผ่าน VPN ไปยัง VPN Server</p>
<pre>[root@vpn-client1 openvpn]# <strong>ping -n 10.1.1.1
</strong>PING 10.1.1.1 (10.1.1.1) 56(84) bytes of data.
64 bytes from 10.1.1.1: icmp_seq=1 ttl=64 time=1.10 ms
64 bytes from 10.1.1.1: icmp_seq=2 ttl=64 time=0.822 ms
64 bytes from 10.1.1.1: icmp_seq=3 ttl=64 time=1.07 ms
^C
--- 10.1.1.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2407ms
rtt min/avg/max/mdev = 0.822/1.000/1.103/0.131 ms</pre>
<p>สำหรับ VPN Cilent เครื่องอื่นๆ สามารถคอนฟิกในทำนองเดียวกัน เพียงแต่ต้องใช้ Certificate และ Private Key สำหรับไคลเอนต์เครื่องต่างๆ</p>
<h4>ตรวจสอบสถานะการเชื่อมต่อ VPN บนเครื่อง Server</h4>
<p>ตัวอย่างไฟล์ /var/log/messages ที่เกิดขึ้นบนเครื่อง OpenVPN Server เมื่อมีการเชื่อมต่อ VPN มาจาก OpenClient</p>
<pre>[root@vpn-server openvpn]# <strong>tail -f /var/log/messages
</strong>Oct 31 18:36:18 vpn-server openvpn[3519]: MULTI: multi_create_instance called
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Re-using SSL/TLS context
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 LZO compression initialized
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Control Channel MTU parms [ L:1542 D:138 EF:38 EB:0 ET:0 EL:0 ]
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Data Channel MTU parms [ L:1542 D:1450 EF:42 EB:135 ET:0 EL:0 AF:3/1 ]
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Local Options hash (VER=V4): '530fdded'
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Expected Remote Options hash (VER=V4): '41690919'
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 TLS: Initial packet from 192.168.1.101:51931, sid=75f786a8 cd2868f2
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 VERIFY OK: depth=1, /C=TH/ST=Nonthaburi/L=Pak_Kret/O=My Company Name/CN=My Company Name_CA/emailAddress=info@my-vpn-network.com
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 VERIFY OK: depth=0, /C=TH/ST=Nonthaburi/L=Pak_Kret/O=My Company Name/CN=vpn-client1/emailAddress=info@my-vpn-network.com
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Data Channel Encrypt: Cipher 'BF-CBC' initialized with 128 bit key
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Data Channel Encrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Data Channel Decrypt: Cipher 'BF-CBC' initialized with 128 bit key
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Data Channel Decrypt: Using 160 bit message hash 'SHA1' for HMAC authentication
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
Oct 31 18:36:18 vpn-server openvpn[3519]: 192.168.1.101:51931 [vpn-client1] Peer Connection Initiated with 192.168.1.101:51931
Oct 31 18:36:18 vpn-server openvpn[3519]: vpn-client1/192.168.1.101:51931 MULTI: Learn: 10.1.1.6 -&gt; vpn-client1/192.168.1.101:51931
Oct 31 18:36:18 vpn-server openvpn[3519]: vpn-client1/192.168.1.101:51931 MULTI: primary virtual IP for vpn-client1/192.168.1.101:51931: 10.1.1.6
Oct 31 18:36:20 vpn-server openvpn[3519]: vpn-client1/192.168.1.101:51931 PUSH: Received control message: 'PUSH_REQUEST'
Oct 31 18:36:20 vpn-server openvpn[3519]: vpn-client1/192.168.1.101:51931 SENT CONTROL [vpn-client1]: 'PUSH_REPLY,route 10.1.1.1,topology net30,ping 10,ping-restart 120,ifconfig 10.1.1.6 10.1.1.5' (status=1)</pre>
<p>ตัวอย่างไฟล์ openvpn-status.log เมื่อมีการเชื่อมต่อจาก VPN Client เรียบร้อยแล้ว</p>
<pre>[root@vpn-server ~]# <strong>cat /etc/openvpn/openvpn-status.log
</strong>OpenVPN CLIENT LIST
Updated,Fri Oct 31 18:39:18 2008
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
vpn-client1,192.168.1.101:51931,5563,6519,Fri Oct 31 18:36:18 2008
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
10.1.1.6,vpn-client1,192.168.1.101:51931,Fri Oct 31 18:38:59 2008
GLOBAL STATS
Max bcast/mcast queue length,0
END</pre>
<p>ทดสอบ ping จากเครื่องเซิร์ฟเวอร์กลับไปยังไคลเอนต์ผ่านทาง VPN ได้</p>
<pre>[root@vpn-server ~]# <strong>ping -n 10.1.1.6
</strong>PING 10.1.1.6 (10.1.1.6) 56(84) bytes of data.
64 bytes from 10.1.1.6: icmp_seq=1 ttl=64 time=0.816 ms
64 bytes from 10.1.1.6: icmp_seq=2 ttl=64 time=0.624 ms
^C
--- 10.1.1.6 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1303ms
rtt min/avg/max/mdev = 0.624/0.720/0.816/0.096 ms</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_1">คอนฟิก OpenVPN แบบ Multiple Client &#8211; ตอนที่ 1<br />
</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_2/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>คอนฟิก OpenVPN แบบ Multiple Client &#8211; ตอนที่ 1</title>
		<link>http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_1</link>
		<comments>http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_1#comments</comments>
		<pubDate>Fri, 31 Oct 2008 19:05:50 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[VPN]]></category>
		<category><![CDATA[openvpn]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=321</guid>
		<description><![CDATA[จากบทความเรื่อง คอนฟิก OpenVPN แบบ Static Key บน Fedora Linux ที่กล่าวถึงการสร้าง VPN เพื่อเชื่อมโยงระหว่างเครื่องสองเครื่องแบบหนึ่งต่อหนี่งนั้น ในทางปฎิบัติจะไม่สะดวกในการนำไปใช้กับเครือข่ายที่มีขนาดใหญ่ ที่มีการเชื่อมโยง VPN ระหว่างหลายๆ เครื่องเข้าด้วยกัน ในบทความนี้จะอธิบายการคอนฟิก OpenVPN แบบ Multiple Clients เพื่อเชื่อมโยง VPN หลายๆ เครื่องเข้าด้วยกัน ในลักษณะที่ เครื่องหนึ่งทำหน้าที่เป็น VPN Server รองรับการสร้าง VPN มาจาก VPN Client หลายๆ เครื่อง ซึ่งสามารถนำไปดัดแปลงใช้กับเครือข่ายที่มีลักษณะเป็นสำนักงานใหญ่ และสาขากระจายไปตามจุดต่างๆ ได้ การคอนฟิกแบบ Multiple Client นี้ จะใช้หลักการของ Public/Private key และ Certificate Authority (CA) เพื่อตรวจสอบคีย์ของเครื่องที่ต้องการเชื่อมต่อว่าถูกต้องหรือไม่ ก่อนที่จะอนุญาตให้สร้าง VPN ระหว่าง [...]]]></description>
			<content:encoded><![CDATA[<p>จากบทความเรื่อง <a href="http://spalinux.com/2008/06/howto_configure_openvpn_static_key_on_fedora_linux">คอนฟิก OpenVPN แบบ Static Key บน Fedora Linux</a> ที่กล่าวถึงการสร้าง VPN เพื่อเชื่อมโยงระหว่างเครื่องสองเครื่องแบบหนึ่งต่อหนี่งนั้น  ในทางปฎิบัติจะไม่สะดวกในการนำไปใช้กับเครือข่ายที่มีขนาดใหญ่ ที่มีการเชื่อมโยง VPN ระหว่างหลายๆ เครื่องเข้าด้วยกัน</p>
<p>ในบทความนี้จะอธิบายการคอนฟิก OpenVPN แบบ Multiple Clients เพื่อเชื่อมโยง VPN หลายๆ เครื่องเข้าด้วยกัน ในลักษณะที่ เครื่องหนึ่งทำหน้าที่เป็น VPN Server รองรับการสร้าง VPN มาจาก VPN Client หลายๆ เครื่อง ซึ่งสามารถนำไปดัดแปลงใช้กับเครือข่ายที่มีลักษณะเป็นสำนักงานใหญ่ และสาขากระจายไปตามจุดต่างๆ ได้</p>
<p>การคอนฟิกแบบ Multiple Client นี้ จะใช้หลักการของ Public/Private key และ Certificate Authority (CA) เพื่อตรวจสอบคีย์ของเครื่องที่ต้องการเชื่อมต่อว่าถูกต้องหรือไม่ ก่อนที่จะอนุญาตให้สร้าง VPN  ระหว่าง Server และ Client แต่ละเครื่องได้</p>
<p><span id="more-321"></span></p>
<h4>ระบบที่ทดสอบ</h4>
<ul>
<li>เครื่อง vpn-server  ทำหน้าที่เป็น VPN Server มี IP Address คือ 192.168.1.1</li>
<li>เครื่อง vpn-client1, vpn-client2, vpn-client3 เป็น VPN Client เครื่องที่ 1, 2, 3 ..และมี IP Address คือ 192.168.1.101, 192.168.1.102, 192.168.1.103</li>
</ul>
<p>หมายเหตุ</p>
<ul>
<li>ในแต่ละหัวข้อจะมีวงเล็บอยู่ด้วย เพื่อบอกว่าขั้นตอนนั้น ต้องทำบนเครื่องใดบ้าง</li>
<li>เพื่อความสะดวก วงเล็บ (CA) ให้รันคำสั่งบนเครื่อง vpn-server</li>
</ul>
<h4>ติดตั้งโปรแกรม OpenVPN (ทุกเครื่อง)</h4>
<p>ติดตั้งโปรแกรม OpenVPN บนเครื่องทุกเครื่องทั้งเซิร์ฟเวอร์และไคลเอนต์ ถ้าใช้ Fedora 9 ไฟล์ที่ติดตั้งอยู่ในแผ่นดีวีดีติดตั้งอยู่แล้ว</p>
<p>ตัวอย่างการติดตั้ง OpenVPN บน Fedora 9</p>
<pre>[root@vpn-server Packages]# <strong>rpm -ivh openvpn-2.1-0.25.rc7.fc9.i386.rpm
</strong>error: Failed dependencies:
        liblzo2.so.2 is needed by openvpn-2.1-0.25.rc7.fc9.i386</pre>
<p>หากตอนติดตั้งเจอข้อความฟ้องเรื่อง Failed dependencies แบบด้านบน ต้องติดตั้งโปรแกรม lzo ก่อน แล้วค่อยติดตั้ง openvpn อีกที</p>
<pre>[root@vpn-server Packages]# <strong>rpm -ivh lzo-2.02-4.fc9.i386.rpm
</strong>Preparing...                ########################################### [100%]
   1:lzo                    ########################################### [100%]
[root@vpn-server Packages]# <strong>rpm -ivh openvpn-2.1-0.25.rc7.fc9.i386.rpm</strong>
Preparing...                ########################################### [100%]
   1:openvpn                ########################################### [100%]</pre>
<h4>เซ็ตอัป OpenVPN Certificate Authority  (CA)</h4>
<p>เริ่มต้นเราต้องเซ็ตอัป Certificate Authority (CA) ขึ้นมา เพื่อใช้ในการสร้าง Public/Private Key และ Certificate สำหรับเซิร์ฟเวอร์และไคลเอนต์  ในที่นี้เพื่อความสะดวก เราจะรันคำสั่งเพื่อเซ็ตอัปบนเครื่องเดียวกับ VPN Server</p>
<p>จากการติดตั้งโปรแกรม OpenVPN จะมีสคริปต์ที่ใช้ในการสร้าง CA อยู่ในไดเร็คทอรี /usr/share/openvpn/easy-rsa/2.0/ ในนี้จะมีหลายๆ ไฟล์ และต้องทำหลายขั้นตอนดังนี้</p>
<p>แก้ไขในส่วนด้านล่างของไฟล์ &#8220;vars&#8221; เพื่อระบุข้อมูลของหน่วยงานเรา เช่นชื่อบริษัท สถานที่ตั้ง โดยข้อมูลเหล่านี้จะถูกเก็บไว้ในไฟล์ Certificate</p>
<p>ตัวอย่างส่วนของไฟล์ &#8220;vars&#8221; ที่มีการแก้ไข</p>
<pre>[root@vpn-server ~]# <strong>cd /usr/share/openvpn/easy-rsa/2.0/
</strong>[root@vpn-server 2.0]# <strong>cat vars</strong>
...
# 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="Nonthaburi"
export KEY_CITY="Pak Kret"
export KEY_ORG="My Company Name"
export KEY_EMAIL="info@my-vpn-network.com"</pre>
<p>หลังแก้ไขไฟล์ &#8220;vars&#8221; ให้รันคำสั่งต่อไปนี้ เพื่อเตรียมไดเร็คทอรีและไฟล์ที่จำเป็นในการสร้าง CA</p>
<pre>[root@vpn-server 2.0]# <strong>source ./vars</strong>
NOTE: If you run ./clean-all, I will be doing a rm -rf on /usr/share/openvpn/easy-rsa/2.0/keys</pre>
<pre>[root@vpn-server 2.0]# <strong>./clean-all</strong></pre>
<pre>[root@vpn-server 2.0]# <strong>ls -l keys/
</strong>total 4
-rw-r--r-- 1 root root 0 2008-10-31 17:45 index.txt
-rw-r--r-- 1 root root 3 2008-10-31 17:45 serial</pre>
<p>ใช้คำสั่ง &#8220;build-ca&#8221; เพื่อสร้าง CA</p>
<pre>[root@vpn-server 2.0]# <strong>./build-ca
</strong>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) [Nonthaburi]:
Locality Name (eg, city) [Pak Kret]:
Organization Name (eg, company) [My Company Name]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [My Company Name CA]:
Email Address [info@my-vpn-network.com]:</pre>
<p>ไฟล์ของ CA ที่ถูกสร้างขึ้นจะถูกเก็บไว้ในไดเร็คทอรี &#8220;keys/&#8221; โดยจะมีไฟล์ &#8220;ca.crt&#8221; ซึ่งเป็นไฟล์ Certiifacate ของ CA และไฟล์ &#8220;ca.key&#8221; ซึ่งเป็นไฟล์ Private Key ของ CA</p>
<p>ข้อควรระวัง ไฟล์ที่ลงท้ายด้วย &#8220;.key&#8221; ในการคอนฟิก OpenVPN ส่วนมากจะเป็นไฟล์ที่เก็บ Private Key ซึ่งต้องเป็นความลับ ไม่ให้คนอื่นสามารถดูไฟล์นี้ได้ ยกเว้น root เพราะฉะนั้นสิทธิ (permission) ของไฟล์นี้ต้องเป็น 600</p>
<p>ตัวอย่างไฟล์ที่ถูกสร้างขึ้นจากคำสั่ง &#8220;build-ca&#8221;</p>
<pre>[root@vpn-server 2.0]# <strong>ls -l keys/
</strong>total 12
-rw-r--r-- 1 root root 1245 2008-10-31 17:46 ca.crt
-rw------- 1 root root  891 2008-10-31 17:46 ca.key
-rw-r--r-- 1 root root    0 2008-10-31 17:45 index.txt
-rw-r--r-- 1 root root    3 2008-10-31 17:45 serial</pre>
<p>ตัวอย่างบางส่วนของไฟล์ &#8220;ca.crt&#8221;</p>
<pre>[root@vpn-server 2.0]# <strong>cat keys/ca.crt
</strong>-----BEGIN CERTIFICATE-----
MIIFaTdC...
...
-----END CERTIFICATE-----</pre>
<p>ตัวอย่างบางส่วนของไฟล์ &#8220;ca.key&#8221;</p>
<pre>[root@vpn-server 2.0]# <strong>cat keys/ca.key</strong>
-----BEGIN RSA PRIVATE KEY-----
MIIBAAKB...
...
-----END RSA PRIVATE KEY-----</pre>
<h4>สร้าง Certificate และ Private Key สำหรับ Server (CA)</h4>
<p>ใช้คำสั่ง &#8220;build-key-server&#8221; ตามด้วยชื่อเครื่องเซิร์ฟเวอร์ เพื่อทำการสร้าง Certificate และ Private Kye สำหรับใช้กับ VPN Server โดยไฟล์ที่สร้างได้จะถูกเก็บไว้ในไดเร็คทอรี &#8220;keys/&#8221; และตั้งชื่อตามชื่อเครื่องเซิร์ฟเวอร์ที่เราระบุไว้</p>
<p>ตัวอย่างการใช้คำสั่ง &#8220;build-key-server&#8221; เพื่อสร้าง Certificate และ Private Key ของเครื่อง vpn-server</p>
<pre>[root@vpn-server 2.0]# <strong>./build-key-server vpn-server</strong>
Generating a 1024 bit RSA private key
.....++++++
............++++++
writing new private key to 'vpn-server.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) [Nonthaburi]:
Locality Name (eg, city) [Pak Kret]:
Organization Name (eg, company) [My Company Name]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [vpn-server]:
Email Address [info@my-vpn-network.com]:</pre>
<pre>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/openvpn/easy-rsa/2.0/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'TH'
stateOrProvinceName   <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'Nonthaburi'
localityName          <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'Pak Kret'
organizationName      <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'My Company Name'
commonName            <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'vpn-server'
emailAddress          :IA5STRING:'info@my-vpn-network.com'
Certificate is to be certified until Oct 29 10:48:18 2018 GMT (3650 days)
Sign the certificate? [y/n]:<strong>y</strong></pre>
<pre>1 out of 1 certificate requests certified, commit? [y/n]<strong>y
</strong>Write out database with 1 new entries
Data Base Updated</pre>
<p>ตัวอย่างบางส่วนของไฟล์ &#8220;vpn-server.crt&#8221;  (Certificate ของเครื่อง vpn-server)</p>
<pre>[root@vpn-server openvpn]# <strong>cat keys/vpn-server.crt
</strong>Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 1 (0x1)
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=TH, ST=Nonthaburi, L=Pak Kret, O=My Company Name, CN=My Company Name CA/emailAddress=info@my-vpn-network.com
        Validity
            Not Before: Oct 31 10:48:18 2008 GMT
            Not After : Oct 29 10:48:18 2018 GMT
        Subject: C=TH, ST=Nonthaburi, L=Pak Kret, O=My Company Name, CN=vpn-server/emailAddress=info@my-vpn-network.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (1024 bit)
                Modulus (1024 bit):
                    00:bb:fd:...
                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:
                0A:BB:...
            X509v3 Authority Key Identifier:
                keyid:6D:C8:...
                DirName:/C=TH/ST=Nonthaburi/L=Pak Kret/O=My Company Name/CN=My Company Name <a href="mailto:CA/emailAddress=info@my-vpn-network.com">CA/emailAddress=info@my-vpn-network.com</a>
                serial:87:1D:...</pre>
<pre>            X509v3 Extended Key Usage:
                TLS Web Server Authentication
            X509v3 Key Usage:
                Digital Signature, Key Encipherment
    Signature Algorithm: sha1WithRSAEncryption
        4e:44:...
         ...
-----BEGIN CERTIFICATE-----
MIIDaTCC...
...
-----END CERTIFICATE-----</pre>
<p>ตัวอย่างบางส่วนของไฟล์ &#8220;vpn-server.key&#8221;  (Private Key ของเครื่อง vpn-server) ไฟล์นี้ต้องมี permission เป็น 600</p>
<pre>[root@vpn-server openvpn]# <strong>cat keys/vpn-server.key
</strong>-----BEGIN RSA PRIVATE KEY-----
MIIWwIBA
...
-----END RSA PRIVATE KEY-----</pre>
<h4>สร้างไฟล์ Diffie Hellman parameters (CA)</h4>
<pre>[root@vpn-server 2.0]# <strong>./build-dh
</strong>Generating DH parameters, 1024 bit long safe prime, generator 2
This is going to take a long time
..................+..+..</pre>
<pre>[root@vpn-server 2.0]# <strong>cat keys/dh1024.pem</strong>
-----BEGIN DH PARAMETERS-----
MIGHAoGB...
...
-----END DH PARAMETERS-----</pre>
<h4>สร้าง Certificate และ Private Key สำหรับ Client  (CA)</h4>
<p>ใช้คำสั่ง &#8220;build-key&#8221; ตามด้วยชื่อเครื่องไคลเอนต์แต่ะละเครื่อง เพื่อสร้าง Certificate และ Private Kye สำหรับใช้กับ VPN Client โดยไฟล์ที่สร้างได้จะถูกเก็บไว้ในไดเร็คทอรี &#8220;keys/&#8221; และตั้งชื่อตามชื่อเครื่องไคลเอนต์ที่เราระบุไว้</p>
<p>ตัวอย่างการใช้คำสั่ง &#8220;build-key&#8221; เพื่อสร้าง Certiifacte และ Private Key ให้เครื่อง vpn-client1</p>
<pre>[root@vpn-server 2.0]# <strong>./build-key vpn-client1
</strong>Generating a 1024 bit RSA private key
........++++++
..........++++++
writing new private key to 'vpn-client1.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) [Nonthaburi]:
Locality Name (eg, city) [Pak Kret]:
Organization Name (eg, company) [My Company Name]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) [vpn-client1]:
Email Address [info@my-vpn-network.com]:</pre>
<pre>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/openvpn/easy-rsa/2.0/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'TH'
stateOrProvinceName   <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'Nonthaburi'
localityName          <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'Pak Kret'
organizationName      <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'My Company Name'
commonName            <img src='http://spalinux.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> RINTABLE:'vpn-client1'
emailAddress          :IA5STRING:'info@my-vpn-network.com'
Certificate is to be certified until Oct 29 10:49:13 2018 GMT (3650 days)
Sign the certificate? [y/n]:<strong>y</strong></pre>
<pre>1 out of 1 certificate requests certified, commit? [y/n]<strong>y
</strong>Write out database with 1 new entries
Data Base Updated</pre>
<p>ตัวอย่างบางส่วนของไฟล์ &#8220;vpn-client1.crt&#8221;  (Certificate ของเครื่อง vpn-client1)</p>
<pre>[root@vpn-client1 openvpn]# <strong>cat keys/vpn-client1.crt
</strong>Certificate:
    Data:
        Version: 3 (0x2)
        Serial Number: 2 (0x2)
        Signature Algorithm: sha1WithRSAEncryption
        Issuer: C=TH, ST=Nonthaburi, L=Pak Kret, O=My Company Name, CN=My Company Name CA/emailAddress=info@my-vpn-network.com
        Validity
            Not Before: Oct 31 10:49:13 2008 GMT
            Not After : Oct 29 10:49:13 2018 GMT
        Subject: C=TH, ST=Nonthaburi, L=Pak Kret, O=My Company Name, CN=vpn-client1/emailAddress=info@my-vpn-network.com
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
            RSA Public Key: (1024 bit)
                Modulus (1024 bit):
                    00:c0:...
                    ...
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Basic Constraints:
                CA:FALSE
            Netscape Comment:
                Easy-RSA Generated Certificate
            X509v3 Subject Key Identifier:
                35:1C:...
            X509v3 Authority Key Identifier:
                keyid:6D:C8:...
                DirName:/C=TH/ST=Nonthaburi/L=Pak Kret/O=My Company Name/CN=My Company Name CA/emailAddress=info@my-vpn-network.com
                serial:87:1D:...</pre>
<pre>            X509v3 Extended Key Usage:
                TLS Web Client Authentication
            X509v3 Key Usage:
                Digital Signature
    Signature Algorithm: sha1WithRSAEncryption
        2e:31:...
        ...
-----BEGIN CERTIFICATE-----
MIIsTCCx...
...
-----END CERTIFICATE-----</pre>
<p>ตัวอย่างบางส่วนของไฟล์ &#8220;vpn-client1.key&#8221;  (Private Key ของเครื่อง vpn-client1) ไฟล์นี้ต้องมี permission เป็น 600</p>
<pre>[root@vpn-client1 openvpn]# <strong>cat keys/vpn-client1.key
</strong>-----BEGIN RSA PRIVATE KEY-----
MIICXBAA
...
-----END RSA PRIVATE KEY-----</pre>
<h4>สรุปตัวอย่างไฟล์ keys ที่ถูกสร้างบน CA</h4>
<p>ตัวอย่างไฟล์ keys ทั้งหมดที่สร้างได้บน CA สำหรับเครื่องเซิร์ฟเวอร์ vpn-server และเครื่องไคลเอนต์ vpn-client1, vpn-client2, vpn-client3</p>
<pre>[root@vpn-server 2.0]# <strong>ls -l keys/
</strong>total 100
-rw-r--r-- 1 root root 3922 2008-10-31 17:48 01.pem
-rw-r--r-- 1 root root 3805 2008-10-31 17:49 02.pem
-rw-r--r-- 1 root root 3805 2008-10-31 17:49 03.pem
-rw-r--r-- 1 root root 3805 2008-10-31 17:50 04.pem
-rw-r--r-- 1 root root 1245 2008-10-31 17:46 ca.crt
-rw------- 1 root root  891 2008-10-31 17:46 ca.key
-rw-r--r-- 1 root root  245 2008-10-31 17:50 dh1024.pem
-rw-r--r-- 1 root root  463 2008-10-31 17:50 index.txt
-rw-r--r-- 1 root root   20 2008-10-31 17:50 index.txt.attr
-rw-r--r-- 1 root root   20 2008-10-31 17:49 index.txt.attr.old
-rw-r--r-- 1 root root  347 2008-10-31 17:49 index.txt.old
-rw-r--r-- 1 root root    3 2008-10-31 17:50 serial
-rw-r--r-- 1 root root    3 2008-10-31 17:49 serial.old
-rw-r--r-- 1 root root 3805 2008-10-31 17:49 vpn-client1.crt
-rw-r--r-- 1 root root  684 2008-10-31 17:49 vpn-client1.csr
-rw------- 1 root root  887 2008-10-31 17:49 vpn-client1.key
-rw-r--r-- 1 root root 3805 2008-10-31 17:49 vpn-client2.crt
-rw-r--r-- 1 root root  684 2008-10-31 17:49 vpn-client2.csr
-rw------- 1 root root  887 2008-10-31 17:49 vpn-client2.key
-rw-r--r-- 1 root root 3805 2008-10-31 17:50 vpn-client3.crt
-rw-r--r-- 1 root root  684 2008-10-31 17:50 vpn-client3.csr
-rw------- 1 root root  887 2008-10-31 17:50 vpn-client3.key
-rw-r--r-- 1 root root 3922 2008-10-31 17:48 vpn-server.crt
-rw-r--r-- 1 root root  684 2008-10-31 17:48 vpn-server.csr
-rw------- 1 root root  887 2008-10-31 17:48 vpn-server.key</pre>
<h4>ข้อมูลอ้างอิง</h4>
<ul>
<li><a href="http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_2">คอนฟิก OpenVPN แบบ Multiple Client – ตอนที่ 2</a></li>
<li><a href="http://spalinux.com/2008/06/howto_configure_openvpn_static_key_on_fedora_linux">คอนฟิก OpenVPN แบบ Static Key บน Fedora Linux</a></li>
<li><a href="http://openvpn.net/index.php/documentation/howto.html" target="_blank">OpenVPN HOWTO</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_1/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>คอนฟิก OpenVPN แบบ Static Key บน Fedora Linux</title>
		<link>http://spalinux.com/2008/06/howto_configure_openvpn_static_key_on_fedora_linux</link>
		<comments>http://spalinux.com/2008/06/howto_configure_openvpn_static_key_on_fedora_linux#comments</comments>
		<pubDate>Fri, 13 Jun 2008 13:00:18 +0000</pubDate>
		<dc:creator>editor</dc:creator>
				<category><![CDATA[Networking]]></category>
		<category><![CDATA[VPN]]></category>
		<category><![CDATA[openvpn]]></category>

		<guid isPermaLink="false">http://spalinux.com/?p=39</guid>
		<description><![CDATA[บทความนี้จะแนะนำการคอนฟิก OpenVPN ซึ่งเป็นโปรแกรม VPN อันหนึ่งที่นิยมใช้กันอย่างแพร่หลายบนลินุกซ์ โดยจะคอนฟิกในรูปแบบง่ายที่สุด คือเป็นแบบ static key เพื่อศึกษาทำความเข้าใจกับ OpenVPN ก่อนที่จะปรับปรุงเป็นแบบคอนฟิกที่ใช้ Public/Private key ซึ่งจะมีคุณสมบัติมากกว่าพร้อมทั้งความปลอดภัยที่ดีกว่าด้วย ระบบที่ทดสอบ ทั้งเครื่อง Server และ Client ติดตั้ง Fedora 8 หรือ Fedora 9 ลงโปรแกรม openvpn คอนฟิก network ก่อนที่จะเริ่มคอนฟิก OpenVPN แนะนำให้สร้างคอนฟิก network ระหว่าง Server และ Client โดยมีการเชื่อมต่อตามแบบด้านล่างนี้ LAN1 -------[ server ]---------------[ client ]------- LAN2 eth0 eth1 eth1 eth0 Server: eth0: 10.1.0.1/24 eth1: 192.168.2.1/24 [...]]]></description>
			<content:encoded><![CDATA[<p>บทความนี้จะแนะนำการคอนฟิก OpenVPN ซึ่งเป็นโปรแกรม VPN อันหนึ่งที่นิยมใช้กันอย่างแพร่หลายบนลินุกซ์ โดยจะคอนฟิกในรูปแบบง่ายที่สุด คือเป็นแบบ static key เพื่อศึกษาทำความเข้าใจกับ OpenVPN ก่อนที่จะปรับปรุงเป็นแบบคอนฟิกที่ใช้ Public/Private key ซึ่งจะมีคุณสมบัติมากกว่าพร้อมทั้งความปลอดภัยที่ดีกว่าด้วย</p>
<p><span id="more-39"></span></p>
<p><!-- more --></p>
<p><strong>ระบบที่ทดสอบ</strong></p>
<ul>
<li>ทั้งเครื่อง Server และ Client ติดตั้ง Fedora 8 หรือ Fedora 9</li>
<li>ลงโปรแกรม openvpn</li>
</ul>
<p><strong>คอนฟิก network</strong><br />
ก่อนที่จะเริ่มคอนฟิก OpenVPN แนะนำให้สร้างคอนฟิก network ระหว่าง Server และ Client โดยมีการเชื่อมต่อตามแบบด้านล่างนี้</p>
<pre>LAN1 -------[ <strong>server </strong>]---------------[ <strong>client</strong> ]------- LAN2
       eth0            eth1      eth1            eth0</pre>
<p>Server:</p>
<ul>
<li>eth0: 10.1.0.1/24</li>
<li>eth1: 192.168.2.1/24</li>
<li>ทุกเครื่องที่อยู่ในวง LAN 1 จะคอนฟิก default gateway มาที่ 10.1.0.1</li>
</ul>
<p>Client:</p>
<ul>
<li>eth0: 10.2.0.1/24</li>
<li>eth1: 192.168.2.2/24</li>
<li>ทุกเครื่องที่อยู่ในวง LAN 2 จะคอนฟิก default gateway มาที่ 10.2.0.1</li>
</ul>
<p>หมายเหตุ</p>
<ul>
<li>เพื่อความง่ายในการทดสอบ ในบทความนี้จะใช้พอร์ต eth1 ของ server และ client เชื่อมต่อ network เดียวกันเลย แต่ในการใช้งานจริง ทั้งสองเครื่องจะอยู่คนละ network กัน โดยอาจจะผ่าน internet ก็ได้ ขอให้มองเห็นกันได้ผ่านพอร์ต udp 1194 คือไม่มี firewall กั้นพอร์ตนี้ ก็เพียงพอแล้ว</li>
<li>สำหรับการทดสอบ ให้ปิด iptables firewall</li>
</ul>
<p><strong>ติดตั้งโปรแกรม OpenVPN</strong><br />
โปรแกรม OpenVPN จะอยู่ในแผ่นติดตั้งอยู่แล้ว ถ้าเป็น Fedora 8 ไฟล์จะชื่อ openvpn-2.1-0.19.rc4.fc7.x86_64.rpm แต่ถ้าเป็น Fedora 9 ไฟล์จะชื่อ openvpn-2.1-0.25.rc7.fc9.i386.rpm</p>
<p>ตัวอย่างการติดตั้ง OpenVPN บน Fedora 9</p>
<pre>[root@server media]# <strong>rpm –ivh openvpn-2.1-0.25.rc7.fc9.i386.rpm</strong></pre>
<p><strong>สร้าง static key</strong><br />
ไฟล์คอนฟิกหลักของ OpenVPN จะอยู่ใน /etc/openvpn/ แต่จากการติดตั้งโปรแกรม OpenVPN จะไม่มีไฟล์อะไรเลยอยู่ใน directory นี้ แต่จะมีตัวอย่างไฟล์อยู่ใน /usr/share/doc/openvpn-2.1/ พร้อมทั้งคำเอกสารอธิบายด้วย</p>
<p>ขั้นแรกต้องสร้าง static key ขึ้นมาก่อนโดยทั้ง server และ client จะใช้ไฟล์ key เดียวกันเลย โดยเราสามารถจะรันคำสั่งสร้างจากเครื่องไหนก็ได้แล้ว copy ไปไว้อีกเครื่อง อยู่ใน /etc/openvpn/ เหมือนกัน</p>
<p>เริ่มต้น cd เข้าไปใน /etc/openvpn/ แล้วใช้คำสั่งตามตัวอย่างด้านล่างนี้ เพื่อสร้างไฟล์ static.key ขึ้นมา</p>
<p>ตัวอย่างการสร้างไฟล์ static.key บนเครื่อง server</p>
<pre>[root@server ~]# <strong>cd /etc/openvpn/</strong>
[root@server openvpn]# <strong>ls –l</strong>
total 0
[root@server openvpn]# <strong>openvpn --genkey --secret static.key</strong>
total 4
-rw------- 1 root root 636 2008-06-13 18:59 static.key</pre>
<p>พอได้ไฟล์ static.key บน server แล้ว ก็ copy ไปไว้ใน client โดยอาจใช้คำสั่ง scp (secure copy) เป็นต้น</p>
<p><strong>สร้างไฟล์คอนฟิกหลัก</strong><br />
ขั้นต่อไปสร้างไฟล์คอนฟิกหลักขึ้นมา โดยจะเป็นชื่อไฟล์อะไรก็ได้ แต่ต้องลงท้ายด้วย .conf โดยโปรแกรม OpenVPN จะอ่านไฟล์ที่ลงท้ายด้วย .conf ทุกไฟล์ที่อยู่ใน /etc/openvpn/</p>
<p>คุณสามารถดูไฟล์คอนฟิกตัวอย่างได้จาก /usr/share/doc/openvpn-2.1/sample-config-files/ ซึ่งจะมีคำอธิบายอยู่ในไฟล์แล้ว</p>
<p>ในที่นี้ จะนำตัวอย่างไฟล์ static-office.conf มาแก้ไขเป็นคอนฟิกสำหรับ server และไฟล์ static-home.conf มาแก้ไขเป็นคอนฟิกสำหรับ client</p>
<p>ตัวอย่างคอนฟิกไฟล์ของ server ที่แก้ไขแล้ว และเอาบรรทัดที่มีเครื่องหมาย # และ ; (comment) ออกทั้งหมด บันทึกเป็นชื่อไฟล์ /etc/openvpn/static-office.conf</p>
<pre>dev tun
ifconfig <strong>10.8.0.1 10.8.0.2</strong>
secret static.key

ping 15
ping-restart 45
ping-timer-rem
persist-tun
persist-key

verb 3</pre>
<p>ตัวอย่างคอนฟิกไฟล์ของ client ที่แก้ไขแล้ว และเอาบรรทัดที่มีเครื่องหมาย # และ ; (comment) ออกทั้งหมด บันทึกเป็นชื่อไฟล์ /etc/openvpn/static-home.conf</p>
<pre>dev tun
remote <strong>192.168.2.1</strong>
ifconfig <strong>10.8.0.2 10.8.0.1</strong>
secret static.key

ping 15
ping-restart 45
ping-timer-rem
persist-tun
persist-key

verb 3</pre>
<p>หมายเหตุ บรรทัดที่มีคำว่า remote นั้น 192.168.2.1 เป็น ip ของพอร์ต eth1 ของ server ซึ่ง client ต้องมองเห็นและสามารถใช้พอร์ต udp 1194</p>
<p><strong>เริ่มต้นโปรแกรมบน server</strong><br />
เมื่อแก้ไขไฟล์คอนฟิกเรียบร้อยต้องเริ่มต้นโปรแกรม OpenVPN แนะนำให้รันบน server ก่อน</p>
<p>ตัวอย่างการเริ่มต้น OpenVPN บน server</p>
<pre>[root@server openvpn]# <strong>/etc/init.d/openvpn start</strong>
Starting openvpn:                                          [  OK  ]</pre>
<p>หลังจากรันโปรแกรมแล้ว ให้ใช้คำสั่ง ifconfig ในการตรวจสอบ สังเกตว่าจะมี interface ใหม่ถูกสร้างขึ้นมาชื่อ tun0<br />
และมี inet addr เป็น 10.8.0.1 ส่วน P-t-P จะเป็น 10.8.0.2 ซึ่งจะตรงกับในบรรทัด ifconfig ในไฟล์ /etc/openvpn/ static-office.conf</p>
<pre>[root@server openvpn]# <strong>ifconfig</strong>
...
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)</pre>
<p>ทดลองใช้คำสั่ง ping ทดสอบ ณ ตอนนี้จะ ping ได้แค่ 10.8.0.1 ซึ่งเป็น VPN ip address ของตัว server เอง แต่จะไม่สามารถ ping 10.8.0.2 ซึ่งเป็น VP ip address ของ client เพราะเรายังไม่ได้รันโปรแกรม OpenVPN บนเครื่อง client นั่นเอง</p>
<p><strong>เริ่มต้น OpenVPN บน client</strong><br />
ใช้คำสั่งเดียวกัน รันบนเครื่อง client ด้วย เพื่อเริ่มต้นโปรแกรม</p>
<pre>[root@client openvpn]# <strong>/etc/init.d/openvpn start</strong>
Starting openvpn:                                          [  OK  ]</pre>
<p>หลังจากรันโปรแกรมแล้ว ให้ใช้คำสั่ง ifconfig ในการตรวจสอบ สังเกตว่าจะมี interface ใหม่ถูกสร้างขึ้นมาชื่อ tun0<br />
และมี inet addr เป็น 10.8.0.2 ส่วน P-t-P จะเป็น 10.8.0.1 ซึ่งจะตรงกับในบรรทัด ifconfig ในไฟล์ /etc/openvpn/ static-home.conf สังเกตว่า จะสลับกับ ip ของ server</p>
<pre>[root@client openvpn]# <strong>ifconfig</strong>
...
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.2  P-t-P:10.8.0.1  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)</pre>
<p>ทดลองใช้คำสั่ง ping ทดสอบ ณ ตอนนี้จะ ping ได้ทั้งสอง ip เลย แสดงว่าจากเครื่อง client สามารถจะเชื่อมต่อกับ server ผ่านทาง VPN ได้แล้ว</p>
<p><strong>คอนฟิก server และ client ให้ทำหน้าที่เป็น router</strong><br />
เพื่อให้ LAN1 และ LAN2 จากรูป network ด้านบนสุดสามารถติดต่อกันได้ เราต้องคอนฟิก server และ client ให้ทำหน้าที่เป็น router</p>
<p>หมายเหตุ ในการใช้งานจริง ส่วนใหญ่แล้วจะคอนฟิกเป็นแบบ NAT กัน ระหว่าง network ข้ามเครือข่าย โดยเฉพาะผ่าน internet<br />
วิธีการง่ายสุดทำให้ linux ที่มี interface สองพอร์ตขึ้นไปทำหน้าที่เป็น router ได้ คือ แก้ไขไฟล์ /etc/sysctl.conf โดยแก้บรรทัดที่มีคำว่า net.ipv4.ip_forward แก้ค่าตัวแปรจาก 0 ให้เป็น 1 เพื่อเป็นการ enable ip forwarding นั่นเอง</p>
<p>ตัวอย่างการแก้ไขไฟล์ /etc/sysctl.conf</p>
<pre>...
# Controls IP packet forwarding
net.ipv4.ip_forward = <strong>1</strong>
...</pre>
<p>หลังจากทั้ง server และ client ทำหน้าที่เป็น router แล้ว เราต้องคอนฟิก routing ให้มองเห็นกันอย่างถูกต้องโดยจะผ่าน VPN ทั้งหมด</p>
<p>ตัวอย่างการคอนฟิก routing บน server</p>
<pre>[root@server ~]# route add –net 10.2.0.0 netmask 255.255.255.0 gw 10.8.0.2</pre>
<p>ตัวอย่างการคอนฟิก routing บนclient</p>
<pre>[root@client ~]# route add –net 10.1.0. netmask 255.255.255.0 gw 10.8.0.1</pre>
<p>หลังจากคอนฟิกเสร็จเรียบร้อย ให้ทดลอง ping ระหว่างเครื่องที่อยู่ใน LAN1 และ LAN2 ได้</p>
<p><strong>การแก้ไขปัญหา OpenVPN</strong><br />
เมื่อเกิดปัญหา สามารถตรวจสอบได้จากไฟล์ /var/log/messages โดยไฟล์นี้จะเก็บ log ทั้งหมดของ OpenVPN</p>
<p>ปัญหาที่พบบ่อยตอนเริ่มต้นคอนฟิกคือ static key ระหว่างสองเครื่องไม่เหมือนกัน โดยจะมีข้อความด้านล่างนี้เกิดขึ้นในไฟล์ /var/log/messages บน server</p>
<pre>Jun 13 17:13:00 server openvpn[2199]: Authenticate/Decrypt packet error: packet HMAC authentication failed</pre>
<p>วิธีการแก้ไข ให้ตรวจสอบไฟล์ /etc/openvpn/static.key ให้เหมือนกัน</p>
<p><strong>ข้อมูลอ้างอิง</strong></p>
<ul>
<li><a href="http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_1">คอนฟิก OpenVPN แบบ Multiple Client &#8211; ตอนที่ 1</a>
<li><a href="http://spalinux.com/2008/11/configure_openvpn_for_multiple_clients_part_2">คอนฟิก OpenVPN แบบ Multiple Client &#8211; ตอนที่ 2</a>
<li><a href="http://openvpn.net/index.php/documentation/miscellaneous/static-key-mini-howto.html">OpenVPN &#8211; Static Key Mini-HOWTO</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://spalinux.com/2008/06/howto_configure_openvpn_static_key_on_fedora_linux/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

