{"id":78139,"date":"2026-02-26T09:25:11","date_gmt":"2026-02-26T01:25:11","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/78139.html"},"modified":"2026-02-26T09:25:11","modified_gmt":"2026-02-26T01:25:11","slug":"wireguard%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%ef%bc%9a%e5%9c%a8ubuntu%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a%e9%85%8d%e7%bd%aemtu%e5%92%8c%e6%8c%81%e4%b9%85%e5%8c%96keepalive","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/78139.html","title":{"rendered":"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive"},"content":{"rendered":"<h2>WireGuard\u6027\u80fd\u8c03\u4f18\u5b9e\u6218&#xff1a;MTU\u4e0e\u6301\u4e45\u5316Keepalive\u7684\u6df1\u5ea6\u89e3\u6790<\/h2>\n<p>\u5728\u5f53\u4eca\u9ad8\u901f\u53d1\u5c55\u7684\u7f51\u7edc\u73af\u5883\u4e2d&#xff0c;WireGuard\u4ee5\u5176\u7b80\u6d01\u9ad8\u6548\u7684\u8bbe\u8ba1\u7406\u5ff5\u8d62\u5f97\u4e86\u5e7f\u6cdb\u9752\u7750\u3002\u7136\u800c&#xff0c;\u8bb8\u591a\u7528\u6237\u5728\u57fa\u7840\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u5e38\u4f1a\u9047\u5230\u8fde\u63a5\u4e0d\u7a33\u5b9a\u6216\u4f20\u8f93\u901f\u5ea6\u4e0d\u7406\u60f3\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u4e24\u4e2a\u5173\u952e\u6027\u80fd\u4f18\u5316\u53c2\u6570\u2014\u2014MTU\u8bbe\u7f6e\u4e0e\u6301\u4e45\u5316Keepalive\u673a\u5236&#xff0c;\u5e2e\u52a9\u60a8\u6253\u9020\u66f4\u7a33\u5b9a\u9ad8\u6548\u7684WireGuard\u7f51\u7edc\u73af\u5883\u3002<\/p>\n<h3>1. \u7406\u89e3WireGuard\u6027\u80fd\u74f6\u9888<\/h3>\n<p>WireGuard\u867d\u7136\u4ee5\u9ad8\u6548\u8457\u79f0&#xff0c;\u4f46\u5728\u5b9e\u9645\u90e8\u7f72\u4e2d\u4ecd\u53ef\u80fd\u9762\u4e34\u5404\u79cd\u6027\u80fd\u6311\u6218\u3002\u5f53\u60a8\u53d1\u73b0\u8fde\u63a5\u65f6\u65ad\u65f6\u7eed\u3001\u4f20\u8f93\u901f\u5ea6\u8fdc\u4f4e\u4e8e\u9884\u671f\u5e26\u5bbd&#xff0c;\u6216\u8005\u5728\u67d0\u4e9b\u7f51\u7edc\u73af\u5883\u4e0b\u5b8c\u5168\u65e0\u6cd5\u5efa\u7acb\u8fde\u63a5\u65f6&#xff0c;\u8fd9\u4e9b\u95ee\u9898\u5f80\u5f80\u6e90\u4e8e\u4e24\u4e2a\u6838\u5fc3\u56e0\u7d20&#xff1a;<\/p>\n<ul>\n<li>MTU&#xff08;\u6700\u5927\u4f20\u8f93\u5355\u5143&#xff09;\u4e0d\u5339\u914d&#xff1a;\u5bfc\u81f4\u6570\u636e\u5305\u5206\u7247\u548c\u91cd\u7ec4&#xff0c;\u663e\u8457\u964d\u4f4e\u4f20\u8f93\u6548\u7387<\/li>\n<li>NAT\/\u9632\u706b\u5899\u8d85\u65f6&#xff1a;\u5728\u6ca1\u6709\u6301\u7eed\u6d41\u91cf\u65f6\u4e2d\u65ad\u8fde\u63a5&#xff0c;\u5f71\u54cd\u670d\u52a1\u53ef\u7528\u6027<\/li>\n<\/ul>\n<p>\u6211\u66fe\u5728\u4e00\u4e2a\u8de8\u56fd\u4f01\u4e1a\u9879\u76ee\u4e2d\u9047\u5230\u5178\u578b\u573a\u666f&#xff1a;\u56e2\u961f\u5206\u5e03\u5728\u4e09\u4e2a\u5927\u6d32\u7684\u529e\u516c\u5ba4\u901a\u8fc7WireGuard\u4e92\u8054&#xff0c;\u521d\u671f\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u4e9a\u6d32\u4e0e\u6b27\u6d32\u8282\u70b9\u95f4\u7684\u6587\u4ef6\u4f20\u8f93\u901f\u5ea6\u53ea\u6709\u7406\u8bba\u503c\u768430%&#xff0c;\u4e14\u6bcf\u969420\u5206\u949f\u5de6\u53f3\u5c31\u4f1a\u65ad\u5f00\u8fde\u63a5\u3002\u7ecf\u8fc7\u7cfb\u7edf\u6392\u67e5&#xff0c;\u6700\u7ec8\u53d1\u73b0\u662fMTU\u8bbe\u7f6e\u4e0d\u5f53\u548c\u7f3a\u4e4fKeepalive\u673a\u5236\u6240\u81f4\u3002<\/p>\n<h3>2. MTU\u4f18\u5316&#xff1a;\u6d88\u9664\u6570\u636e\u5305\u5206\u7247<\/h3>\n<h4>2.1 MTU\u7684\u6838\u5fc3\u6982\u5ff5<\/h4>\n<p>MTU&#xff08;Maximum Transmission Unit&#xff09;\u51b3\u5b9a\u4e86\u5355\u6b21\u6570\u636e\u4f20\u8f93\u7684\u6700\u5927\u5c3a\u5bf8\u3002WireGuard\u9ed8\u8ba4\u4f7f\u75281420\u5b57\u8282\u7684MTU&#xff08;\u5728\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u4e2d&#xff09;&#xff0c;\u4f46\u8fd9\u4e2a\u503c\u5e76\u975e\u653e\u4e4b\u56db\u6d77\u800c\u7686\u51c6\u3002<\/p>\n<p>\u5e38\u89c1\u7f51\u7edc\u73af\u5883\u7684MTU\u53c2\u8003\u503c&#xff1a;<\/p>\n<table>\n<tr>\u7f51\u7edc\u7c7b\u578b\u5178\u578bMTU\u503c\u5907\u6ce8<\/tr>\n<tbody>\n<tr>\n<td>\u6807\u51c6\u4ee5\u592a\u7f51<\/td>\n<td>1500<\/td>\n<td>\u6700\u5e38\u89c1\u7684\u57fa\u7840\u503c<\/td>\n<\/tr>\n<tr>\n<td>PPPoE<\/td>\n<td>1492<\/td>\n<td>\u9700\u8003\u86518\u5b57\u8282\u5f00\u9500<\/td>\n<\/tr>\n<tr>\n<td>\u4e91\u670d\u52a1VPC<\/td>\n<td>9001<\/td>\n<td>AWS\u7b49\u4e91\u5e73\u53f0\u7684\u5de8\u578b\u5e27<\/td>\n<\/tr>\n<tr>\n<td>4G\u79fb\u52a8\u7f51\u7edc<\/td>\n<td>1400-1500<\/td>\n<td>\u6ce2\u52a8\u8f83\u5927\u9700\u5b9e\u6d4b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>2.2 \u8bca\u65adMTU\u95ee\u9898<\/h4>\n<p>\u5728Ubuntu\u670d\u52a1\u5668\u4e0a&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7ec4\u5408\u8bca\u65adMTU\u95ee\u9898&#xff1a;<\/p>\n<p># \u67e5\u770b\u5f53\u524dwg0\u63a5\u53e3\u7684MTU\u8bbe\u7f6e<br \/>\nip link show wg0<\/p>\n<p># \u8fdb\u884cMTU\u6d4b\u8bd5&#xff08;\u4ece\u5927\u5230\u5c0f\u63a2\u6d4b&#xff09;<br \/>\nping -M do -s 1472 -c 4 10.10.10.1<\/p>\n<p>\u5173\u952e\u53c2\u6570\u89e3\u6790&#xff1a;<\/p>\n<ul>\n<li>-M do&#xff1a;\u7981\u6b62\u5206\u7247<\/li>\n<li>-s 1472&#xff1a;\u6d4b\u8bd5\u8f7d\u8377\u5927\u5c0f&#xff08;1472&#043;28\u5b57\u8282\u5305\u5934&#061;1500&#xff09;<\/li>\n<li>\u9010\u6b65\u51cf\u5c0f-s\u503c\u76f4\u5230\u80fd\u6b63\u5e38\u901a\u4fe1<\/li>\n<\/ul>\n<p>\u5f53\u51fa\u73b0&#034;Frag needed and DF set&#034;\u9519\u8bef\u65f6&#xff0c;\u8868\u793a\u9700\u8981\u964d\u4f4eMTU\u503c\u3002<\/p>\n<h4>2.3 \u52a8\u6001\u8c03\u6574MTU<\/h4>\n<p>\u5728\/etc\/wireguard\/wg0.conf\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u65b9\u5f0f\u8bbe\u7f6eMTU&#xff1a;<\/p>\n<p>[Interface]<br \/>\n# \u65b9\u6cd51&#xff1a;\u76f4\u63a5\u6307\u5b9aMTU\u503c<br \/>\nMTU &#061; 1400<\/p>\n<p># \u65b9\u6cd52&#xff1a;\u901a\u8fc7PostUp\u811a\u672c\u52a8\u6001\u8bbe\u7f6e<br \/>\nPostUp &#061; ip link set mtu %i 1400<\/p>\n<p>\u5b9e\u9645\u6848\u4f8b&#xff1a;\u5728\u67d0\u6df7\u5408\u4e91\u73af\u5883\u4e2d&#xff0c;\u6211\u4eec\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u4f18\u5316MTU&#xff1a;<\/p>\n<li>\u4f7f\u7528tracepath\u786e\u5b9a\u8def\u5f84\u6700\u5c0fMTU<\/li>\n<li>\u8bbe\u7f6ewg0\u63a5\u53e3MTU\u6bd4\u6700\u5c0f\u503c\u5c0f80\u5b57\u8282&#xff08;\u9884\u7559\u52a0\u5bc6\u5f00\u9500&#xff09;<\/li>\n<li>\u6700\u7ec8\u5c061500\u7684\u6807\u51c6\u503c\u8c03\u6574\u4e3a1380&#xff0c;\u4f20\u8f93\u6548\u7387\u63d0\u534740%<\/li>\n<h3>3. \u6301\u4e45\u5316Keepalive\u914d\u7f6e<\/h3>\n<h4>3.1 NAT\u7a7f\u900f\u7684\u6311\u6218<\/h4>\n<p>\u5728\u4f01\u4e1a\u7f51\u7edc\u6216\u5bb6\u5ead\u5bbd\u5e26\u73af\u5883\u4e2d&#xff0c;NAT\u8d85\u65f6\u662f\u5bfc\u81f4WireGuard\u8fde\u63a5\u4e2d\u65ad\u7684\u5e38\u89c1\u539f\u56e0\u3002\u4e0d\u540c\u7f51\u7edc\u8bbe\u5907\u7684NAT\u8d85\u65f6\u65f6\u95f4\u5dee\u5f02\u5f88\u5927&#xff1a;<\/p>\n<table>\n<tr>\u8bbe\u5907\u7c7b\u578b\u5178\u578bUDP\u8d85\u65f6\u65f6\u95f4<\/tr>\n<tbody>\n<tr>\n<td>\u5bb6\u7528\u8def\u7531\u5668<\/td>\n<td>30-180\u79d2<\/td>\n<\/tr>\n<tr>\n<td>\u4f01\u4e1a\u9632\u706b\u5899<\/td>\n<td>30-300\u79d2<\/td>\n<\/tr>\n<tr>\n<td>\u79fb\u52a8\u7f51\u7edc<\/td>\n<td>20-60\u79d2<\/td>\n<\/tr>\n<tr>\n<td>\u4e91\u8d1f\u8f7d\u5747\u8861\u5668<\/td>\n<td>30-600\u79d2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 Keepalive\u914d\u7f6e\u8be6\u89e3<\/h4>\n<p>\u5728\/etc\/wireguard\/wg0.conf\u4e2d&#xff0c;\u4e3a\u6bcf\u4e2a[Peer]\u6dfb\u52a0&#xff1a;<\/p>\n<p>[Peer]<br \/>\nPublicKey &#061; xxxxxxxxxxxxxxxx<br \/>\nEndpoint &#061; example.com:51820<br \/>\nAllowedIPs &#061; 10.10.10.0\/24<br \/>\nPersistentKeepalive &#061; 25<\/p>\n<p>\u53c2\u6570\u9009\u62e9\u5efa\u8bae&#xff1a;<\/p>\n<ul>\n<li>25\u79d2&#xff1a;\u9002\u5408\u5927\u591a\u6570\u4f01\u4e1a\u7f51\u7edc\u73af\u5883<\/li>\n<li>15\u79d2&#xff1a;\u9002\u7528\u4e8e\u4e25\u683c\u9632\u706b\u5899\u6216\u79fb\u52a8\u7f51\u7edc<\/li>\n<li>0&#xff08;\u9ed8\u8ba4&#xff09;&#xff1a;\u4ec5\u5728\u9700\u8981\u4e3b\u52a8\u53d1\u9001\u6570\u636e\u65f6\u5efa\u7acb\u8fde\u63a5<\/li>\n<\/ul>\n<p>\u6ce8\u610f&#xff1a;Keepalive\u4f1a\u589e\u52a0\u5c11\u91cf\u7f51\u7edc\u5f00\u9500&#xff08;\u7ea60.5KB\/\u5c0f\u65f6\/\u8fde\u63a5&#xff09;&#xff0c;\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u53ef\u80fd\u5f71\u54cd\u7535\u6c60\u7eed\u822a<\/p>\n<h4>3.3 \u9ad8\u7ea7Keepalive\u7b56\u7565<\/h4>\n<p>\u5bf9\u4e8e\u9700\u8981\u7cbe\u7ec6\u63a7\u5236\u7684\u573a\u666f&#xff0c;\u53ef\u4ee5\u7ed3\u5408iptables\u5b9e\u73b0\u667a\u80fdKeepalive&#xff1a;<\/p>\n<p>PostUp &#061; iptables -A OUTPUT -p udp &#8211;dport 51820 -m connbytes &#8211;connbytes 0:1024 &#8211;connbytes-dir both &#8211;connbytes-mode packets -j ACCEPT; \\\\<br \/>\n         iptables -A OUTPUT -p udp &#8211;dport 51820 -m recent &#8211;set &#8211;name wgkeepalive; \\\\<br \/>\n         iptables -A OUTPUT -p udp &#8211;dport 51820 -m recent &#8211;update &#8211;seconds 25 &#8211;hitcount 1 &#8211;name wgkeepalive -j ACCEPT; \\\\<br \/>\n         iptables -A OUTPUT -p udp &#8211;dport 51820 -j DROP<\/p>\n<p>\u8fd9\u5957\u89c4\u5219\u5b9e\u73b0\u4e86&#xff1a;<\/p>\n<li>\u5141\u8bb8\u5c0f\u6570\u636e\u5305\u81ea\u7531\u901a\u8fc7&#xff08;\u5047\u8bbe\u4e1a\u52a1\u6570\u636e&#xff09;<\/li>\n<li>\u5bf9\u7a7a\u95f2\u8fde\u63a5\u5f3a\u5236\u6267\u884c25\u79d2\u95f4\u9694\u7684Keepalive<\/li>\n<li>\u5b8c\u5168\u963b\u6b62\u4e0d\u7b26\u5408\u6761\u4ef6\u7684\u63a2\u6d4b\u5305<\/li>\n<h3>4. \u7efc\u5408\u8c03\u4f18\u5b9e\u6218<\/h3>\n<h4>4.1 \u6027\u80fd\u57fa\u51c6\u6d4b\u8bd5\u65b9\u6cd5<\/h4>\n<p>\u5efa\u7acb\u5b8c\u6574\u7684\u6027\u80fd\u8bc4\u4f30\u4f53\u7cfb\u662f\u8c03\u4f18\u7684\u57fa\u7840&#xff1a;<\/p>\n<p># \u5b89\u88c5\u6d4b\u8bd5\u5de5\u5177<br \/>\nsudo apt install iperf3 traceroute<\/p>\n<p># \u5e26\u5bbd\u6d4b\u8bd5&#xff08;\u670d\u52a1\u7aef&#xff09;<br \/>\niperf3 -s<\/p>\n<p># \u5e26\u5bbd\u6d4b\u8bd5&#xff08;\u5ba2\u6237\u7aef&#xff09;<br \/>\niperf3 -c 10.10.10.1 -t 60 -P 4<\/p>\n<p># \u5ef6\u8fdf\u6d4b\u8bd5<br \/>\nping -c 100 10.10.10.1 | awk &#039;\/^rtt\/ {print $4}&#039; | cut -d&#039;\/&#039; -f2<\/p>\n<h4>4.2 \u5178\u578b\u4f18\u5316\u6848\u4f8b<\/h4>\n<p>\u6848\u4f8b1&#xff1a;\u8de8\u56fd\u89c6\u9891\u4f1a\u8bae\u4f18\u5316<\/p>\n<ul>\n<li>\u521d\u59cb\u72b6\u6001&#xff1a;\u5e73\u5747\u5ef6\u8fdf280ms&#xff0c;\u6296\u52a8\u4e25\u91cd<\/li>\n<li>\u4f18\u5316\u6b65\u9aa4&#xff1a;\n<li>\u901a\u8fc7tracepath\u53d1\u73b0MTU\u74f6\u9888\u57281380<\/li>\n<li>\u8bbe\u7f6eMTU&#061;1300\u8865\u507f\u52a0\u5bc6\u5f00\u9500<\/li>\n<li>\u914d\u7f6ePersistentKeepalive&#061;20<\/li>\n<\/li>\n<li>\u7ed3\u679c&#xff1a;\u5ef6\u8fdf\u964d\u81f3210ms&#xff0c;\u6296\u52a8\u51cf\u5c1160%<\/li>\n<\/ul>\n<p>\u6848\u4f8b2&#xff1a;\u6df7\u5408\u4e91\u6587\u4ef6\u540c\u6b65<\/p>\n<ul>\n<li>\u521d\u59cb\u72b6\u6001&#xff1a;\u4f20\u8f93\u901f\u5ea6\u4ec530MB\/s&#xff08;\u5343\u5146\u94fe\u8def&#xff09;<\/li>\n<li>\u4f18\u5316\u6b65\u9aa4&#xff1a;\n<li>\u53d1\u73b0AWS VPC\u652f\u63019001\u5de8\u578b\u5e27<\/li>\n<li>\u8bbe\u7f6eMTU&#061;8900&#xff08;\u51cf\u53bb\u52a0\u5bc6\u5f00\u9500&#xff09;<\/li>\n<li>\u8c03\u6574wg-quick\u4f7f\u7528\u5927\u5185\u5b58\u7f13\u51b2\u533a<\/li>\n<\/li>\n<li>\u7ed3\u679c&#xff1a;\u901f\u5ea6\u63d0\u5347\u81f3110MB\/s<\/li>\n<\/ul>\n<h3>5. \u9ad8\u7ea7\u6280\u5de7\u4e0e\u6545\u969c\u6392\u9664<\/h3>\n<h4>5.1 \u52a8\u6001MTU\u8c03\u6574\u811a\u672c<\/h4>\n<p>\u521b\u5efa\/etc\/wireguard\/mtu-optimizer.sh&#xff1a;<\/p>\n<p>#!\/bin\/bash<br \/>\nINTERFACE&#061;$1<br \/>\nPEER_IP&#061;$2<\/p>\n<p># \u63a2\u6d4b\u8def\u5f84MTU<br \/>\nPMTU&#061;$(ping -M do -c 2 -s 1500 $PEER_IP 2&gt;&amp;1 | grep -oP &#039;PMTU is \\\\K\\\\d&#043;&#039;)<\/p>\n<p># \u8ba1\u7b97\u5efa\u8bae\u503c&#xff08;\u9884\u7559100\u5b57\u8282\u7ed9\u52a0\u5bc6\/\u5c01\u88c5&#xff09;<br \/>\nWG_MTU&#061;$((PMTU &#8211; 100))<\/p>\n<p># \u5e94\u7528\u8bbe\u7f6e<br \/>\nip link set mtu $WG_MTU dev $INTERFACE<br \/>\nlogger &#034;WireGuard MTU optimized to $WG_MTU for $INTERFACE&#034;<\/p>\n<p>exit 0<\/p>\n<p>\u5728wg0.conf\u4e2d\u8c03\u7528&#xff1a;<\/p>\n<p>PostUp &#061; \/etc\/wireguard\/mtu-optimizer.sh %i 10.10.10.2<\/p>\n<h4>5.2 \u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6848<\/h4>\n<p>\u95ee\u98981&#xff1a;\u8fde\u63a5\u968f\u673a\u65ad\u5f00<\/p>\n<ul>\n<li>\u68c0\u67e5NAT\u8d85\u65f6\u65f6\u95f4&#xff1a;sudo conntrack -L -p udp<\/li>\n<li>\u9002\u5f53\u51cf\u5c0fKeepalive\u95f4\u9694&#xff08;\u5982\u4ece25\u6539\u4e3a15&#xff09;<\/li>\n<\/ul>\n<p>\u95ee\u98982&#xff1a;\u901f\u5ea6\u6ce2\u52a8\u5927<\/p>\n<ul>\n<li>\u4f7f\u7528tc qdisc\u9650\u5236\u7a81\u53d1\u6d41\u91cf<\/li>\n<li>\u8c03\u6574wg-quick\u7684nofile\u9650\u5236<\/li>\n<\/ul>\n<p>\u95ee\u98983&#xff1a;\u9ad8CPU\u4f7f\u7528\u7387<\/p>\n<ul>\n<li>\u68c0\u67e5\/proc\/interrupts\u786e\u8ba4\u662f\u5426\u542f\u7528\u591a\u961f\u5217<\/li>\n<li>\u8bbe\u7f6ewg-quick\u4f7f\u7528\u7279\u5b9aCPU\u6838\u5fc3&#xff1a;<\/li>\n<\/ul>\n<p>PostUp &#061; taskset -cp 2-3 $(pgrep -f &#039;wg.*%i&#039;)<\/p>\n<h3>6. \u7cfb\u7edf\u7ea7\u4f18\u5316<\/h3>\n<h4>6.1 \u5185\u6838\u53c2\u6570\u8c03\u6574<\/h4>\n<p>\/etc\/sysctl.conf\u4e2d\u6dfb\u52a0&#xff1a;<\/p>\n<p># \u63d0\u9ad8UDP\u7f13\u51b2\u533a<br \/>\nnet.core.rmem_max &#061; 4194304<br \/>\nnet.core.wmem_max &#061; 4194304<\/p>\n<p># \u4f18\u5316\u52a0\u5bc6\u6027\u80fd<br \/>\nnet.ipv4.tcp_fastopen &#061; 3<br \/>\nnet.ipv4.udp_rmem_min &#061; 8192<br \/>\nnet.ipv4.udp_wmem_min &#061; 8192<\/p>\n<p>\u5e94\u7528\u8bbe\u7f6e&#xff1a;sudo sysctl -p<\/p>\n<h4>6.2 \u73b0\u4ee3CPU\u52a0\u901f<\/h4>\n<p>\u68c0\u67e5\u5e76\u542f\u7528\u786c\u4ef6\u52a0\u901f&#xff1a;<\/p>\n<p># \u68c0\u67e5AES-NI\u652f\u6301<br \/>\ngrep aes \/proc\/cpuinfo<\/p>\n<p># \u68c0\u67e5ChaCha20\u4f18\u5316<br \/>\nwg show | grep -i chacha<\/p>\n<p>\u5bf9\u4e8e\u652f\u6301AVX2\u7684CPU&#xff0c;\u53ef\u4ee5\u7f16\u8bd1\u4f18\u5316\u7248WireGuard&#xff1a;<\/p>\n<p>sudo apt build-dep wireguard<br \/>\ngit clone https:\/\/git.zx2c4.com\/wireguard-linux-compat<br \/>\nmake -C wireguard-linux-compat\/src -j$(nproc)<br \/>\nsudo make -C wireguard-linux-compat\/src install<\/p>\n<h3>7. \u76d1\u63a7\u4e0e\u7ef4\u62a4<\/h3>\n<h4>7.1 \u5b9e\u65f6\u72b6\u6001\u76d1\u63a7<\/h4>\n<p>\u7ec4\u5408\u4f7f\u7528\u8fd9\u4e9b\u547d\u4ee4\u83b7\u53d6\u5168\u9762\u6d1e\u5bdf&#xff1a;<\/p>\n<p># \u67e5\u770b\u8fde\u63a5\u72b6\u6001<br \/>\nwatch -n 1 &#039;wg show wg0 transfer&#039;<\/p>\n<p># \u76d1\u63a7\u63a5\u53e3\u7edf\u8ba1<br \/>\nip -s link show wg0<\/p>\n<p># \u8ddf\u8e2a\u6570\u636e\u5305\u8def\u5f84<br \/>\nsudo tcpdump -i wg0 -nn -vv<\/p>\n<h4>7.2 \u81ea\u52a8\u5316\u5065\u5eb7\u68c0\u67e5<\/h4>\n<p>\u521b\u5efa\/etc\/cron.hourly\/wireguard-check&#xff1a;<\/p>\n<p>#!\/bin\/bash<br \/>\nif ! ping -c 3 -I wg0 10.10.10.1 &amp;&gt;\/dev\/null; then<br \/>\n    systemctl restart wg-quick&#064;wg0<br \/>\n    echo &#034;$(date): WireGuard restarted&#034; &gt;&gt; \/var\/log\/wg-monitor.log<br \/>\nfi<\/p>\n<p>\u8bb0\u5f97\u6dfb\u52a0\u6267\u884c\u6743\u9650&#xff1a;chmod &#043;x \/etc\/cron.hourly\/wireguard-check<\/p>\n<h3>8. \u5b89\u5168\u52a0\u56fa\u5efa\u8bae<\/h3>\n<p>\u5728\u8ffd\u6c42\u6027\u80fd\u7684\u540c\u65f6&#xff0c;\u5b89\u5168\u540c\u6837\u91cd\u8981&#xff1a;<\/p>\n<li>\n<p>\u5bc6\u94a5\u8f6e\u6362&#xff1a;\u6bcf\u6708\u81ea\u52a8\u66f4\u65b0\u5bc6\u94a5<\/p>\n<p>wg genkey | tee \/etc\/wireguard\/new_privatekey | wg pubkey &gt; \/etc\/wireguard\/new_publickey<\/p>\n<\/li>\n<li>\n<p>\u7aef\u53e3\u968f\u673a\u5316&#xff1a;\u907f\u514d\u4f7f\u7528\u9ed8\u8ba451820\u7aef\u53e3<\/p>\n<\/li>\n<li>\n<p>\u9632\u706b\u5899\u89c4\u5219&#xff1a;\u9650\u5236\u6e90IP\u8bbf\u95eeWireGuard\u7aef\u53e3<\/p>\n<p>ufw allow from 203.0.113.5 to any port 51820 proto udp<\/p>\n<\/li>\n<li>\n<p>\u8fde\u63a5\u901f\u7387\u9650\u5236&#xff1a;\u9632\u6b62\u66b4\u529b\u7834\u89e3<\/p>\n<p>iptables -A INPUT -p udp &#8211;dport 51820 -m hashlimit &#8211;hashlimit-name wg &#8211;hashlimit-mode srcip &#8211;hashlimit-above 2\/minute -j DROP<\/p>\n<\/li>\n","protected":false},"excerpt":{"rendered":"<p>WireGuard\u6027\u80fd\u8c03\u4f18\u5b9e\u6218&#xff1a;MTU\u4e0e\u6301\u4e45\u5316Keepalive\u7684\u6df1\u5ea6\u89e3\u6790<br \/>\n\u5728\u5f53\u4eca\u9ad8\u901f\u53d1\u5c55\u7684\u7f51\u7edc\u73af\u5883\u4e2d&#xff0c;WireGuard\u4ee5\u5176\u7b80\u6d01\u9ad8\u6548\u7684\u8bbe\u8ba1\u7406\u5ff5\u8d62\u5f97\u4e86\u5e7f\u6cdb\u9752\u7750\u3002\u7136\u800c&#xff0c;\u8bb8\u591a\u7528\u6237\u5728\u57fa\u7840\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u5e38\u4f1a\u9047\u5230\u8fde\u63a5\u4e0d\u7a33\u5b9a\u6216\u4f20\u8f93\u901f\u5ea6\u4e0d\u7406\u60f3\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u4e24\u4e2a\u5173\u952e\u6027\u80fd\u4f18\u5316\u53c2\u6570\u2014\u2014MTU\u8bbe\u7f6e\u4e0e\u6301\u4e45\u5316Keepalive\u673a\u5236&#xff0c;\u5e2e\u52a9\u60a8\u6253\u9020\u66f4\u7a33\u5b9a\u9ad8\u6548\u7684WireGuard\u7f51\u7edc\u73af\u5883\u3002<br \/>\n1. \u7406\u89e3WireGuard\u6027\u80fd\u74f6\u9888<br \/>\nWir<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[8604,103,1554,1555],"topic":[],"class_list":["post-78139","post","type-post","status-publish","format-standard","hentry","category-server","tag-8604","tag-ubuntu","tag-vpn","tag-wireguard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/78139.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"WireGuard\u6027\u80fd\u8c03\u4f18\u5b9e\u6218&#xff1a;MTU\u4e0e\u6301\u4e45\u5316Keepalive\u7684\u6df1\u5ea6\u89e3\u6790 \u5728\u5f53\u4eca\u9ad8\u901f\u53d1\u5c55\u7684\u7f51\u7edc\u73af\u5883\u4e2d&#xff0c;WireGuard\u4ee5\u5176\u7b80\u6d01\u9ad8\u6548\u7684\u8bbe\u8ba1\u7406\u5ff5\u8d62\u5f97\u4e86\u5e7f\u6cdb\u9752\u7750\u3002\u7136\u800c&#xff0c;\u8bb8\u591a\u7528\u6237\u5728\u57fa\u7840\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u5e38\u4f1a\u9047\u5230\u8fde\u63a5\u4e0d\u7a33\u5b9a\u6216\u4f20\u8f93\u901f\u5ea6\u4e0d\u7406\u60f3\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u4e24\u4e2a\u5173\u952e\u6027\u80fd\u4f18\u5316\u53c2\u6570\u2014\u2014MTU\u8bbe\u7f6e\u4e0e\u6301\u4e45\u5316Keepalive\u673a\u5236&#xff0c;\u5e2e\u52a9\u60a8\u6253\u9020\u66f4\u7a33\u5b9a\u9ad8\u6548\u7684WireGuard\u7f51\u7edc\u73af\u5883\u3002 1. \u7406\u89e3WireGuard\u6027\u80fd\u74f6\u9888 Wir\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/78139.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-26T01:25:11+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78139.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/78139.html\",\"name\":\"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-26T01:25:11+00:00\",\"dateModified\":\"2026-02-26T01:25:11+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/78139.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/78139.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/78139.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/78139.html","og_locale":"zh_CN","og_type":"article","og_title":"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"WireGuard\u6027\u80fd\u8c03\u4f18\u5b9e\u6218&#xff1a;MTU\u4e0e\u6301\u4e45\u5316Keepalive\u7684\u6df1\u5ea6\u89e3\u6790 \u5728\u5f53\u4eca\u9ad8\u901f\u53d1\u5c55\u7684\u7f51\u7edc\u73af\u5883\u4e2d&#xff0c;WireGuard\u4ee5\u5176\u7b80\u6d01\u9ad8\u6548\u7684\u8bbe\u8ba1\u7406\u5ff5\u8d62\u5f97\u4e86\u5e7f\u6cdb\u9752\u7750\u3002\u7136\u800c&#xff0c;\u8bb8\u591a\u7528\u6237\u5728\u57fa\u7840\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u5e38\u4f1a\u9047\u5230\u8fde\u63a5\u4e0d\u7a33\u5b9a\u6216\u4f20\u8f93\u901f\u5ea6\u4e0d\u7406\u60f3\u7684\u95ee\u9898\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u4e24\u4e2a\u5173\u952e\u6027\u80fd\u4f18\u5316\u53c2\u6570\u2014\u2014MTU\u8bbe\u7f6e\u4e0e\u6301\u4e45\u5316Keepalive\u673a\u5236&#xff0c;\u5e2e\u52a9\u60a8\u6253\u9020\u66f4\u7a33\u5b9a\u9ad8\u6548\u7684WireGuard\u7f51\u7edc\u73af\u5883\u3002 1. \u7406\u89e3WireGuard\u6027\u80fd\u74f6\u9888 Wir","og_url":"https:\/\/www.wsisp.com\/helps\/78139.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-26T01:25:11+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/78139.html","url":"https:\/\/www.wsisp.com\/helps\/78139.html","name":"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-26T01:25:11+00:00","dateModified":"2026-02-26T01:25:11+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/78139.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/78139.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/78139.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"WireGuard\u6027\u80fd\u4f18\u5316\uff1a\u5728Ubuntu\u670d\u52a1\u5668\u4e0a\u914d\u7f6eMTU\u548c\u6301\u4e45\u5316Keepalive"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=78139"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/78139\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=78139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=78139"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=78139"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=78139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}