OpenWRT 如何部署 OpenVPN Server?
02-02
如何在公司總部的路由器部署openvpn server 使各區域分公司能用vpn連公司呢?路由器系統是OpenWRT。
OpenVPN的資料被少,我看到這篇論壇帖有說怎麼搞OPENVPN:香港人寫的OpenWRT常用應用合集裡面的:PPTP和OpenVPN的設置(感謝gl5900as)而且樓主說「如果大家有什麼資料找不到(例如被屏的openvpn、GoAgent),都可以回覆本帖,小的盡力幫忙~」 你可以回覆找他問資料,謝謝
正好前段時間在openwrt下了試用了openvpn,在這裡也簡單聊聊。openwrt 下有2個openvpn server,一個是openvpn-openssl,另一個是openvpn-polarssl,配置方法是通用的。
以下以openvpn-polarssl為例,(之前寫的備忘錄,怕自己忘記了,供參考,部分內容需要根據你網路實際情況進行調整):
1.1. OpenVPN - Polarssl
opkg updateopkg install openvpn-polarssl1.1.1. Config CA files
1) On the OpenVPN Server, install the Easy-RSA package:opkg update; opkg install openvpn-easy-rsa2) If running Attitude Adjustment (specifically, version 2.2.2-2 of the Easy-RSA package), then you must tweak the PKI configuration to prevent problems later on (this step comments-out the relevant code):## do not set the KEY_CN environment variablesed -i /KEY_CN/ s:^export:# : /etc/easy-rsa/vars
3) Establish the shell variables, and start with a clean slate (you may get warnings about ./clean-all, which you can ignore):source /etc/easy-rsa/varsclean-all? Define Key Informationsexport KEY_SIZE=2048export KEY_COUNTRY=CNexport KEY_PROVINCE=Cantonexport KEY_CITY=city_nameexport KEY_ORG=org_nameexport KEY_EMAIL=email_address
4) Create the Certification Authority, Server, and Client certificates:pkitool –initca ## equivalent to the build-ca scriptpkitool --server my-server ## equivalent to the build-key-server scriptpkitool my-client ## equivalent to the build-key scriptpkitool my-client-1pkitool my-client-2.......5) Finally, create the Diffie Hellman parameters (left until last because it can take a long time):build-dh ## this script will take a long time6) create OpenVPN static key
openvpn --genkey --secret keys/ta.key1.1.2. Config OpenVPN ServerFile:/etc/config/networkconfig interface lanchg : option ifname wlan0 tun0File:/etc/config/openvpn
config openvpn servernameoption enabled 1option port 1194option proto tcp
option dev tunoption ca /etc/openvpn/ca.crtoption cert /etc/openvpn/server.crtoption key /etc/openvpn/server.keyoption dh /etc/openvpn/dh2048.pemoption server "172.16.1.0 255.255.255.0"list push "redirect-gateway def1"list push "dhcp-option DNS 192.168.1.1"option tls_auth "/etc/openvpn/ta.key 0"option tls_server 1
option comp_lzo yesoption max_clients 10option persist_key 1option persist_tun 1option status /tmp/openvpn-status.logoption log /tmp/openvpn.logoption verb 4option mute 20cmd:
iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j MASQUERADE
File:/etc/firewall.user
add: iptables -A forwarding_rule -s 172.16.1.0/24 -j ACCEPTFile:/etc/config/firewall
#Add rule for openvpn accessconfig ruleoption enabled 1option target ACCEPToption src wanoption name Allow-WAN-OpenVPN-Inputoption family ipv4
option proto tcpoption dest_port 1194然後:
/etc/init.d/openvpn enablereboot(or /etc/init.d/network restart;/etc/init.d/firewall restart;/etc/init.d/openvpn start)各區域的終端安裝openvpn 客戶端撥入即可。推薦閱讀:
※OpenWRT和DD-WRT一起上,VLAN解決家裡的IPTV問題
TAG:OpenWrt |