{"id":2170,"date":"2020-09-29T00:43:45","date_gmt":"2020-09-28T16:43:45","guid":{"rendered":"https:\/\/sforest.in\/?p=2170"},"modified":"2020-09-29T00:43:45","modified_gmt":"2020-09-28T16:43:45","slug":"wsl2-automatically-proxy-configuration","status":"publish","type":"post","link":"https:\/\/sforest.in\/ja\/wsl2-automatically-proxy-configuration\/","title":{"rendered":"WSL2\u7684Proxy\u8bbe\u7f6e"},"content":{"rendered":"<p>WSL2\u8bbe\u7f6eProxy\u7684\u65f6\u5019\u6bd4\u8f83\u9ebb\u70e6\u7684\u4e00\u70b9\u662fHost\u7684IP\u4f1a\u4e00\u76f4\u53d8\u3002<\/p>\n\n\n\n<p>\u4f46\u662f\u6ca1\u6709\u4ee3\u7406\u7684\u8bdd\u5f88\u591a\u4e8b\u60c5\u90fd\u4e0d\u65b9\u4fbf\uff0c\u88c5\u8f6f\u4ef6\u5305\u3001\u4e0b\u6570\u636e\u3001\u6345VPS\u7b49\u7b49\u2026\u2026<\/p>\n\n\n\n<p>\u6700\u540e\u8fd8\u662f\u6574\u4e86\u4e00\u4e2a\u811a\u672c\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#!\/bin\/sh\nhostip=$(cat \/etc\/resolv.conf | grep nameserver | awk '{ print $2 }')\nwslip=$(hostname -I | awk '{print $1}')\nport=7890\n\nset_proxy(){\n    export http_proxy=\"http:\/\/${hostip}:${port}\"\n    export https_proxy=\"http:\/\/${hostip}:${port}\"\n    export all_proxy=\"http:\/\/${hostip}:${port}\"\n}\n\nunset_proxy(){\n    unset http_proxy\n    unset https_proxy\n    unset all_proxy\n}\n\ntest_setting(){\n    echo \"Host IP:\" ${hostip}\n    echo \"WSL IP:\" ${wslip}\n    echo \"Current Proxy:\" ${all_proxy}\n}\n\nif [ \"$1\" = \"set\" ]\nthen\n    set_proxy\n\nelif [ \"$1\" = \"unset\" ]\nthen\n    unset_proxy\n\nelif [ \"$1\" = \"test\" ]\nthen\n    test_setting\nelse\n    echo \"Usage: source proxy [set|unset|test]\"\nfi<\/pre>\n\n\n\n<p>\u4e22\u8fdb\/usr\/bin\/proxy\uff0cchmod 755\uff0c\u518d\u5f80.zshrc\u672b\u5c3e\u52a0\u4e0asource proxy set\uff0c\u6536\u5de5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u4e3a\u4ec0\u4e48\u8981\u7528source\uff1f &#8211; \u5982\u679c\u76f4\u63a5\u6267\u884c\u7684\u8bdd\uff0c\u662f\u65b0\u8d77\u7684shell\uff0c\u4e0d\u4f1a\u4fee\u6539\u5f53\u524d\u7ec8\u7aef\u7684\u73af\u5883\u53d8\u91cf\u3002<\/li><li>\u4e3a\u4ec0\u4e48\u8981set\u4e09\u4e2a\u73af\u5883\u53d8\u91cf\uff1f- VSCode (Remote WSL)\u9700\u8981\u66f4\u65b0\u5b83\u7684Extension\uff0c\u6ca1\u6709\u4ee3\u7406\u641e\u5f97\u5b83\u6bcf\u6b21\u90fd\u81ea\u52a8\u628aC++ Extension\u7ed9\u5220\u4e86\uff08\u7136\u540e\u53c8timeout\u4e0b\u4e0d\u56de\u6765\u65b0\u7684\uff09\u3002\u7136\u540e\u5b83\u7684\u4ee3\u7406\u9ed8\u8ba4\u662f\u7ee7\u627fhttp_proxy \/ https_proxy\u7684\uff0c\u53c8\u4e0d\u8ba9\u6211\u586b\u522b\u7684\u4e1c\u897f\uff0c\u60f3\u4e86\u60f3\u5e72\u8106\u5168set\u4e86\u5427\u2026\u2026 <\/li><\/ul>\n\n\n\n<p>\u867d\u7136\u8bf4\u611f\u89c9\u8fd9\u4e2asolution\u4e5f\u633augly\u7684\uff0c\u4f46\u662f\u6211\u4e00\u4e0b\u5b50\u4e5f\u60f3\u4e0d\u5230\u4ec0\u4e48\u597d\u7684\u89e3\u6cd5\uff08\u8eba<\/p>\n\n\n\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>WSL2\u8bbe\u7f6eProxy\u7684\u65f6\u5019\u6bd4\u8f83\u9ebb\u70e6\u7684\u4e00\u70b9\u662fHost\u7684IP\u4f1a\u4e00\u76f4\u53d8\u3002 \u4f46\u662f\u6ca1\u6709\u4ee3\u7406\u7684\u8bdd\u5f88\u591a\u4e8b\u60c5\u90fd\u4e0d\u65b9\u4fbf\uff0c\u88c5\u8f6f\u4ef6\u5305\u3001\u4e0b\u6570\u636e\u3001\u6345VPS\u7b49\u7b49\u2026\u2026 \u6700\u540e\u8fd8\u662f\u6574\u4e86\u4e00\u4e2a\u811a\u672c\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[36,51],"class_list":["post-2170","post","type-post","status-publish","format-standard","hentry","category-coding","tag-proxy","tag-wsl"],"_links":{"self":[{"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/posts\/2170","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/comments?post=2170"}],"version-history":[{"count":0,"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/posts\/2170\/revisions"}],"wp:attachment":[{"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/media?parent=2170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/categories?post=2170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sforest.in\/ja\/wp-json\/wp\/v2\/tags?post=2170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}