﻿{"id":2527,"date":"2023-06-05T10:12:35","date_gmt":"2023-06-05T02:12:35","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=2527"},"modified":"2023-07-05T11:21:42","modified_gmt":"2023-07-05T03:21:42","slug":"%e5%90%af%e7%94%a8win10%e7%9a%84linux%e5%ad%90%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/win\/2527","title":{"rendered":"\u542f\u7528Win10\u7684Linux\u5b50\u7cfb\u7edf"},"content":{"rendered":"<p>\u5efa\u8bae\u76f4\u63a5\u4f7f\u7528WSL2\uff1a\n<a href=\"https:\/\/learn.microsoft.com\/zh-cn\/windows\/wsl\/install-manual#step-4---download-the-linux-kernel-update-package\"><a href=\"https:\/\/learn.microsoft.com\/zh-cn\/windows\/wsl\/install-manual#step-4---download-the-linux-kernel-update-package\">https:\/\/learn.microsoft.com\/zh-cn\/windows\/wsl\/install-manual#step-4&#8212;download-the-linux-kernel-update-package<\/a><\/a><\/p>\n<p>dism.exe \/online \/enable-feature \/featurename:Microsoft-Windows-Subsystem-Linux \/all \/norestart\ndism.exe \/online \/enable-feature \/featurename:VirtualMachinePlatform \/all \/norestart\nwsl &#8211;update &#8211;web-download\nwsl &#8211;set-default-version 2<\/p>\n<p>wsl &#8211;import-in-place ubuntu ubuntu.tar &#8211;user admin<\/p>\n<p>\/etc\/wsl.conf\n<span class=\"token punctuation\">[<\/span>boot<span class=\"token punctuation\">]<\/span>\nsystemd<span class=\"token operator\">=<\/span>\n<span class=\"token boolean\">true<\/span>\n[user]\ndefault=username\n[boot]\ncommand=service docker start\n<span class=\"token punctuation\">[<\/span>network<span class=\"token punctuation\">]<\/span>\nhostname <span class=\"token operator\">=<\/span> DemoHost\ngenerateHosts <span class=\"token operator\">=<\/span> <span class=\"token boolean\">false<\/span>\ngenerateResolvConf <span class=\"token operator\">=<\/span> <span class=\"token boolean\">false<\/span><\/p>\n<p>WSL2 \u670d\u52a1\u8bbf\u95ee\n\u7531\u4e8e WSL2 \u4e0e\u4e3b\u673a\u4e4b\u95f4\u662f\u901a\u8fc7\u79c1\u6709\u7f51\u7edc\u8bbf\u95ee\uff0c\u90a3\u4e48\u5916\u7f51\u9700\u8981\u8bbf\u95ee WSL2 \u4e2d\u7684\u670d\u52a1\u65f6\uff0c\u9700\u8981\u5728\u4e3b\u673a\u8bbe\u7f6e\u7aef\u53e3\u8f6c\u53d1\u3002 \u4f8b\u5982\u9700\u8981\u8bbf\u95ee WSL2 \u4e2d\u7684 5000 \u7aef\u53e3\u65f6\uff0c\u5219\u9700\u5728\u4e3b\u673a\u8bbe\u7f6e\uff1a<\/p>\n<p>netsh interface portproxy add v4tov4 listenport=8899 listenaddress=* connectport=8080 connectaddress=127.0.0.1 protocol=tcp<\/p>\n<p>listenport\uff1a\u8868\u793a\u5728\u4e3b\u673a\u4e0a\u76d1\u542c\u7684\u7aef\u53e3\uff0c\u8fd9\u91cc\u8bbe\u7f6e\u4e3a5000\uff0c\u4e5f\u53ef\u8bbe\u7f6e\u4e3a\u5176\u4ed6\u7aef\u53e3\uff1b\nlistenaddress: \u8868\u793a\u53ef\u8bbf\u95ee\u76d1\u542c\u7aef\u53e3\u7684 IP \u5730\u5740\u8303\u56f4\uff0c * \u8868\u793a\u4efb\u610f\u5730\u5740\uff1b\nconnectport\uff1a\u8868\u793a\u8f6c\u53d1\u81f3 WSL2 \u7684\u7aef\u53e3\uff1b\nconnectaddress\uff1a\u8868\u793a WSL2 \u7684\u5730\u5740\uff1b\nCAUTION\n\u9700\u8981\u6ce8\u610f\u7684\u662f\uff1a<\/p>\n<p>WSL2 \u4e2d\u7684\u670d\u52a1\u9700\u76d1\u542c 0.0.0.0 \u5730\u5740\u6bb5\uff0c\u800c\u4e0d\u80fd\u662f localhost\uff1b\n\u4e3b\u673a\u9632\u706b\u5899\u9700\u8bbe\u7f6e\u89c4\u5219\uff0c\u5141\u8bb8\u76d1\u542c\u7aef\u53e3\uff0c\u5426\u5219\u4e3b\u673a\u5916\u7f51\u65e0\u6cd5\u8bbf\u95ee\u3002\nTIP\n\u53e6\u5916\uff0c\u6bcf\u6b21\u91cd\u542f\u7535\u8111\u540e\uff0cWSL2 \u7684 IP \u5730\u5740\u4f1a\u6539\u53d8\uff0c\u7b28\u529e\u6cd5\u5c31\u662f\u91cd\u65b0\u518d\u8bbe\u7f6e\u4e00\u6b21\uff0c\u65e0\u9700\u5220\u9664\u539f\u6709\u89c4\u5219\uff0c\u76f4\u63a5\u53ef\u8986\u76d6\uff1b\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u957f\u671f\u4e0d\u91cd\u542f\u7535\u8111\uff1b\u5176\u5b83\u7f51\u4e0a\u4e5f\u6709\u5f88\u591a\u529e\u6cd5\uff0c\u6bd4\u5982\u52a8\u6001\u8bbe\u7f6e\u57df\u540d\u8bbf\u95ee WSL2 \u7b49\uff0c\u53ef\u81ea\u884c\u53c2\u8003\u3002<\/p>\n<p>\u67e5\u770b\u7aef\u53e3\u8f6c\u53d1\u547d\u4ee4\uff1a<\/p>\n<p>netsh interface portproxy show all<\/p>\n<p>\u5220\u9664\u7aef\u53e3\u8f6c\u53d1\u547d\u4ee4\uff1a<\/p>\n<p>netsh interface portproxy delete v4tov4 listenport=8899 listenaddress=*<\/p>","protected":false},"excerpt":{"rendered":"<p>\u5efa\u8bae\u76f4\u63a5\u4f7f\u7528WSL2\uff1a <a href=\"https:\/\/learn.microsoft.com\/zh-cn\/windows\/wsl\/install-manual#step-4&#8212;download-the-l&#46;&#46;&#038;#46\">https:\/\/learn.microsoft.com\/zh-cn\/windows\/wsl\/install-manual#step-4&#8212;download-the-l&#46;&#46;&#038;#46<\/a>;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,3],"tags":[518,538],"class_list":["post-2527","post","type-post","status-publish","format-standard","hentry","category-linux","category-win","tag-win10","tag-wsl"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2527","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=2527"}],"version-history":[{"count":10,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2527\/revisions"}],"predecessor-version":[{"id":2580,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/2527\/revisions\/2580"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=2527"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=2527"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=2527"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}