{"id":3221,"date":"2012-12-06T23:09:09","date_gmt":"2012-12-06T21:09:09","guid":{"rendered":"http:\/\/skeletor.org.ua\/?p=3221"},"modified":"2021-01-15T10:23:20","modified_gmt":"2021-01-15T08:23:20","slug":"%d1%86%d0%b5%d0%bf%d0%be%d1%87%d0%ba%d0%b0-%d1%81%d0%b5%d1%80%d0%b2%d0%b5%d1%80%d0%be%d0%b2-%d1%81-openvpn","status":"publish","type":"post","link":"https:\/\/skeletor.org.ua\/?p=3221","title":{"rendered":"\u0426\u0435\u043f\u043e\u0447\u043a\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u043e\u0432 \u0441 openvpn"},"content":{"rendered":"<p>\u0421\u0445\u0435\u043c\u0430 \u0442\u0430\u043a\u0430\u044f: <strong>client -&gt; server1 (ip=XX.XX.XX.XX) -&gt; server2 (IP=YY.YY.YY.YY)<\/strong> \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u0447\u0451\u043c \u0441 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432 <strong>256<\/strong> \u0431\u0438\u0442. \u0425\u043e\u0447\u0443 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 <strong>server1<\/strong> \u0431\u0443\u0434\u0435\u0442 2 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 &#8211; \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a<strong> server2<\/strong>) \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (\u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0442\u0438\u043f\u0430 client)<\/p>\n<p><!--more--><\/p>\n<p><strong><span style=\"color: #0000ff;\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 client<\/span><\/strong><\/p>\n<p><code>client<br \/>\ndev tun<br \/>\ntls-client<br \/>\nproto udp<br \/>\nremote XX.XX.XX.XX 1194<br \/>\nresolv-retry infinite<br \/>\nnobind<br \/>\nremote-cert-tls server<br \/>\nverb 3<br \/>\ncipher AES-256-CBC<br \/>\ncompress lzo<br \/>\nca C:\\\\vpn\\\\ca.crt<br \/>\ndh C:\\\\vpn\\\\dh1024.pem<br \/>\ntls-auth C:\\\\vpn\\\\ta.key 1<br \/>\ncert C:\\\\vpn\\\\client1.crt<br \/>\nkey C:\\\\vpn\\\\client1.key<br \/>\npersist-key<br \/>\npersist-tun<\/code><\/p>\n<p><strong><span style=\"color: #0000ff;\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 server1<\/span><\/strong><\/p>\n<p><em><span style=\"color: #ff6600;\">&#8211; \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/span><\/em><\/p>\n<p><code>client<br \/>\ndev tun1<br \/>\ntls-client<br \/>\nproto udp<br \/>\nremote YY.YY.YY.YY 1194<br \/>\nresolv-retry infinite<br \/>\nnobind<br \/>\nremote-cert-tls\u00a0server<br \/>\ncipher AES-256-CBC<br \/>\ncompress lzo<br \/>\nca \/etc\/openvpn\/client_vps6\/ca.crt<br \/>\ncert \/etc\/openvpn\/client_vps6\/vps5.crt<br \/>\nkey \/etc\/openvpn\/client_vps6\/vps5.key<br \/>\ndh \/etc\/openvpn\/client_vps6\/dh1024.pem<br \/>\ntls-auth \/etc\/openvpn\/client_vps6\/ta.key 1<br \/>\npersist-key<br \/>\npersist-tun<br \/>\nuser root<br \/>\ngroup nobody<br \/>\nscript-security 2<br \/>\nup \/scripts\/openvpn_client.sh<\/code><\/p>\n<p>\u0444\u0430\u0439\u043b \u0441\u043a\u0440\u0438\u043f\u0442\u0430 <strong>\/scripts\/openvpn_client.sh<\/strong><\/p>\n<p><code>#!\/bin\/sh<br \/>\n\/sbin\/ip route add default via 10.6.11.5 proto static table T2<\/code><\/p>\n<p><em><span style=\"color: #ff6600;\">&#8211; \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430<\/span><\/em><\/p>\n<p><code>port 1194<br \/>\nproto udp<br \/>\ndev tun0<br \/>\nca \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ca.crt<br \/>\ncert \/etc\/openvpn\/easy-rsa\/2.0\/keys\/server.crt<br \/>\nkey \/etc\/openvpn\/easy-rsa\/2.0\/keys\/server.key<br \/>\ndh \/etc\/openvpn\/easy-rsa\/2.0\/keys\/dh1024.pem<br \/>\ntls-auth \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ta.key 0<br \/>\nclient-to-client<br \/>\nserver 10.5.11.0 255.255.255.0<br \/>\npush \"route 10.5.11.0 255.255.255.0\"<br \/>\npush \"redirect-gateway\"<br \/>\ntls-server<br \/>\ncompress lzo<br \/>\ncipher AES-256-CBC<br \/>\nuser root<br \/>\ngroup nobody<br \/>\npersist-key<br \/>\npersist-tun<br \/>\nkeepalive 10 120<br \/>\nscript-security 2<br \/>\nup \/scripts\/openvpn_server.sh<\/code><\/p>\n<p>\u0424\u0430\u0439\u043b \u0441\u043a\u0440\u0438\u043f\u0442\u0430 <strong>\/scripts\/openvpn_server.sh<\/strong><\/p>\n<p><code>#!\/bin\/sh<br \/>\n\/sbin\/ip rule add from 10.5.11.0\/24 to 0\/0 table T2<\/code><\/p>\n<p><em><strong><span style=\"color: #ff6600;\">\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435.<\/span><\/strong><\/em><\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u0441\u0435\u0440\u0432\u0435\u0440 \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 \u043d\u0430 <strong>tun0<\/strong>, \u0430 \u043a\u043b\u0438\u0435\u043d\u0442 &#8211; \u043d\u0430 <strong>tun1<\/strong>. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u0432 \u043a\u043e\u043d\u0444\u0438\u0433\u0430\u0445.<\/p>\n<p><strong><span style=\"color: #0000ff;\">\u041a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 server2<\/span><\/strong><\/p>\n<p><code>port 1194<br \/>\nproto udp<br \/>\ndev tun<br \/>\nca \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ca.crt<br \/>\ncert \/etc\/openvpn\/easy-rsa\/2.0\/keys\/server.crt<br \/>\nkey \/etc\/openvpn\/easy-rsa\/2.0\/keys\/server.key<br \/>\ndh \/etc\/openvpn\/easy-rsa\/2.0\/keys\/dh1024.pem<br \/>\ntls-auth \/etc\/openvpn\/easy-rsa\/2.0\/keys\/ta.key 0<br \/>\nclient-to-client<br \/>\nserver 10.6.11.0 255.255.255.0<br \/>\npush \"route 10.6.11.0 255.255.255.0\"<br \/>\ntls-server<br \/>\ncompress lzo<br \/>\ncipher AES-256-CBC<br \/>\nuser root<br \/>\ngroup nobody<br \/>\npersist-key<br \/>\npersist-tun<br \/>\nkeepalive 10 120<\/code><\/p>\n<p><strong><span style=\"color: #0000ff;\">\u041f\u043e\u044f\u0441\u043d\u0435\u043d\u0438\u0435<\/span><\/strong><\/p>\n<p>\u0421\u043a\u0440\u0438\u043f\u0442\u044b <strong>\/scripts\/openvpn_server.sh<\/strong> \u0438 <strong>\/scripts\/openvpn_client.sh<\/strong> \u043d\u0443\u0436\u043d\u044b \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u044b \u0437\u0430\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0442\u044c \u0442\u0440\u0430\u0444\u0438\u043a \u043e\u0442 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432 (\u0442\u0438\u043f\u0430 <strong>client<\/strong>) \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 <strong>server2<\/strong><\/p>\n<p><em><span style=\"color: #ff6600;\">\u041a\u0430\u043a\u0438\u0435 \u0438 \u0433\u0434\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043f\u043e\u0434\u0441\u0435\u0442\u0438:<\/span><\/em><\/p>\n<p><strong>client<\/strong> \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u0438\u0437 \u0441\u0435\u0442\u0438 <strong>10.5.11.0\/2<\/strong>4<br \/>\n<strong>server1<\/strong> \u043f\u0440\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u043a <strong>server2<\/strong> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u0438\u0437 \u0441\u0435\u0442\u0438 <strong>10.6.11.0\/24<\/strong> (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e <strong>10.6.11.5<\/strong> \u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e <strong>gw=10.6.11.6<\/strong>)<\/p>\n<p><em><span style=\"color: #ff6600;\">\u0424\u0430\u0439\u0435\u0440\u0432\u043e\u043b \u0438 \u041d\u0410\u0422<\/span><\/em><\/p>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b &#8211; \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u043d\u0430 \u043e\u0431\u0435\u0438\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445:<\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #008000; text-decoration: underline;\">&#8211; server1<\/span><\/span><\/p>\n<p><code>iptables --table nat --append POSTROUTING --out-interface tun1 -j SNAT --to 10.6.11.6<\/code><\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <strong>tun1<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u0432 \u0441\u0442\u043e\u0440\u043e\u043d\u0443 <strong>server2<\/strong> \u0438 \u0432\u0435\u0441\u044c \u0442\u0440\u0430\u0444\u0438\u043a \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 <strong>server2<\/strong> \u0441 server1 NAT&#8217;\u0438\u0442\u0441\u044f \u043d\u0430 \u0418\u041f <strong>10.6.11.6<\/strong><\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #008000; text-decoration: underline;\">&#8211; server2<\/span><\/span><\/p>\n<p><code>iptables --table nat --append POSTROUTING --out-interface eth0 -j SNAT --to YY.YY.YY.YY<\/code><\/p>\n<p><em><span style=\"color: #ff6600;\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 sysctl:<\/span><\/em><\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #008000; text-decoration: underline;\">&#8211; server1<\/span><\/span><\/p>\n<p><code>net.ipv4.ip_forward = 1<br \/>\nnet.ipv4.conf.tun0.rp_filter=0<br \/>\nnet.ipv4.conf.tun1.rp_filter=0<\/code><\/p>\n<p><span style=\"text-decoration: underline;\"><span style=\"color: #008000; text-decoration: underline;\">&#8211; server2<\/span><\/span><\/p>\n<p><code>net.ipv4.ip_forward = 1<\/code><\/p>\n<p><em><span style=\"color: #ff6600;\">\u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 iproute2 (\u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f server1)<\/span><\/em><\/p>\n<p>\u0414\u043b\u044f iproute \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u0445 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 <strong>T2<\/strong>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u0444\u0430\u0439\u043b <strong>\/etc\/iproute2\/rt_tables<\/strong> \u0442\u0430\u043a\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443<\/p>\n<p><code>251 T2<\/code><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0439 \u0444\u0430\u0439\u0435\u0440\u0432\u043e\u043b, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u0430\u043a \u0436\u0435 \u0440\u0430\u0437\u0440\u0435\u0448\u0438\u0442\u044c \u0444\u043e\u0440\u0432\u0430\u0440\u0438\u0434\u0438\u043d\u0433 \u043f\u0430\u043a\u0435\u0442\u043e\u0432+\u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0434\u043b\u044f \u0442\u0443\u043d\u0435\u043b\u0435\u0439 \u0438 \u0441\u0435\u0442\u0435\u0439.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u0445\u0435\u043c\u0430 \u0442\u0430\u043a\u0430\u044f: client -&gt; server1 (ip=XX.XX.XX.XX) -&gt; server2 (IP=YY.YY.YY.YY) \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0430\u043d\u043e\u043d\u0438\u043c\u043d\u043e\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u041f\u0440\u0438\u0447\u0451\u043c \u0441 \u0448\u0438\u0444\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432 256 \u0431\u0438\u0442. \u0425\u043e\u0447\u0443 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 server1 \u0431\u0443\u0434\u0435\u0442 2 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 &#8211; \u043a\u043b\u0438\u0435\u043d\u0442\u0430 (\u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a server2) \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 (\u0434\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432, \u0442\u0438\u043f\u0430 client)<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,13],"tags":[],"class_list":["post-3221","post","type-post","status-publish","format-standard","hentry","category-linux","category-security"],"_links":{"self":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/3221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3221"}],"version-history":[{"count":10,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/3221\/revisions"}],"predecessor-version":[{"id":5688,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/3221\/revisions\/5688"}],"wp:attachment":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}