2. OpenVPN Server Setting:

其實有以下方法都能將Certificate放進DD-WRT裡
1. GUI > Service > VPN
2. 把所有設定參數直接寫入 > Administration > Commands裡
3. nvram直接寫到 DD-WRT上
               
三個做法都可以的,只是Path及位置有點不同, 如選用用第3個的話請確定有足夠位置才行,這裡簡單介紹1這個方法,有興趣可自行用2或3,而原理也是一樣的,小弟做過都沒甚麼問題。
        
a. 先Login到 GUI > Service > VPN
b.  Enable OpenVPN Daemon >
Startup OpenVPN = "Enable" ; Startup Type = "Wan Up"
c. 下面的設定是用來放證書, cat一下./keys底下的證書及將代碼複製到相關空格中,下方注釋應該十分清楚,看不懂請自行到OpenVPN網頁找各參數的意思,請對照以下格式:
  1.   
  2. Public Server Cert = ca.crt
  3. Certificate Revoke List = N/A
  4. Certificate Revoke List = server.crt
  5. Private Client Key = server.key
  6. DH PEM = dh1024/2048.pem
  7. OpenVPN Config = see below
  8. OpenVPN TLS Auth = add if necessary
複製代碼
  1.         
  2. ######## OpenVPN Config ##########
  3. # Tunnel options
  4. mode server       # Set OpenVPN major mode
  5. proto udp         # Setup the protocol (server)
  6. port 1234         # TCP/UDP port number
  7. dev tun0          # TUN/TAP virtual network device
  8. keepalive 15 60   # Simplify the expression of --ping
  9. daemon            # Become a daemon after all initialization
  10. verb 3            # Set output verbosity to n
  11. comp-lzo          # Use fast LZO compression


  12. # OpenVPN server mode options
  13. client-to-client  # tells OpenVPN to internally route client-to-client traffic
  14. duplicate-cn      # Allow multiple clients with the same common name


  15. # IP Address Routing
  16. push "route 192.168.50.0 255.255.255.0"
  17. server 192.168.60.0 255.255.255.0
  18. # Above IP addresses need to change to be your own address


  19. # TLS Mode Options
  20. tls-server      # Enable TLS and assume server role during TLS handshake
  21. dh /tmp/openvpn/dh.pem     # File containing Diffie Hellman parameters
  22. ca /tmp/openvpn/ca.crt       # Certificate authority (CA) file
  23. cert /tmp/openvpn/cert.pem     # Local peers signed certificate
  24. key /tmp/openvpn/key.pem       # Local peers private key
  25. ;tls-auth /tmp/openvpn/ta.key 0      # TLS-authorization (Uncommet if necessary)
複製代碼
**如更改過儲放Certificate的目錄,在TLS Mode Options裡的path需設定為對應的新目錄,設定後OpenVPN基本己經建立完成,接下來到這裡加入iptables及Startup的設定,如果之前是用tap的話,iptables要更改為相對的參數,這裡是比較要注意地方,下面己有注釋得, 沒理由不明白的。

先到 GUI > Administration > Commands
  1. ###### Firewall Config: #######
  2. # Replace 1234 with your OpenVPN port number:
  3. iptables -I INPUT 1 -p tcp --dport 1234 -j ACCEPT
  4. iptables -I INPUT 1 -p udp --dport 1234 -j ACCEPT


  5. # These next two lines may or may not be necessary.
  6. # Thus, we include them so that this works for more people:
  7. iptables -I FORWARD -i br0 -o tun0 -j ACCEPT
  8. iptables -I FORWARD -i tun0 -o br0 -j ACCEPT

  9. # Replace 192.168.60.0/24 with your OpenVPN server subnet:
  10. iptables -I FORWARD 1 --source 192.168.60.0/24 -j ACCEPT
複製代碼
>>> add to Firewall
  1. # Startup Config:
  2. openvpn --mktun --dev tun0
  3. brctl addif br0 tun0
  4. ifconfig tun0 0.0.0.0 promisc up
複製代碼
>>> add to Startup


為安全起見,先Reboot,起動後ps及查看/var/log/messages記錄,以確定OpenVPN有是否生效,
當無法啟動再加以下command添到startup下 (看情況自行增加或修改Path)
  1. # Add these command to startup if openvpn not stay opened:
  2. sleep 5
  3. ln -s /usr/sbin/openvpn /tmp/myvpn
  4. /tmp/myvpn --config openvpn.conf
複製代碼
>>> add to Startup


沒問題的話,Server Side基本上己己經設定成功。下一部是Client Side的設定。

[ 本帖最後由 ToRoGene 於 2009-12-15 23:11 編輯 ]

TOP

3. OpenVPN Client Setting:

OpenVPN支持Muti-platform, Mac下可使用TunnelBlick或Viscosity進行連線,而Windows下用OpenVPN GUI就可以,請自行download相關軟件。小弟己加入注釋,參數如下:
  1. # Client Side conf:
  2. client          # Set OpenVPN major mode
  3. dev tun0     # TUN/TAP virtual network device
  4. proto udp    # Setup the protocol (server)
  5. comp-lzo    # Use fast LZO compression
  6. verb 3         # Set output verbosity to n
  7. remote myvpnaddress.org 1234     # remote address, port number        
  8. resolv-retry infinite     # Keep trying indefinitely to resolve the host name of the OpenVPN server        
  9. nobind         # Most clients don't need to bind to a specific local port number.
  10. persist-key   # Try to preserve some state across restarts.
  11. persist-tun    # Try to preserve some state across restarts.
  12. ns-cert-type server   # you will need to generate, your server certificates with the nsCertType field set to "server"
  13. float          # For a routed OpenVPN, the "float" option is necessary

  14. # Certificate Located:
  15. ca ca.crt          # Certificate authority (CA) file
  16. cert client1.crt     # Client1 signed certificate
  17. key client1.key     # Client1 private key
  18. ;tls-auth ta.key 1     # If a tls-auth key is used on the server, every client also have the key
