{"id":43786,"date":"2024-10-06T10:12:27","date_gmt":"2024-10-06T02:12:27","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43786\/"},"modified":"2024-10-06T10:12:27","modified_gmt":"2024-10-06T02:12:27","slug":"centos-7-%e9%83%a8%e7%bd%b2-l2tp","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43786\/","title":{"rendered":"CentOS 7 \u90e8\u7f72 L2TP"},"content":{"rendered":"<h1 id=\"centos-7-%e9%83%a8%e7%bd%b2-l2tp-JQTjarTcMg\">CentOS 7 \u90e8\u7f72 L2TP<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u865b\u64ec\u79c1\u4eba\u7db2\u7d61\uff08VPN\uff09\u5df2\u6210\u70ba\u4fdd\u8b77\u7528\u6236\u96b1\u79c1\u548c\u5b89\u5168\u7684\u91cd\u8981\u5de5\u5177\u3002L2TP\uff08Layer 2 Tunneling Protocol\uff09\u662f\u4e00\u7a2e\u5e38\u7528\u7684VPN\u5354\u8b70\uff0c\u901a\u5e38\u8207IPsec\u7d50\u5408\u4f7f\u7528\uff0c\u4ee5\u63d0\u4f9b\u66f4\u9ad8\u7684\u5b89\u5168\u6027\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728CentOS 7\u4e0a\u90e8\u7f72L2TP VPN\uff0c\u5e6b\u52a9\u7528\u6236\u5efa\u7acb\u5b89\u5168\u7684\u7db2\u7d61\u9023\u63a5\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-JQTjarTcMg\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u78ba\u4fdd\u60a8\u7684CentOS 7\u7cfb\u7d71\u5df2\u7d93\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u66f4\u65b0\uff1a<\/p>\n<pre><code>sudo yum update -y<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd\u4e00\u4e9b\u5fc5\u8981\u7684\u8edf\u4ef6\u5305\uff0c\u5305\u62ec<strong>xl2tpd<\/strong>\u548c<strong>libreswan<\/strong>\uff08\u7528\u65bcIPsec\uff09\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo yum install xl2tpd libreswan -y<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%aeipsec-JQTjarTcMg\">\u914d\u7f6eIPsec<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u914d\u7f6eIPsec\u3002\u7de8\u8f2f<strong>\/etc\/ipsec.conf<\/strong>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>config setup\n    protostack=netkey\n    nat_traversal=yes\n    virtual_private=%v4:192.168.0.0\/16,%v4:10.0.0.0\/8,%v4:172.16.0.0\/12\n    oe=off\n\nconn L2TP-PSK\n    authby=secret\n    pfs=no\n    auto=add\n    keyingtries=1\n    ikelifetime=60m\n    salifetime=60m\n    dpdtimeout=300s\n    dpdaction=clear\n    left=%defaultroute\n    leftid=\u60a8\u7684\u4f3a\u670d\u5668IP\n    leftsubnet=0.0.0.0\/0\n    right=%any\n    rightprotoport=17\/1701\n    rightid=%any\n<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u7de8\u8f2f<strong>\/etc\/ipsec.secrets<\/strong>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>\u60a8\u7684\u4f3a\u670d\u5668IP : PSK \"\u60a8\u7684\u9810\u5171\u4eab\u5bc6\u9470\"<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ael2tp-JQTjarTcMg\">\u914d\u7f6eL2TP<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u914d\u7f6eL2TP\u3002\u7de8\u8f2f<strong>\/etc\/xl2tpd\/xl2tpd.conf<\/strong>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>[lac vpn-connection]\n    lnsmux = yes\n    redial = yes\n    redial timeout = 5\n    require chap = yes\n    require authentication = yes\n    name = \"vpn-connection\"\n    ppp debug = yes\n    pppoptfile = \/etc\/ppp\/options.xl2tpd\n    length bit = yes\n<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u7de8\u8f2f<strong>\/etc\/ppp\/options.xl2tpd<\/strong>\u6587\u4ef6\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>require-chap\nrefuse-eap\nrefuse-pap\nrefuse-mschap\nrefuse-mschap-v2\nname \"vpn-connection\"\npassword \"\u60a8\u7684VPN\u5bc6\u78bc\"\nms-dns 8.8.8.8\nms-dns 8.8.4.4\nnodefaultroute\ndebug\nlock\n<\/code><\/pre>\n<h2 id=\"%e5%95%9f%e5%8b%95%e6%9c%8d%e5%8b%99-JQTjarTcMg\">\u555f\u52d5\u670d\u52d9<\/h2>\n<p>\u5b8c\u6210\u914d\u7f6e\u5f8c\uff0c\u60a8\u9700\u8981\u555f\u52d5IPsec\u548cL2TP\u670d\u52d9\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5\u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start ipsec\nsudo systemctl start xl2tpd<\/code><\/pre>\n<p>\u70ba\u4e86\u78ba\u4fdd\u670d\u52d9\u5728\u7cfb\u7d71\u555f\u52d5\u6642\u81ea\u52d5\u555f\u52d5\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>sudo systemctl enable ipsec\nsudo systemctl enable xl2tpd<\/code><\/pre>\n<h2 id=\"%e9%98%b2%e7%81%ab%e7%89%86%e8%a8%ad%e7%bd%ae-JQTjarTcMg\">\u9632\u706b\u7246\u8a2d\u7f6e<\/h2>\n<p>\u78ba\u4fdd\u9632\u706b\u7246\u5141\u8a31L2TP\u548cIPsec\u6d41\u91cf\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u958b\u653e\u76f8\u61c9\u7684\u7aef\u53e3\uff1a<\/p>\n<pre><code>sudo firewall-cmd --permanent --add-port=500\/udp\nsudo firewall-cmd --permanent --add-port=4500\/udp\nsudo firewall-cmd --permanent --add-port=1701\/udp\nsudo firewall-cmd --reload<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-JQTjarTcMg\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u7d93\u6210\u529f\u5728CentOS 7\u4e0a\u90e8\u7f72\u4e86L2TP VPN\u3002\u9019\u7a2e\u914d\u7f6e\u4e0d\u50c5\u80fd\u5920\u63d0\u4f9b\u5b89\u5168\u7684\u7db2\u7d61\u9023\u63a5\uff0c\u9084\u80fd\u5920\u4fdd\u8b77\u60a8\u7684\u96b1\u79c1\u3002\u5728\u9078\u64c7\u5408\u9069\u7684\u4f3a\u670d\u5668\u6642\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u4f86\u9032\u4e00\u6b65\u63d0\u5347\u60a8\u7684\u7db2\u7d61\u6027\u80fd\u548c\u5b89\u5168\u6027\u3002\u7121\u8ad6\u662f\u500b\u4eba\u4f7f\u7528\u9084\u662f\u5546\u696d\u9700\u6c42\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\u90fd\u80fd\u70ba\u60a8\u5e36\u4f86\u66f4\u597d\u7684\u9ad4\u9a57\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to deploy L2TP on CentOS 7 with step-by-step instructions for secure and efficient VPN setup.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43786","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43786"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43786\/revisions"}],"predecessor-version":[{"id":43787,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43786\/revisions\/43787"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}