{"id":1365,"date":"2026-09-09T18:33:26","date_gmt":"2026-09-09T10:33:26","guid":{"rendered":"https:\/\/www.suannai.link\/blog\/wireguard%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%e9%9a%be%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a%e4%bb%8e%e7%8e%af%e5%a2%83%e5%87%86%e5%a4%87%e5%88%b0%e9%85%8d%e7%bd%ae%e9%aa%8c%e8%af%81\/"},"modified":"2026-09-09T18:33:26","modified_gmt":"2026-09-09T10:33:26","slug":"wireguard%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%e9%9a%be%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a%e4%bb%8e%e7%8e%af%e5%a2%83%e5%87%86%e5%a4%87%e5%88%b0%e9%85%8d%e7%bd%ae%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"https:\/\/www.suannai.link\/blog\/wireguard%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%90%ad%e5%bb%ba%e9%9a%be%e5%ba%a6%e8%a7%a3%e6%9e%90%ef%bc%9a%e4%bb%8e%e7%8e%af%e5%a2%83%e5%87%86%e5%a4%87%e5%88%b0%e9%85%8d%e7%bd%ae%e9%aa%8c%e8%af%81\/","title":{"rendered":"WireGuard\u670d\u52a1\u5668\u642d\u5efa\u96be\u5ea6\u89e3\u6790\uff1a\u4ece\u73af\u5883\u51c6\u5907\u5230\u914d\u7f6e\u9a8c\u8bc1"},"content":{"rendered":"<p>WireGuard \u670d\u52a1\u5668\u642d\u5efa\u7684\u6838\u5fc3\u96be\u70b9\u5e76\u4e0d\u5728\u4e8e\u5b89\u88c5\u8f6f\u4ef6\u672c\u8eab\uff0c\u800c\u5728\u4e8e\u7f51\u7edc\u73af\u5883\u7684\u590d\u6742\u6027\u4e0e\u914d\u7f6e\u903b\u8f91\u7684\u4e25\u8c28\u6027\u3002\u5bf9\u4e8e\u666e\u901a\u7528\u6237\u800c\u8a00\uff0c\u6700\u5927\u7684\u969c\u788d\u901a\u5e38\u4e0d\u662f\u4ee3\u7801\u7f16\u5199\uff0c\u800c\u662f\u5bf9 IP \u5730\u5740\u89c4\u5212\u3001\u9632\u706b\u5899\u89c4\u5219\u4ee5\u53ca NAT \u7a7f\u900f\u673a\u5236\u7684\u7406\u89e3\u3002\u53ea\u8981\u7406\u6e05\u4e86\u201c\u670d\u52a1\u5668\u7aef\u201d\u4e0e\u201c\u5ba2\u6237\u7aef\u201d\u4e4b\u95f4\u7684\u901a\u4fe1\u903b\u8f91\uff0c\u642d\u5efa\u8fc7\u7a0b\u5b9e\u9645\u4e0a\u662f\u9ad8\u5ea6\u6807\u51c6\u5316\u7684\u3002\u672c\u6587\u5c06\u62c6\u89e3\u642d\u5efa\u8fc7\u7a0b\u4e2d\u7684\u5173\u952e\u6b65\u9aa4\uff0c\u91cd\u70b9\u89e3\u51b3<a href=\"https:\/\/www.suannai.link\/blog\/wireguard%e5%ae%89%e8%a3%85%ef%bc%9a%e4%bb%8e%e7%8e%af%e5%a2%83%e5%87%86%e5%a4%87%e5%88%b0%e9%85%8d%e7%bd%ae%e9%aa%8c%e8%af%81%e7%9a%84%e5%ae%8c%e6%95%b4%e6%ad%a5%e9%aa%a4\/\" target=\"_blank\" rel=\"noopener\">\u73af\u5883\u68c0\u67e5<\/a>\u3001\u914d\u7f6e\u903b\u8f91\u3001\u9632\u706b\u5899\u653e\u884c\u4ee5\u53ca\u8fde\u901a\u6027\u9a8c\u8bc1\u8fd9\u56db\u4e2a\u6838\u5fc3\u73af\u8282\uff0c\u5e2e\u52a9\u4f60\u5224\u65ad\u81ea\u8eab\u6280\u672f\u80fd\u529b\u662f\u5426\u8db3\u4ee5\u72ec\u7acb\u5b8c\u6210\u90e8\u7f72\u3002<\/p>\n<h2>\u73af\u5883\u51c6\u5907\u4e0e\u7cfb\u7edf\u517c\u5bb9\u6027\u5224\u65ad<\/h2>\n<p>\u5728\u5f00\u59cb\u914d\u7f6e\u4e4b\u524d\uff0c\u9996\u8981\u4efb\u52a1\u662f\u786e\u8ba4\u8fd0\u884c\u73af\u5883\u7684\u517c\u5bb9\u6027\u3002WireGuard \u4f9d\u8d56\u4e8e Linux \u5185\u6838\u6a21\u5757\uff0c\u56e0\u6b64\u64cd\u4f5c\u7cfb\u7edf\u7684\u5185\u6838\u7248\u672c\u76f4\u63a5\u51b3\u5b9a\u4e86\u642d\u5efa\u7684\u96be\u6613\u7a0b\u5ea6\u3002<\/p>\n<p><strong>1. \u5185\u6838\u7248\u672c\u68c0\u67e5<\/strong><br \/>WireGuard \u539f\u751f\u96c6\u6210\u5728 Linux 5.6+ \u5185\u6838\u4e2d\u3002\u5982\u679c\u4f60\u7684\u670d\u52a1\u5668\u8fd0\u884c\u7684\u662f\u8f83\u65b0\u7684\u53d1\u884c\u7248\uff08\u5982 Ubuntu 22.04\/24.04\u3001Debian 11\/12\u3001CentOS Stream 9 \u6216 AlmaLinux 9\uff09\uff0c\u901a\u5e38\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5\uff0c\u65e0\u9700\u7f16\u8bd1\u5185\u6838\uff0c\u96be\u5ea6\u8f83\u4f4e\u3002<br \/>\u82e5\u4f7f\u7528\u8f83\u65e7\u7684\u64cd\u4f5c\u7cfb\u7edf\uff08\u5982 CentOS 7 \u6216 Ubuntu 18.04\uff09\uff0c\u5219\u9700\u8981\u624b\u52a8\u5b89\u88c5 ELRepo \u6216 DKMS \u6a21\u5757\uff0c\u6216\u8005\u4ece\u6e90\u7801\u7f16\u8bd1\u5185\u6838\u6a21\u5757\u3002\u8fd9\u4e00\u6b65\u9aa4\u6781\u6613\u56e0\u4f9d\u8d56\u7f3a\u5931\u800c\u5931\u8d25\uff0c\u663e\u8457\u589e\u52a0\u642d\u5efa\u96be\u5ea6\u3002<\/p>\n<p><strong>2. \u865a\u62df\u5316\u73af\u5883\u7684\u5f71\u54cd<\/strong><br \/>\u8bb8\u591a\u7528\u6237\u8fd0\u884c\u5728 KVM\u3001VMware \u6216 VirtualBox \u7b49\u865a\u62df\u5316\u5e73\u53f0\u4e0a\u3002<br \/>\u2022 <strong>KVM\/Xen<\/strong>\uff1a\u901a\u5e38\u652f\u6301\u5185\u6838\u6a21\u5757\u52a0\u8f7d\uff0c\u642d\u5efa\u96be\u5ea6\u6b63\u5e38\u3002<br \/>\u2022 <strong>OpenVZ\/LXC<\/strong>\uff1a\u8fd9\u7c7b\u5bb9\u5668\u5316\u73af\u5883\u65e0\u6cd5\u52a0\u8f7d\u5185\u6838\u6a21\u5757\uff0c\u56e0\u6b64<strong>\u65e0\u6cd5<\/strong>\u5728\u5bb9\u5668\u5185\u90e8\u76f4\u63a5\u642d\u5efa WireGuard \u670d\u52a1\u7aef\u3002\u4f60\u5fc5\u987b\u4f7f\u7528 iptables\/nftables \u8fdb\u884c\u8f6c\u53d1\uff0c\u6216\u8005\u5728\u5bbf\u4e3b\u673a\u4e0a\u642d\u5efa\u3002\u8fd9\u662f\u65b0\u624b\u6700\u5bb9\u6613\u8e29\u7684\u5751\uff0c\u5bfc\u81f4\u914d\u7f6e\u5b8c\u5ba2\u6237\u7aef\u65e0\u6cd5\u8fde\u63a5\u3002<\/p>\n<p><strong>\u5224\u65ad\u6807\u51c6<\/strong>\uff1a\u5728\u7ec8\u7aef\u8f93\u5165 `uname -r` \u67e5\u770b\u5185\u6838\u7248\u672c\u3002\u5982\u679c\u5185\u6838\u4f4e\u4e8e 5.6 \u4e14\u4f60\u4f7f\u7528\u7684\u662f OpenVZ \u73af\u5883\uff0c\u642d\u5efa\u96be\u5ea6\u5c06\u5448\u6307\u6570\u7ea7\u4e0a\u5347\uff0c\u5efa\u8bae\u76f4\u63a5\u6539\u7528\u57fa\u4e8e\u7528\u6237\u6001\u7684\u89e3\u51b3\u65b9\u6848\u6216\u5347\u7ea7\u5bbf\u4e3b\u673a\u3002<\/p>\n\n<h2>\u5bc6\u94a5\u751f\u6210\u4e0e\u914d\u7f6e\u903b\u8f91\u89e3\u6790<\/h2>\n<p>WireGuard \u7684\u914d\u7f6e\u6838\u5fc3\u5728\u4e8e\u201c\u975e\u5bf9\u79f0\u5bc6\u94a5\u5bf9\u201d\u7684\u751f\u6210\u4e0e\u914d\u5bf9\u3002\u7406\u89e3\u8fd9\u4e00\u903b\u8f91\u662f\u964d\u4f4e\u96be\u5ea6\u7684\u5173\u952e\u3002<\/p>\n<p><strong>1. \u5bc6\u94a5\u751f\u6210\u7684\u5b89\u5168\u6027<\/strong><br \/>\u670d\u52a1\u5668\u7aef\u548c\u5ba2\u6237\u7aef\u90fd\u9700\u8981\u751f\u6210\u4e00\u5bf9\u79c1\u94a5\uff08Private Key\uff09\u548c\u516c\u94a5\uff08Public Key\uff09\u3002<br \/>\u2022 <strong>\u64cd\u4f5c\u903b\u8f91<\/strong>\uff1a\u4f7f\u7528 `wg genkey` \u751f\u6210\u79c1\u94a5\uff0c\u518d\u901a\u8fc7 `wg pubkey` \u4ece\u79c1\u94a5\u6d3e\u751f\u516c\u94a5\u3002<br \/>\u2022 <strong>\u5e38\u89c1\u9519\u8bef<\/strong>\uff1a\u6df7\u6dc6\u516c\u79c1\u94a5\uff0c\u6216\u5c06\u5ba2\u6237\u7aef\u7684\u79c1\u94a5\u8bef\u586b\u5230\u670d\u52a1\u5668\u7684 AllowedPeers \u5b57\u6bb5\u4e2d\u3002<br \/>\u2022 <strong>\u6b63\u786e\u505a\u6cd5<\/strong>\uff1a\u670d\u52a1\u5668\u6301\u6709\u81ea\u5df1\u7684\u79c1\u94a5\uff0c\u5e76\u5c06\u6240\u6709\u5ba2\u6237\u7aef\u7684\u516c\u94a5\u586b\u5165 AllowedPeers\uff1b\u5ba2\u6237\u7aef\u6301\u6709\u81ea\u5df1\u7684\u79c1\u94a5\uff0c\u5e76\u5c06\u670d\u52a1\u5668\u7684\u516c\u94a5\u586b\u5165 Endpoint \u5bf9\u5e94\u7684 Peer \u5757\u4e2d\u3002<\/p>\n<p><strong>2. \u914d\u7f6e\u6587\u4ef6\u7ed3\u6784\u62c6\u89e3<\/strong><br \/>WireGuard \u7684\u914d\u7f6e\u6587\u4ef6\uff08\u901a\u5e38\u4e3a `wg0.conf`\uff09\u5206\u4e3a `[Interface]` \u548c `[Peer]` \u4e24\u90e8\u5206\u3002<\/p>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;\">\n<thead>\n<tr>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u914d\u7f6e\u533a\u5757<\/th>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u5173\u952e\u5b57\u6bb5<\/th>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u4f5c\u7528\u8bf4\u660e<\/th>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u6613\u9519\u70b9<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Interface<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">PrivateKey<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u672c\u7aef\u79c1\u94a5\uff0c\u7528\u4e8e\u89e3\u5bc6\u6570\u636e<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u79c1\u94a5\u6cc4\u9732\u5373\u5bfc\u81f4\u670d\u52a1\u5931\u63a7<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Interface<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Address<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u670d\u52a1\u5668\u865a\u62df IP \u53ca\u5b50\u7f51<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u9700\u786e\u4fdd\u4e0d\u4e0e\u5c40\u57df\u7f51 IP \u51b2\u7a81<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Interface<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">ListenPort<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u76d1\u542c\u7aef\u53e3\uff08\u9ed8\u8ba4 51820\uff09<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u9700\u4e0e\u9632\u706b\u5899\u5165\u7ad9\u89c4\u5219\u4e00\u81f4<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Interface<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">PostUp\/Down<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u9632\u706b\u5899\u4e0e\u8def\u7531\u811a\u672c<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u811a\u672c\u8bed\u6cd5\u9519\u8bef\u5bfc\u81f4\u670d\u52a1\u8d77\u4e0d\u6765<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Peer<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">PublicKey<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u5bf9\u7aef\u516c\u94a5<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u516c\u79c1\u94a5\u5bf9\u5e94\u5173\u7cfb\u9519\u8bef<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Peer<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">AllowedIPs<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u5141\u8bb8\u8def\u7531\u7684 IP \u8303\u56f4<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u8bbe\u4e3a 0.0.0.0\/0 \u8868\u793a\u6240\u6709\u6d41\u91cf\u8d70\u96a7\u9053<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Peer<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">Endpoint<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u5ba2\u6237\u7aef IP \u548c\u7aef\u53e3<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u670d\u52a1\u5668\u7aef\u901a\u5e38\u7559\u7a7a\uff0c\u7531\u5ba2\u6237\u7aef\u4e3b\u52a8\u53d1\u8d77<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u914d\u7f6e\u5efa\u8bae<\/strong>\uff1a<br \/>\u2022 <strong>Address \u8bbe\u7f6e<\/strong>\uff1a\u670d\u52a1\u5668\u7aef\u5efa\u8bae\u8bbe\u7f6e\u4e3a `10.8.0.1\/24` \u6216 `192.168.4.1\/24`\u3002\u5fc5\u987b\u786e\u4fdd\u8fd9\u4e2a\u7f51\u6bb5\u6ca1\u6709\u88ab\u4f60\u7684\u672c\u5730\u7f51\u7edc\u6216\u5176\u4ed6\u670d\u52a1\u5360\u7528\u3002<br \/>\u2022 <strong>AllowedIPs \u8bbe\u7f6e<\/strong>\uff1a\u5982\u679c\u5e0c\u671b\u6240\u6709\u6d41\u91cf\u90fd\u7ecf\u8fc7\u96a7\u9053\uff0c\u8bbe\u7f6e\u4e3a `0.0.0.0\/0`\uff08IPv4\uff09\u548c `::\/0`\uff08IPv6\uff09\u3002\u5982\u679c\u53ea\u5e0c\u671b\u8bbf\u95ee\u7279\u5b9a\u5185\u7f51\u8d44\u6e90\uff0c\u9700\u7cbe\u786e\u6307\u5b9a\u5b50\u7f51\u3002<\/p>\n<h2>\u9632\u706b\u5899\u4e0e\u8def\u7531\u8f6c\u53d1\u914d\u7f6e<\/h2>\n<p>\u8fd9\u662f\u642d\u5efa\u8fc7\u7a0b\u4e2d<strong>\u96be\u5ea6\u6700\u9ad8<\/strong>\u4e14<strong>\u5931\u8d25\u7387\u6700\u9ad8<\/strong>\u7684\u73af\u8282\u3002WireGuard \u5efa\u7acb\u96a7\u9053\u540e\uff0c\u6570\u636e\u9700\u8981\u5728\u670d\u52a1\u5668\u5185\u90e8\u8fdb\u884c\u8def\u7531\u8f6c\u53d1\uff0c\u5e76\u5728\u5916\u90e8\u901a\u8fc7\u9632\u706b\u5899\u653e\u884c\u3002<\/p>\n<p><strong>1. \u542f\u7528 IP \u8f6c\u53d1<\/strong><br \/>Linux \u9ed8\u8ba4\u7981\u6b62 IP \u8f6c\u53d1\u3002\u4f60\u9700\u8981\u4fee\u6539 `\/etc\/sysctl.conf` \u6587\u4ef6\uff0c\u5c06 `net.ipv4.ip_forward` \u8bbe\u7f6e\u4e3a `1`\uff0c\u5e76\u6267\u884c `sysctl -p` \u751f\u6548\u3002<br \/>\u2022 <strong>\u539f\u56e0<\/strong>\uff1a\u5982\u679c\u4e0d\u542f\u7528\u8f6c\u53d1\uff0c\u670d\u52a1\u5668\u53ea\u80fd\u5904\u7406\u53d1\u5f80\u81ea\u8eab\u7684\u6d41\u91cf\uff0c\u65e0\u6cd5\u5c06\u96a7\u9053\u5185\u7684\u6d41\u91cf\u8f6c\u53d1\u5230\u4e92\u8054\u7f51\u3002<\/p>\n<p><strong>2. \u9632\u706b\u5899\u89c4\u5219\uff08iptables\/nftables\uff09<\/strong><br \/>\u4f60\u9700\u8981\u5f00\u653e UDP 51820 \u7aef\u53e3\uff0c\u5e76\u8bbe\u7f6e MASQUERADE\uff08\u6e90\u5730\u5740\u4f2a\u88c5\uff09\u89c4\u5219\u3002<\/p>\n<p>&#8220;`bash<\/p>\n<h2>\u793a\u4f8b\u903b\u8f91\uff08\u5177\u4f53\u547d\u4ee4\u53d6\u51b3\u4e8e\u4f60\u4f7f\u7528\u7684\u9632\u706b\u5899\u5de5\u5177\uff09<\/h2>\n<p><\/p>\n<h2>1. \u5141\u8bb8 WireGuard \u7aef\u53e3<\/h2>\n<p>iptables -A INPUT -p udp &#8211;dport 51820 -j ACCEPT<\/p>\n<h2>2. \u8bbe\u7f6e NAT \u4f2a\u88c5\uff0c\u4f7f\u96a7\u9053\u6d41\u91cf\u80fd\u8bbf\u95ee\u5916\u7f51<\/h2>\n<p>iptables -t nat -A POSTROUTING -s 10.8.0.0\/24 -o eth0 -j MASQUERADE<\/p>\n<h2>3. \u5141\u8bb8\u8f6c\u53d1<\/h2>\n<p>iptables -A FORWARD -i wg0 -j ACCEPT<br \/>iptables -A FORWARD -o wg0 -j ACCEPT<br \/>&#8220;`<\/p>\n<p><strong>\u5e38\u89c1\u6545\u969c\u70b9<\/strong>\uff1a<br \/>\u2022 <strong>\u4e91\u670d\u52a1\u5546\u5b89\u5168\u7ec4<\/strong>\uff1a\u9664\u4e86\u670d\u52a1\u5668\u5185\u90e8\u7684\u9632\u706b\u5899\uff0c\u4e91\u5382\u5546\uff08\u5982\u963f\u91cc\u4e91\u3001\u817e\u8baf\u4e91\u3001AWS\uff09\u901a\u5e38\u8fd8\u6709\u5916\u90e8\u7684\u201c\u5b89\u5168\u7ec4\u201d\u6216\u201c\u9632\u706b\u5899\u201d\u7b56\u7565\u3002\u5982\u679c\u672a\u5728\u63a7\u5236\u53f0\u5f00\u653e UDP 51820\uff0c\u5916\u90e8\u6d41\u91cf\u6839\u672c\u5230\u8fbe\u4e0d\u4e86\u670d\u52a1\u5668\u3002\u8fd9\u662f\u65b0\u624b\u6700\u5bb9\u6613\u5ffd\u7565\u7684\u4e00\u6b65\u3002<br \/>\u2022 <strong>\u9632\u706b\u5899\u91cd\u8f7d<\/strong>\uff1a\u4fee\u6539 iptables \u89c4\u5219\u540e\uff0c\u90e8\u5206\u7cfb\u7edf\u9700\u8981\u91cd\u542f\u670d\u52a1\u6216\u4fdd\u5b58\u89c4\u5219\uff08\u5982 `iptables-save`\uff09\uff0c\u5426\u5219\u91cd\u542f\u540e\u914d\u7f6e\u4e22\u5931\u3002<\/p>\n<h2>\u5ba2\u6237\u7aef\u914d\u7f6e\u4e0e\u8fde\u901a\u6027\u9a8c\u8bc1<\/h2>\n<p>\u670d\u52a1\u5668\u7aef\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u642d\u5efa\u5de5\u4f5c\u53ea\u5b8c\u6210\u4e86\u4e00\u534a\u3002\u5ba2\u6237\u7aef\u7684\u6b63\u786e\u914d\u7f6e\u548c\u8fde\u901a\u6027\u6d4b\u8bd5\u662f\u6700\u7ec8\u9a8c\u8bc1\u73af\u8282\u3002<\/p>\n<p><strong>1. \u5ba2\u6237\u7aef\u914d\u7f6e\u8981\u70b9<\/strong><br \/>\u5728\u5ba2\u6237\u7aef\uff08\u624b\u673a\u6216\u7535\u8111\uff09\u5bfc\u5165\u914d\u7f6e\u6587\u4ef6\u65f6\uff0c\u9700\u7279\u522b\u6ce8\u610f\u4ee5\u4e0b\u5b57\u6bb5\uff1a<br \/>\u2022 <strong>PrivateKey<\/strong>\uff1a\u5ba2\u6237\u7aef\u81ea\u5df1\u7684\u79c1\u94a5\u3002<br \/>\u2022 <strong>PublicKey<\/strong>\uff1a\u670d\u52a1\u5668\u7684\u516c\u94a5\u3002<br \/>\u2022 <strong>Endpoint<\/strong>\uff1a\u670d\u52a1\u5668\u7684\u516c\u7f51 IP \u548c\u7aef\u53e3\uff08\u683c\u5f0f\uff1a`IP:Port`\uff09\u3002<br \/>\u2022 <strong>PersistentKeepalive<\/strong>\uff1a\u5efa\u8bae\u8bbe\u7f6e\u4e3a `25`\u3002<br \/>\u2022 <strong>\u539f\u56e0<\/strong>\uff1a\u5728 NAT \u73af\u5883\u4e0b\uff0c\u957f\u65f6\u95f4\u65e0\u6d41\u91cf\u4f1a\u5bfc\u81f4\u8fde\u63a5\u65ad\u5f00\u3002\u5f00\u542f Keepalive \u53ef\u5b9a\u671f\u53d1\u9001\u5fc3\u8df3\u5305\uff0c\u7ef4\u6301\u8fde\u63a5\u72b6\u6001\uff0c\u663e\u8457\u63d0\u5347\u7a33\u5b9a\u6027\u3002<\/p>\n<p><strong>2. \u8fde\u901a\u6027\u9a8c\u8bc1\u6b65\u9aa4<\/strong><br \/>\u4e0d\u8981\u4ec5\u51ed\u201c\u663e\u793a\u5df2\u8fde\u63a5\u201d\u5c31\u8ba4\u4e3a\u642d\u5efa\u6210\u529f\uff0c\u9700\u8fdb\u884c\u5206\u5c42\u6d4b\u8bd5\uff1a<br \/>\u2022 <strong>\u96a7\u9053\u5efa\u7acb\u6d4b\u8bd5<\/strong>\uff1a\u68c0\u67e5\u5ba2\u6237\u7aef\u65e5\u5fd7\uff0c\u786e\u8ba4\u662f\u5426\u751f\u6210\u4e86\u52a0\u5bc6\u5bc6\u94a5\u5bf9\u5e76\u5efa\u7acb\u4e86\u4f1a\u8bdd\u3002<br \/>\u2022 <strong>\u5185\u7f51\u4e92\u901a\u6d4b\u8bd5<\/strong>\uff1a\u5728\u5ba2\u6237\u7aef ping \u670d\u52a1\u5668\u7684\u865a\u62df IP\uff08\u5982 `ping 10.8.0.1`\uff09\u3002\u5982\u679c\u901a\uff0c\u8bf4\u660e\u96a7\u9053\u5c42\u6b63\u5e38\u3002<br \/>\u2022 <strong>\u5916\u7f51\u8def\u7531\u6d4b\u8bd5<\/strong>\uff1a\u5728\u5ba2\u6237\u7aef ping \u516c\u7f51 DNS\uff08\u5982 `ping 8.8.8.8` \u6216 `ping 1.1.1.1`\uff09\u3002\u5982\u679c\u4e0d\u901a\uff0c\u8bf4\u660e\u9632\u706b\u5899 NAT \u8f6c\u53d1\u672a\u751f\u6548\u6216\u8def\u7531\u914d\u7f6e\u9519\u8bef\u3002<br \/>\u2022 <strong>\u5b9e\u9645\u8bbf\u95ee\u6d4b\u8bd5<\/strong>\uff1a\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\u7f51\u9875\uff0c\u6216\u4f7f\u7528 `curl ifconfig.me` \u67e5\u770b\u51fa\u53e3 IP \u662f\u5426\u53d8\u4e3a\u670d\u52a1\u5668 IP\u3002<\/p>\n<p><strong>\u6545\u969c\u6392\u67e5\u5bf9\u7167\u8868<\/strong>\uff1a<\/p>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;\">\n<thead>\n<tr>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u73b0\u8c61<\/th>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u53ef\u80fd\u539f\u56e0<\/th>\n<th style=\"border:1px solid #ddd;padding:10px;background:#f7f7f7;text-align:left;\">\u5904\u7406\u65b9\u5411<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u5ba2\u6237\u7aef\u663e\u793a\u201c\u5df2\u8fde\u63a5\u201d\u4f46\u65e0\u6cd5\u4e0a\u7f51<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">NAT \u8f6c\u53d1\u672a\u5f00\u542f\u6216\u9632\u706b\u5899\u672a\u653e\u884c<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u68c0\u67e5 `sysctl ip_forward` \u548c iptables MASQUERADE \u89c4\u5219<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u5ba2\u6237\u7aef\u65e0\u6cd5\u8fde\u63a5\u5230\u670d\u52a1\u5668<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u7aef\u53e3\u672a\u5f00\u653e\u6216 IP \u9519\u8bef<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u68c0\u67e5\u4e91\u63a7\u5236\u53f0\u5b89\u5168\u7ec4\u53ca\u670d\u52a1\u5668\u5185\u90e8\u9632\u706b\u5899<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u5076\u5c14\u65ad\u8fde<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">NAT \u8d85\u65f6<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u68c0\u67e5\u5ba2\u6237\u7aef `PersistentKeepalive` \u662f\u5426\u8bbe\u7f6e<\/td>\n<\/tr>\n<tr>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u670d\u52a1\u5668 ping \u4e0d\u901a\u5ba2\u6237\u7aef<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">AllowedIPs \u914d\u7f6e\u9519\u8bef<\/td>\n<td style=\"border:1px solid #ddd;padding:10px;vertical-align:top;\">\u68c0\u67e5\u670d\u52a1\u5668\u7aef Peer \u7684 AllowedIPs \u662f\u5426\u5305\u542b\u5ba2\u6237\u7aef IP<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><\/p>\n<h2>\u642d\u5efa\u96be\u5ea6\u603b\u7ed3\u4e0e\u9002\u7528\u4eba\u7fa4\u5efa\u8bae<\/h2>\n<p>\u7efc\u5408\u6765\u770b\uff0cWireGuard \u670d\u52a1\u5668\u7684\u642d\u5efa\u96be\u5ea6\u5c5e\u4e8e<strong>\u4e2d\u7b49\u504f\u4e0a<\/strong>\uff0c\u4e3b\u8981\u96be\u70b9\u4e0d\u5728\u4e8e\u6280\u672f\u95e8\u69db\uff0c\u800c\u5728\u4e8e<strong>\u7f51\u7edc\u73af\u5883\u7684\u590d\u6742\u6027<\/strong>\u3002<br \/>\u2022 <strong>\u9002\u5408\u4eba\u7fa4<\/strong>\uff1a\u5177\u5907\u57fa\u7840 Linux \u547d\u4ee4\u884c\u64cd\u4f5c\u80fd\u529b\uff0c\u7406\u89e3 IP \u5730\u5740\u3001\u7aef\u53e3\u3001\u9632\u706b\u5899\u57fa\u672c\u6982\u5ff5\u7684\u7528\u6237\u3002<br \/>\u2022 <strong>\u4e0d\u9002\u5408\u4eba\u7fa4<\/strong>\uff1a\u5b8c\u5168\u4e0d\u61c2\u547d\u4ee4\u884c\u3001\u65e0\u6cd5\u8bbf\u95ee\u670d\u52a1\u5668\u63a7\u5236\u53f0\u3001\u6216\u5bf9\u7f51\u7edc\u8def\u7531\u539f\u7406\u4e00\u65e0\u6240\u77e5\u7684\u7528\u6237\u3002<\/p>\n<p><strong>\u964d\u4f4e\u96be\u5ea6\u7684\u5efa\u8bae<\/strong>\uff1a<br \/>\u2022 <strong>\u4f7f\u7528\u811a\u672c<\/strong>\uff1a\u5bf9\u4e8e\u65b0\u624b\uff0c\u63a8\u8350\u4f7f\u7528\u7ecf\u8fc7\u9a8c\u8bc1\u7684\u4e00\u952e\u5b89\u88c5\u811a\u672c\uff08\u5982 `wg-quick` \u7684\u793e\u533a\u7ef4\u62a4\u7248\uff09\u3002\u811a\u672c\u53ef\u4ee5\u81ea\u52a8\u5904\u7406\u5185\u6838\u6a21\u5757\u5b89\u88c5\u3001\u9632\u706b\u5899\u89c4\u5219\u751f\u6210\u7b49\u7e41\u7410\u6b65\u9aa4\uff0c\u5c06\u642d\u5efa\u96be\u5ea6\u964d\u4f4e\u81f3\u201c\u590d\u5236\u7c98\u8d34\u201d\u7ea7\u522b\u3002<br \/>\u2022 <strong>\u4f18\u5148\u68c0\u67e5\u5b89\u5168\u7ec4<\/strong>\uff1a\u5728\u914d\u7f6e\u670d\u52a1\u5668\u5185\u90e8\u89c4\u5219\u524d\uff0c\u52a1\u5fc5\u5148\u786e\u8ba4\u4e91\u670d\u52a1\u5546\u7684\u5916\u90e8\u9632\u706b\u5899\u5df2\u5f00\u653e UDP 51820 \u7aef\u53e3\u3002<br \/>\u2022 <strong>\u4fdd\u6301\u914d\u7f6e\u7b80\u6d01<\/strong>\uff1a\u521d\u671f\u907f\u514d\u4f7f\u7528\u590d\u6742\u7684\u7b56\u7565\u8def\u7531\u6216 IPv6 \u591a\u6808\u914d\u7f6e\uff0c\u5148\u786e\u4fdd IPv4 \u5355\u6808\u8fde\u901a\uff0c\u518d\u9010\u6b65\u6269\u5c55\u3002<\/p>\n<p>\u901a\u8fc7\u7406\u89e3\u4e0a\u8ff0\u914d\u7f6e\u903b\u8f91\u548c\u6392\u67e5\u8def\u5f84\uff0c\u4f60\u53ef\u4ee5\u66f4\u6e05\u6670\u5730\u8bc4\u4f30\u81ea\u8eab\u7684\u6280\u672f\u50a8\u5907\uff0c\u5e76\u9488\u5bf9\u6027\u5730\u89e3\u51b3\u642d\u5efa\u8fc7\u7a0b\u4e2d\u9047\u5230\u7684\u5177\u4f53\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WireGuard \u670d\u52a1\u5668\u642d\u5efa\u7684\u6838\u5fc3\u96be\u70b9\u5e76\u4e0d\u5728\u4e8e\u5b89\u88c5\u8f6f\u4ef6\u672c\u8eab\uff0c\u800c\u5728\u4e8e\u7f51\u7edc\u73af\u5883\u7684\u590d\u6742\u6027\u4e0e\u914d\u7f6e\u903b\u8f91\u7684\u4e25\u8c28\u6027\u3002\u5bf9\u4e8e\u666e [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1365","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/posts\/1365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/comments?post=1365"}],"version-history":[{"count":0,"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/posts\/1365\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/media?parent=1365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/categories?post=1365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.suannai.link\/blog\/wp-json\/wp\/v2\/tags?post=1365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}