複製代碼
>> save as
Macintosh - config.conf
Windows - config.ovpn

留意的是tls-auth這個參數,如server side設定為0, client side應設定為1,
最後使用相關軟件連線,而OpenVPN是支持Muti-Platform,Macintsoh下可使用Viscosity/TunnelBlick, 而Windows下用OpenVPN GUI就可以了,以下是關的設定:

Macintosh:

1. Viscosity:
a. 安裝及開啟後在Status Bar上會有TunnelBlick的icon出現
b. 開啟 Viscosity > Preferences > + > Import Connection
c. Find config.conf
d. Import後點入設定檔,到Certificates > Authentication
e. Type:選SSl/TLS Client,把在Linux產生的證書放進去
f. 如發現在Advanced裡有些參數沒加進去,請自行加入
        
        >> Connect



2. Tunnel Blick:
a. 安裝及開啟後在Status Bar上會有TunnelBlick的icon出現
b. TunnelBlick > Detail > Edit configuration
c. 把剛才的參數復製進去 > Save
d. 把client*.key, client*.csr和ca.csr都放到
        > ~/Library/openvpn/ 裡
               
        >> Connect
        

Windows

3. Windows OpenVPN GUI:
a. 和Macintosh一樣安裝後,開機後System Tray有個OpenVPN Icon (如想手動開動自行到msconfig關閉)
b. 把client*.key, client*.csr和ca.csr, config.ovpn都放到 > Program File > OpenVPN > Config 裡
b. OpenVPN GUI > Client* >> Connect

[ 本帖最後由 ToRoGene 於 2009-12-16 02:11 編輯 ]

TOP

Remark:



1. 如之前所說,在GUI把Key套入OpenVPN後,Permission是644的,Client連線時機會出現Warning Log, 故建議將它們設為root:root 600

2. 如想用Bridge的朋友建議用tap, 及於Server Side Config中把"server"改為"server-bridge", 設定後緊記Reboot,格式如下:
        server-bridge 192.168.50.1 255.255.255.0 192.168.50.50 192.168.50.60
                              VPN                 Subnet              Start IP        End IP



3. 連線後如想將所有traffic從VPN走的話,於Client Side Config中加入這個參數

(這裡的師兄應該很需要此功能 XDD)

  1. pull     # Pull info from server-side LAN IP's for gateway and DNS
  2. redirect-gateway     # send all traffic through VPN
複製代碼
4. 用Unix-Like OS的朋友可於Server/Client config中加入user nobody和group nobody以提高安全性


5. Mac用家在連線過程中出現"Input/output error (code=5)", 請到這裡
        http://www.dd-wrt.com/phpBB2/vie ... openvpn+mac+clients

        
6. log是記錄在 /var/log/messages,有關連接問題請先看這裡,以便尋找出錯原因

[ 本帖最後由 ToRoGene 於 2009-12-15 22:47 編輯 ]

TOP

這樣所有Client應該可連線成功,接下來就ping一下設定好的subnet是否接通,完成後大致上應該可以了
小弟Post之前重新試過撘一次,與Asterisk使用也沒有問題
設定完成的OpenVPN連線應該十分稳定,
Step By Step應該可以做到的

[ 本帖最後由 ToRoGene 於 2009-12-16 01:33 編輯 ]

TOP

提示: 作者被禁止或刪除 內容自動屏蔽

TOP

嘩~~~勁呀師兄, 多謝分享

睇黎係dual wan下, 可以加多隻NAS 黎行openvpn, 2950 用黎handle pptp

TOP

我是新人
先要多謝這裡的達人
把vpn 簡單化

其實係大陸工作多年
一直都有想起vpn
不過過去用6m pccw
就算起左都係超慢
近期升級30m, 而且也有10上
就開始研究vpn這東西

其實都唔係刨左好多文後
定出方案有兩種
一是起台電腦行vpn server
二是買vpn router

最後決定買 Buffalo WZR-HP-G300NH
如果單單計起vpn 個part
實在是超簡單
幾分鐘就搞定
反而要叫朋友先從香港境內測試
時間更長

香港測試成功後
返大陸公司
用xp 上,第一次便成功
什麼youtube,yahoo.hk 也沒有問題

我自己在大陸有兩台電腦
一台是xp
一台是vista
有趣的是
xp 好簡單用vpn 連線就成,不用打入香港dns
反而vista 就要打入香港dns,真是奇怪

而且暫時非當穩定
就算晚上沒斷開vpn
第二日早上也沒問題,vpn 連線也沒斷開

連度方面
國內連線只得2m
所以沒有什麼要求
但從實際情況
一點也不覺所慢
好像這文也是從vpn 發出的

再次多謝這裡的達人

[ 本帖最後由 ibat 於 2009-12-16 01:10 編輯 ]

TOP

Code裡的參數本來是一行一個注釋的
但長度Forum 顯示問題,小弟只能將它們用space格出來
所以cp到text editor有機會走了位,建議把它們復製後用Tab把它們分好,
方便日後查看

[ 本帖最後由 ToRoGene 於 2009-12-16 01:23 編輯 ]

TOP

原帖由 ToRoGene 於 2009-12-15 21:07 發表
DD-WRT OpenVPN with Certificate Setting:
...


好极了,存起来,留稍後用。
非常感谢 ToRoGene 师兄

TOP

提示: 作者被禁止或刪除 內容自動屏蔽

TOP