{"id":55823,"date":"2020-01-29T00:00:00","date_gmt":"2020-01-28T21:00:00","guid":{"rendered":"https:\/\/prohoster.info\/blog\/blog_prohoster\/uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma"},"modified":"2020-02-18T14:03:58","modified_gmt":"2020-02-18T11:03:58","slug":"uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma","title":{"rendered":"Boosting OpenVPN on OpenWrt router. An alternative version without soldering and hardware extremism","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p><img decoding=\"async\" alt=\"Boosting OpenVPN on OpenWrt router. An alternative version without soldering and hardware extremism\" src=\"\/wp-content\/uploads\/2020\/01\/41eccab7acd03770306db78f510a201f.jpg\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<br \/>\nHello everyone, I recently read <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/368735\/\">an old article<\/a><\/noindex> about how to speed up OpenVPN on a router by offloading the encryption to a separate piece of hardware that can be soldered inside the router itself. I have a similar situation to the author \u2014 a TP-Link WDR3500 with 128 megabytes of RAM and a weak CPU that simply cannot handle the encryption of the tunnels. However, I really didn't want to mess with a soldering iron on the router. Below is my experience of transferring OpenVPN to a separate piece of hardware while keeping a backup on the router in case of failure. <br \/>\n<noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<h3>Task<\/h3>\n<p>\nI have a TP-Link WDR3500 router and an Orange Pi Zero H2. We want the Orange Pi to handle the tunnel encryption in normal operation, but if something happens to it, processing <a class=\"wpil_keyword_link\" href=\"https:\/\/prohoster.info\/en\/vpn\/\"   title=\"VPN\" data-wpil-keyword-link=\"linked\"  data-wpil-monitor-id=\"92\">VPN<\/a> will revert back to the router. All firewall settings on the router should work like before. Overall, the addition of extra hardware should be transparent and seamless for everyone. OpenVPN operates over TCP, with the TAP adapter in bridge mode (server-bridge).<\/p>\n<h3>Solution<\/h3>\n<p>\nInstead of connecting via USB, I decided to utilize one of the router's ports and route all subnets with a VPN bridge through it to the Orange Pi. This way, the hardware will physically be in the same networks as the VPN servers on the router. After that, we set up identical servers on the Orange Pi, and on the router, we configure a proxy to route all incoming connections to the external server, and if the Orange Pi fails or becomes unavailable \u2014 then to the internal fallback server. I used HAProxy.<\/p>\n<p>So it turns out:<\/p>\n<ol>\n<li>A client connects<\/li>\n<li>If the external server is unavailable \u2014 like before, the connection goes to the internal server.<\/li>\n<li>If it is available \u2014 the Orange Pi accepts the client.<\/li>\n<li>The VPN on the Orange Pi decrypts the packets and sends them back to the router.<\/li>\n<li>The router routes them somewhere.<\/li>\n<\/ol>\n<p><\/p>\n<h3>Example of implementation<\/h3>\n<p>\nSo, let's say we have two networks on the router \u2014 main(1) and guest(2), each with its own OpenVPN server for external connections.<\/p>\n<h4>Network configuration<\/h4>\n<p>\nWe need to bridge both networks through one port, so we create 2 VLANs. <\/p>\n<p>On the router in the Network\/Switch section, we create VLANs (for example, 1 and 2) and enable them in tagged mode on the desired port, adding the newly created eth0.1 and eth0.2 to the corresponding networks (for example, adding them to the bridge). <\/p>\n<p>On the Orange Pi, we create two VLAN interfaces (I have Archlinux ARM + netctl):<\/p>\n<p><b class=\"spoiler_title\">\/etc\/netctl\/vlan-main<\/b><\/p>\n<pre><code class=\"plaintext\">Description='Main VLAN on eth0'\nInterface=vlan-main\nConnection=vlan\nBindsToInterfaces=eth0\nVLANID=1\nIP=no\n<\/code><\/pre>\n<p>\n<b class=\"spoiler_title\">\/etc\/netctl\/vlan-guest<\/b><\/p>\n<pre><code class=\"plaintext\">Description='Guest VLAN on eth0'\nInterface=vlan-guest\nConnection=vlan\nBindsToInterfaces=eth0\nVLANID=2\nIP=no\n<\/code><\/pre>\n<p>\nAnd we immediately create two bridges for them:<\/p>\n<p><b class=\"spoiler_title\">\/etc\/netctl\/br-main<\/b><\/p>\n<pre><code class=\"plaintext\">Description=\"Main Bridge connection\"\nInterface=br-main\nConnection=bridge\nBindsToInterfaces=(vlan-main)\nIP=dhcp\n<\/code><\/pre>\n<p>\n<b class=\"spoiler_title\">\/etc\/netctl\/br-guest<\/b><\/p>\n<pre><code class=\"plaintext\">Description=\"Guest Bridge connection\"\nInterface=br-guest\nConnection=bridge\nBindsToInterfaces=(vlan-guest)\nIP=dhcp\n<\/code><\/pre>\n<p>\nWe enable auto-start for all 4 profiles (netctl enable). Now, after rebooting, the Orange Pi will connect to the two required networks. We configure the interface addresses on the Orange Pi in Static Leases on the router. <\/p>\n<p><b class=\"spoiler_title\">ip addr show<\/b><\/p>\n<pre><code class=\"plaintext\">4: vlan-main@eth0:  mtu 1500 qdisc noqueue master br-main state UP group default qlen 1000\n    link\/ether 02:42:f0:f8:23:c8 brd ff:ff:ff:ff:ff:ff\n    inet6 fe80::42:f0ff:fef8:23c8\/64 scope link \n       valid_lft forever preferred_lft forever\n\n5: vlan-guest@eth0:  mtu 1500 qdisc noqueue master br-guest state UP group default qlen 1000\n    link\/ether 02:42:f0:f8:23:c8 brd ff:ff:ff:ff:ff:ff\n    inet6 fe80::42:f0ff:fef8:23c8\/64 scope link \n       valid_lft forever preferred_lft forever\n\n6: br-main:  mtu 1500 qdisc noqueue state UP group default qlen 1000\n    link\/ether 52:c7:0f:89:71:6e brd ff:ff:ff:ff:ff:ff\n    inet 192.168.1.3\/24 brd 192.168.1.255 scope global dynamic noprefixroute br-main\n       valid_lft 29379sec preferred_lft 21439sec\n    inet6 fe80::50c7:fff:fe89:716e\/64 scope link \n       valid_lft forever preferred_lft forever\n\n7: br-guest:  mtu 1500 qdisc noqueue state UP group default qlen 1000\n    link\/ether ee:ea:19:31:34:32 brd ff:ff:ff:ff:ff:ff\n    inet 192.168.2.3\/24 brd 192.168.2.255 scope global br-guest\n       valid_lft forever preferred_lft forever\n    inet6 fe80::ecea:19ff:fe31:3432\/64 scope link \n       valid_lft forever preferred_lft forever\n<\/code><\/pre>\n<p><\/p>\n<h4>VPN Configuration<\/h4>\n<p>\nNext, we copy the OpenVPN settings and keys from the router. The settings can usually be found in <i>\/tmp\/etc\/openvpn*.conf<\/i><\/p>\n<p>By default, OpenVPN running in TAP mode and server-bridge keeps its interface inactive. To make everything work, a script must be added that runs when the connection is activated. <\/p>\n<p><b class=\"spoiler_title\">\/etc\/openvpn\/main.conf<\/b><\/p>\n<pre><code class=\"plaintext\">dev vpn-main\ndev-type tap\n\nclient-to-client\npersist-key\npersist-tun\nca \/etc\/openvpn\/main\/ca.crt\ncert \/etc\/openvpn\/main\/main.crt\ncipher AES-256-CBC\ncomp-lzo yes\ndh \/etc\/openvpn\/main\/dh2048.pem\nifconfig-pool-persist \/etc\/openvpn\/ipp_main.txt\nkeepalive 10 60\nkey \/etc\/openvpn\/main\/main.key\nport 443\nproto tcp\npush \"redirect-gateway\"\npush \"dhcp-option DNS 192.168.1.1\"\nserver-bridge 192.168.1.3 255.255.255.0 192.168.1.200 192.168.1.229\nstatus \/tmp\/openvpn.main.status\nverb 3\n\nsetenv profile_name main\nscript-security 2\nup \/etc\/openvpn\/vpn-up.sh\n<\/code><\/pre>\n<p>\n<b class=\"spoiler_title\">\/etc\/openvpn\/vpn-up.sh<\/b><\/p>\n<pre><code class=\"bash\">#!\/bin\/sh\n\nifconfig vpn-${profile_name} up\nbrctl addif br-${profile_name} vpn-${profile_name}\n<\/code><\/pre>\n<p>\nAs a result, as soon as the connection occurs, the vpn-main interface will be added to br-main. For the guest network, the process is similar but with adjustments to the interface name and address in server-bridge.<\/p>\n<h4>Routing external requests and proxying<\/h4>\n<p>\nAt this stage, the Orange Pi is already able to accept connections and allow clients into the desired networks. It remains to configure the proxying of incoming connections on the router. <\/p>\n<p>We move the router's VPN servers to other ports, install HAProxy on the router, and configure it:<\/p>\n<p><b class=\"spoiler_title\">\/etc\/haproxy.cfg<\/b><\/p>\n<pre><code class=\"plaintext\">global\n        maxconn 256\n        uid 0\n        gid 0\n        daemon\n\ndefaults\n        retries 1\n        contimeout 1000\n        option splice-auto\n\nlisten guest_vpn\n        bind :444\n        mode tcp\n        server 0-orange 192.168.2.3:444 check\n        server 1-local  127.0.0.1:4444 check backup\n\nlisten main_vpn\n        bind :443\n        mode tcp\n        server 0-orange 192.168.1.3:443 check\n        server 1-local  127.0.0.1:4443 check backup\n<\/code><\/pre>\n<p><\/p>\n<h4>Enjoying<\/h4>\n<p>\nIf everything goes as planned, clients will switch to the Orange Pi, the router's processor will no longer overheat, and the VPN speed will noticeably increase. All the network rules defined on the router will remain valid. In case of a failure on the Orange Pi, it will disconnect, and HAProxy will redirect clients to the local servers. <\/p>\n<p>Thank you for your attention, suggestions and corrections are welcome.<br \/>\n<br \/>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/485876\/\">habr.com<\/a><\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442, \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b \u0434\u0430\u0432\u043d\u044e\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c OpenVPN \u043d\u0430 \u0440\u043e\u0443\u0442\u0435\u0440\u0435, \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u044f \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0436\u0435\u043b\u0435\u0437\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043f\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u0430\u043c\u043e\u0433\u043e \u0440\u043e\u0443\u0442\u0435\u0440\u0430. \u0423 \u043c\u0435\u043d\u044f \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0441 \u0430\u0432\u0442\u043e\u0440\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0439 \u2014 TP-Link WDR3500 \u0441 128 \u043c\u0435\u0433\u0430\u0431\u0430\u0439\u0442\u0430\u043c\u0438 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043a\u0438 \u0438 \u0431\u0435\u0434\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u0440\u043e\u0447\u044c \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0442\u0443\u043d\u043d\u0435\u043b\u0435\u0439. \u041e\u0434\u043d\u0430\u043a\u043e, \u043b\u0435\u0437\u0442\u044c \u0432 \u0440\u043e\u0443\u0442\u0435\u0440 \u0441 \u043f\u0430\u044f\u043b\u044c\u043d\u0438\u043a\u043e\u043c \u043c\u043d\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":55824,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-55823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c OpenVPN \u043d\u0430 \u0440\u043e\u0443\u0442\u0435\u0440\u0435 Openwrt. \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0431\u0435\u0437 \u043f\u0430\u044f\u043b\u044c\u043d\u0438\u043a\u0430 \u0438 \u0445\u0430\u0440\u0434\u0432\u0430\u0440\u043d\u043e\u0433\u043e \u044d\u043a\u0441\u0442\u0440\u0435\u043c\u0438\u0437\u043c\u0430 | ProHoster\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-01-28T21:00:00+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-02-18T11:03:58+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47Speeding up OpenVPN on the Openwrt router. An alternative version without soldering and hardware extremism | ProHoster","description":"","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0423\u0441\u043a\u043e\u0440\u044f\u0435\u043c OpenVPN \u043d\u0430 \u0440\u043e\u0443\u0442\u0435\u0440\u0435 Openwrt. \u0410\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f \u0431\u0435\u0437 \u043f\u0430\u044f\u043b\u044c\u043d\u0438\u043a\u0430 \u0438 \u0445\u0430\u0440\u0434\u0432\u0430\u0440\u043d\u043e\u0433\u043e \u044d\u043a\u0441\u0442\u0440\u0435\u043c\u0438\u0437\u043c\u0430 | ProHoster","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/uskoryaem-openvpn-na-routere-openwrt-alternativnaya-versiya-bez-payalnika-i-hardvarnogo-ekstremizma","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2020-01-28T21:00:00+00:00","article:modified_time":"2020-02-18T11:03:58+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"55823","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 19:36:29","updated":"2026-02-04 14:42:02","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/55823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=55823"}],"version-history":[{"count":1,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/55823\/revisions"}],"predecessor-version":[{"id":156721,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/55823\/revisions\/156721"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media\/55824"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=55823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=55823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=55823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}