{"id":1945,"date":"2012-08-18T15:44:05","date_gmt":"2012-08-18T07:44:05","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=1945"},"modified":"2014-01-22T10:35:56","modified_gmt":"2014-01-22T02:35:56","slug":"ubuntu%e4%b8%ad%e6%90%ad%e5%bb%bavpn%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1945.html","title":{"rendered":"ubuntu\u4e2d\u642d\u5efaVPN\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u5728 Ubuntu \u4e2d\u5efa\u7acb pptp server \u9700\u8981\u7684\u8f6f\u4ef6\u5305\u4e3a pptpd\uff0c\u7528 apt-get \u5373\u53ef\u5b89\u88c5\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install pptpd\r\n<\/pre>\n<p>\u7cfb\u7edf\u4f1a\u81ea\u52a8\u89e3\u51b3\u4f9d\u8d56\u5173\u7cfb\uff0c\u5b89\u88c5\u597d\u540e\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u756a\u8bbe\u7f6e\u3002\u9996\u5148\u7f16\u8f91 \/etc\/pptpd.conf<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nvim \/etc\/pptpd.conf\r\n<\/pre>\n<p>\u53bb\u6389\u6587\u4ef6\u6700\u672b\u7aef\u7684 localip \u548c remoteip \u4e24\u4e2a\u53c2\u6570\u7684\u6ce8\u91ca\u3002<br \/>\n\u8fd9\u91cc\uff0clocalip \u662f VPN \u8fde\u901a\u540e\u670d\u52a1\u5668\u7684 ip \u5730\u5740\uff0c\u800c remoteip \u5219\u662f\u5ba2\u6237\u7aef\u7684\u53ef\u5206\u914d ip \u5730\u5740\u3002\u4e0b\u9762\u662f\u6211\u7684\u914d\u7f6e\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# (Recommended)\r\nlocalip 192.168.0.1\r\nremoteip 192.168.0.234-238,192.168.0.245\r\n# or\r\n#localip 192.168.0.234-238,192.168.0.245\r\n#remoteip 192.168.1.234-238,192.168.1.245\r\n<\/pre>\n<p>\u7f16\u8f91\u597d\u8fd9\u4e2a\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u9700\u8981\u7f16\u8f91 \/etc\/ppp\/pptpd-options \u6587\u4ef6\u3002<br \/>\n\u8fd9\u91cc\u7edd\u5927\u591a\u6570\u53c2\u6570\u53ea\u9700\u7ef4\u6301\u539f\u6765\u7684\u9ed8\u8ba4\u503c\u5373\u53ef\uff0c\u6211\u4eec\u53ea\u9700\u8981\u6539\u53d8\u5176\u4e2d\u7684 ms-dns \u9009\u9879\uff0c\u4e3a VPN \u5ba2\u6237\u7aef\u6307\u6d3e DNS \u670d\u52a1\u5668\u5730\u5740\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nms-dns 8.8.8.8\r\nms-dns 8.8.4.4\r\n<\/pre>\n<p>\u4fee\u6539 \/etc\/ppp\/chap-secrets \u6587\u4ef6\uff0c\u8fd9\u91cc\u9762\u5b58\u653e\u7740 VPN \u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\uff0c\u6839\u636e\u4f60\u7684\u5b9e\u9645\u60c5\u51b5\u586b\u5199\u5373\u53ef\u3002\u5982\u6587\u4ef6\u4e2d\u6ce8\u91ca\u6240\u793a\uff0c\u7b2c\u4e00\u5217\u662f\u7528\u6237\u540d\uff0c\u7b2c\u4e8c\u5217\u662f\u670d\u52a1\u5668\u540d\uff08\u9ed8\u8ba4\u5199 pptpd \u5373\u53ef\uff0c\u5982\u679c\u5728 pptpd-options \u6587\u4ef6\u4e2d\u66f4\u6539\u8fc7\u7684\u8bdd\uff0c\u6ce8\u610f\u8fd9\u91cc\u4fdd\u6301\u4e00\u81f4\uff09\uff0c\u7b2c\u4e09\u5217\u662f\u5bc6\u7801\uff0c\u7b2c\u56db\u5217\u662f IP \u9650\u5236\uff08\u4e0d\u505a\u9650\u5236\u5199 * \u5373\u53ef\uff09\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Secrets for authentication using CHAP\r\n# client        server  secret                  IP addresses\r\nusername pptpd password *\r\n<\/pre>\n<p>\u5168\u90e8\u641e\u5b9a\u540e\uff0c\u6211\u4eec\u9700\u8981\u91cd\u542f pptpd \u670d\u52a1\u4f7f\u65b0\u914d\u7f6e\u751f\u6548\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo \/etc\/init.d\/pptpd restart\r\n<\/pre>\n<p>\u7136\u540e\u5728\u672c\u673a\u8bbe\u7f6eVPN\u8fde\u63a5\uff0c\u8fde\u63a5\u597d\u540e\u4f1a\u53d1\u73b0\u9664\u4e86\u53ef\u4ee5\u8bbf\u95ee\u670d\u52a1\u5668\u7684\u8d44\u6e90\uff0c\u5176\u4f59\u5185\u5916\u548c\u4e92\u8054\u7f51\u7684\u5185\u5bb9\u5747\u65e0\u6cd5\u8bbf\u95ee\u3002\u5982\u679c\u9700\u8981\u8bbf\u95ee\u8fd9\u4e9b\u5185\u5bb9\u7684\u8bdd\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u8fdb\u4e00\u6b65\u8bbe\u7f6e\uff1a<\/p>\n<p>\u9996\u5148\uff0c\u5f00\u542f ipv4 forward\u3002\u65b9\u6cd5\u662f\uff0c\u4fee\u6539 \/etc\/sysctl.conf\uff0c\u627e\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u884c\u5e76\u53d6\u6d88\u5b83\u4eec\u7684\u6ce8\u91ca\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nnet.ipv4.ip_forward=1\r\n<\/pre>\n<p>\u7136\u540e\u4f7f\u65b0\u914d\u7f6e\u751f\u6548\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo sysctl -p\r\n<\/pre>\n<p>\u5982\u679c\u5728\u670d\u52a1\u5668\u4e0a\u8fd9\u6837\u64cd\u4f5c\u540e\u4ecd\u7136\u65e0\u6cd5\u8bbf\u95ee\u7f51\u7edc\uff0c\u8fd9\u6837\u6211\u4eec\u5c31\u9700\u8981\u5efa\u7acb\u4e00\u4e2a NAT\u3002\u8fd9\u91cc\u6211\u4eec\u4f7f\u7528\u5f3a\u5927\u7684 iptables \u6765\u5efa\u7acb NAT\u3002<br \/>\n\u6211\u4eec\u5411 nat \u8868\u4e2d\u52a0\u5165\u4e00\u6761\u89c4\u5219\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE &amp;&amp; iptables-save\r\n<\/pre>\n<p>\u8fd9\u6837\u64cd\u4f5c\u540e\uff0c\u5ba2\u6237\u7aef\u673a\u5668\u5e94\u8be5\u5c31\u53ef\u4ee5\u4e0a\u7f51\u4e86\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u53ea\u662f\u8fd9\u6837\uff0ciptables \u7684\u89c4\u5219\u4f1a\u5728\u4e0b\u6b21\u91cd\u542f\u65f6\u88ab\u6e05\u9664\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u9700\u8981\u628a\u5b83\u4fdd\u5b58\u4e0b\u6765\uff0c\u65b9\u6cd5\u662f\u4f7f\u7528 iptables-save \u547d\u4ee4\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo iptables-save &gt; \/etc\/iptables-rules\r\n<\/pre>\n<p>\u7136\u540e\u4fee\u6539 \/etc\/network\/interfaces \u6587\u4ef6\uff0c\u627e\u5230 eth0 \u90a3\u4e00\u8282\uff0c\u5728\u5bf9 eth0 \u7684\u8bbe\u7f6e\u6700\u672b\u5c3e\u52a0\u4e0a\u4e0b\u9762\u8fd9\u53e5\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npre-up iptables-restore &lt; \/etc\/iptables-rules\r\n<\/pre>\n<p>\u8fd9\u6837\u5f53\u7f51\u5361 eth0 \u88ab\u52a0\u8f7d\u7684\u65f6\u5019\u5c31\u4f1a\u81ea\u52a8\u8f7d\u5165\u6211\u4eec\u9884\u5148\u7528 iptables-save \u4fdd\u5b58\u4e0b\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u80fd\u5efa\u7acb\u94fe\u63a5\uff0c\u4f46\u201c\u51e0\u4e4e\u201d\u65e0\u6cd5\u8bbf\u95ee\u4e92\u8054\u7f51\uff0c\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo iptables -A FORWARD -s 192.168.0.0\/24 -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1300\r\n<\/pre>\n<p>\u53ef\u53c2\u8003\u8fd9\u6587\u7ae0\uff1ahttps:\/\/www.digitalocean.com\/community\/articles\/how-to-setup-your-own-vpn-with-pptp<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Ubuntu \u4e2d\u5efa\u7acb pptp server \u9700\u8981\u7684\u8f6f\u4ef6\u5305\u4e3a pptpd\uff0c\u7528 apt-get \u5373\u53ef\u5b89\u88c5\uff1a  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1945","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1945"}],"version-history":[{"count":7,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1945\/revisions"}],"predecessor-version":[{"id":5454,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1945\/revisions\/5454"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}