{"id":201557,"date":"2020-09-30T08:09:13","date_gmt":"2020-09-30T00:09:13","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=201557"},"modified":"2020-09-23T14:09:57","modified_gmt":"2020-09-23T06:09:57","slug":"linux-wifi","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-wifi.html","title":{"rendered":"\u5982\u4f55\u5728 Linux \u7ec8\u7aef\u4e2d\u8fde\u63a5\u4f7f\u7528 WiFi\uff1f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u4f60\u5c06\u5b66\u4e60\u5982\u4f55\u5728 Ubuntu \u4e2d\u4ece\u7ec8\u7aef\u8fde\u63a5\u5230\u65e0\u7ebf\u7f51\u7edc\u3002\u5982\u679c\u4f60\u5728\u4f7f\u7528 Ubuntu \u670d\u52a1\u5668\u65f6\uff0c\u65e0\u6cd5\u8bbf\u95ee\u5e38\u89c4\u7684\u684c\u9762\u73af\u5883\uff0c\u8fd9\u5c06\u5bf9\u4f60\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u6211\u7684\u5bb6\u7528\u7535\u8111\u4e3b\u8981\u4f7f\u7528\u684c\u9762 Linux\u3002\u6211\u4e5f\u6709\u591a\u53f0 Linux \u670d\u52a1\u5668\u7528\u4e8e\u6258\u7ba1\u7f51\u7ad9\u4ee5\u53ca\u5f00\u6e90\u8f6f\u4ef6\uff0c\u5982 Nextcloud\u3001Discourse\u3001Ghost\u3001Rocket Chat \u7b49\u3002
\n\"\"<\/p>\n

\u6211\u53ef\u4ee5\u4f7f\u7528 linode \u5728\u4e91\u7aef\u51e0\u5206\u949f\u5185\u5feb\u901f\u90e8\u7f72 Linux \u670d\u52a1\u5668\u3002\u4f46\u6700\u8fd1\uff0c\u6211\u5728\u6211\u7684\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5\u4e86 Ubuntu \u670d\u52a1\u5668\u3002\u8fd9\u662f\u6211\u7b2c\u4e00\u6b21\u5728\u7269\u7406\u8bbe\u5907\u4e0a\u5b89\u88c5\u670d\u52a1\u5668\uff0c\u6211\u4e0d\u5f97\u4e0d\u505a\u4e00\u4e9b\u989d\u5916\u7684\u4e8b\u60c5\u6765\u901a\u8fc7\u547d\u4ee4\u884c\u5c06 Ubuntu \u670d\u52a1\u5668\u8fde\u63a5\u5230 WiFi\u3002<\/p>\n

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u6211\u5c06\u5c55\u793a\u5728 Ubuntu Linux \u4e2d\u4f7f\u7528\u7ec8\u7aef\u8fde\u63a5\u5230 WiFi \u7684\u6b65\u9aa4\u3002\u4f60\u5e94\u8be5\uff1a<\/p>\n

\u4e0d\u8981\u5bb3\u6015\u4f7f\u7528\u7ec8\u7aef\u7f16\u8f91\u6587\u4ef6\u3002
\n\u77e5\u9053 wifi \u63a5\u5165\u70b9\u540d\u79f0 \uff08SSID\uff09 \u548c\u5bc6\u7801\u3002<\/p>\n

\u5728 Ubuntu \u4e2d\u4ece\u7ec8\u7aef\u8fde\u63a5\u5230 WiFi<\/strong><\/div>\n

\u5f53\u4f60\u4f7f\u7528 Ubuntu \u684c\u9762\u65f6\uff0c\u8fde\u63a5\u5230 WiFi \u662f\u5f88\u5bb9\u6613\u7684\uff0c\u56e0\u4e3a\u4f60\u6709\u56fe\u5f62\u7528\u6237\u754c\u9762\uff0c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u505a\u5230\u8fd9\u4e00\u70b9\u3002\u4f46\u5f53\u4f60\u4f7f\u7528 Ubuntu \u670d\u52a1\u5668\u65f6\u5c31\u4e0d\u4e00\u6837\u4e86\uff0c\u56e0\u4e3a\u4f60\u53ea\u80fd\u4f7f\u7528\u547d\u4ee4\u884c\u3002<\/p>\n

Ubuntu \u4f7f\u7528 Netplan \u5de5\u5177\u6765\u8f7b\u677e\u914d\u7f6e\u7f51\u7edc\u3002\u5728 Netplan \u4e2d\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u7f51\u7edc\u63a5\u53e3\u63cf\u8ff0\u7684 YAML \u6587\u4ef6\uff0c\u7136\u540e\u5728 netplan \u547d\u4ee4\u884c\u5de5\u5177\u7684\u5e2e\u52a9\u4e0b\uff0c\u751f\u6210\u6240\u6709\u9700\u8981\u7684\u914d\u7f6e\u3002<\/p>\n

\u8ba9\u6211\u4eec\u770b\u770b\u5982\u4f55\u4f7f\u7528 Netplan \u4ece\u7ec8\u7aef\u8fde\u63a5\u5230\u65e0\u7ebf\u7f51\u7edc\u3002<\/p>\n

\u6b65\u9aa4 1\uff1a\u786e\u5b9a\u4f60\u7684\u65e0\u7ebf\u7f51\u7edc\u63a5\u53e3\u540d\u79f0<\/strong><\/span><\/div>\n

\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8bc6\u522b\u4f60\u7684\u7f51\u7edc\u63a5\u53e3\u540d\u79f0\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 ip \u547d\u4ee4\u3001\u8fc7\u65f6\u7684 ipconfig \u547d\u4ee4\u6216\u67e5\u770b\u8fd9\u4e2a\u6587\u4ef6\uff1a<\/p>\n

\r\nls \/sys\/class\/net \r\n<\/pre>\n

\u8fd9\u5e94\u8be5\u4f1a\u5c55\u793a\u6240\u6709\u53ef\u7528\u7684\u7f51\u7edc\u63a5\u53e3\uff08\u4ee5\u592a\u7f51\u3001WiFi \u548c\u73af\u56de\uff09\u3002\u65e0\u7ebf\u7f51\u7edc\u63a5\u53e3\u540d\u79f0\u4ee5 w \u5f00\u5934\uff0c\u901a\u5e38\u547d\u540d\u7c7b\u4f3c wlanX\u3001wlpxyz\u3002<\/p>\n

\r\n[email protected]:~$ ls \/sys\/class\/net \r\neth0 lo wlan0 \r\n<\/pre>\n

\u8bb0\u4e0b\u8fd9\u4e2a\u63a5\u53e3\u540d\u3002\u4f60\u5c06\u5728\u4e0b\u4e00\u6b65\u4f7f\u7528\u5b83\u3002<\/p>\n

\u6b65\u9aa4 2\uff1a\u7f16\u8f91 Netplan \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 wifi \u63a5\u53e3\u8be6\u7ec6\u4fe1\u606f<\/strong><\/span><\/div>\n

Netplan \u914d\u7f6e\u6587\u4ef6\u5728 \/etc\/netplan \u76ee\u5f55\u4e0b\u3002\u5982\u679c\u4f60\u67e5\u770b\u8fd9\u4e2a\u76ee\u5f55\u7684\u5185\u5bb9\uff0c\u4f60\u5e94\u8be5\u770b\u5230\u7c7b\u4f3c 01-network-manager-all.yml \u6216 50-cloud-init.yaml \u7b49\u6587\u4ef6\u3002<\/p>\n

\u5982\u679c\u662f Ubuntu \u670d\u52a1\u5668\uff0c\u4f60\u5e94\u8be5\u6709 50-cloud-init.yaml \u6587\u4ef6\u3002\u5982\u679c\u662f\u684c\u9762\u8ba1\u7b97\u673a\uff0c\u5e94\u8be5\u662f 01-network-manager-all.yml \u6587\u4ef6\u3002<\/p>\n

Linux \u684c\u9762\u8ba1\u7b97\u673a\u7684 Network Manager \u5141\u8bb8\u4f60\u9009\u62e9\u4e00\u4e2a\u65e0\u7ebf\u7f51\u7edc\u3002\u4f60\u53ef\u4ee5\u5728\u5b83\u7684\u914d\u7f6e\u4e2d\u786c\u7f16\u7801\u5199\u5165 WiFi \u63a5\u5165\u70b9\u3002\u8fd9\u53ef\u4ee5\u5728\u81ea\u52a8\u6389\u7ebf\u7684\u60c5\u51b5\u4e0b\uff08\u6bd4\u5982\u6302\u8d77\uff09\u65f6\u5e2e\u52a9\u5230\u4f60\u3002<\/p>\n

\u4e0d\u7ba1\u662f\u54ea\u4e2a\u6587\u4ef6\uff0c\u90fd\u53ef\u4ee5\u6253\u5f00\u7f16\u8f91\u3002\u6211\u5e0c\u671b\u4f60\u5bf9 Nano \u7f16\u8f91\u5668\u6709\u4e00\u70b9\u719f\u6089\uff0c\u56e0\u4e3a Ubuntu \u9884\u88c5\u4e86\u5b83\u3002<\/p>\n

\r\nsudo nano \/etc\/netplan\/50-cloud-init.yaml \r\n<\/pre>\n

YAML \u6587\u4ef6\u5bf9\u7a7a\u683c\u3001\u7f29\u8fdb\u548c\u5bf9\u9f50\u65b9\u5f0f\u975e\u5e38\u654f\u611f\u3002\u4e0d\u8981\u4f7f\u7528\u5236\u8868\u7b26\uff0c\u5728\u770b\u5230\u7f29\u8fdb\u7684\u5730\u65b9\u4f7f\u7528 4 \u4e2a\u7a7a\u683c\uff08\u6216 2 \u4e2a\uff0c\u4ee5 YAML \u6587\u4ef6\u4e2d\u5df2\u7ecf\u4f7f\u7528\u7684\u4e3a\u51c6\uff09\u4ee3\u66ff\u3002<\/p>\n

\u57fa\u672c\u4e0a\uff0c\u4f60\u9700\u8981\u6dfb\u52a0\u4ee5\u4e0b\u51e0\u884c\uff0c\u5f15\u53f7\u4e2d\u662f\u63a5\u5165\u70b9\u540d\u79f0\uff08SSID\uff09 \u548c\u5bc6\u7801\uff08\u901a\u5e38\uff09\uff1a<\/p>\n

\r\nwifis: \r\n    wlan0: \r\n        dhcp4: true \r\n        optional: true \r\n        access-points: \r\n            \"SSID_name\": \r\n                password: \"WiFi_password\" \r\n<\/pre>\n

\u518d\u8bf4\u4e00\u6b21\uff0c\u4fdd\u6301\u6211\u6240\u5c55\u793a\u7684\u5bf9\u9f50\u65b9\u5f0f\uff0c\u5426\u5219 YAML \u6587\u4ef6\u4e0d\u80fd\u88ab\u89e3\u6790\uff0c\u5b83\u4f1a\u629b\u51fa\u4e00\u4e2a\u9519\u8bef\u3002<\/p>\n

\u4f60\u7684\u5b8c\u6574\u914d\u7f6e\u6587\u4ef6\u53ef\u80fd\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n

\r\n# This file is generated from information provided by the datasource. Changes \r\n# to it will not persist across an instance reboot. To disable cloud-init's \r\n# network configuration capabilities, write a file \r\n# \/etc\/cloud\/cloud.cfg.d\/99-disable-network-config.cfg with the following: \r\n# network: {config: disabled} \r\nnetwork: \r\n    ethernets: \r\n        eth0: \r\n            dhcp4: true \r\n            optional: true \r\n    version: 2 \r\n    wifis: \r\n        wlan0: \r\n            dhcp4: true \r\n            optional: true \r\n            access-points: \r\n                \"SSID_name\": \r\n                    password: \"WiFi_password\" \r\n<\/pre>\n

\u6211\u89c9\u5f97\u5f88\u5947\u602a\uff0c\u5c3d\u7ba1\u6709\u6d88\u606f\u8bf4\u66f4\u6539\u4e0d\u4f1a\u5728\u5b9e\u4f8b\u91cd\u542f\u540e\u4fdd\u7559\uff0c\u4f46\u5b83\u4ecd\u7136\u53ef\u4ee5\u5de5\u4f5c\u3002<\/p>\n

\u4e0d\u7ba1\u600e\u6837\uff0c\u7528\u8fd9\u4e2a\u547d\u4ee4\u751f\u6210\u914d\u7f6e\uff1a<\/p>\n

\r\nsudo netplan generate \r\n<\/pre>\n

\u5982\u679c\u4f60\u5e78\u8fd0\u7684\u8bdd\uff0c\u4f60\u5e94\u8be5\u8fde\u4e0a\u7f51\u7edc\u3002\u5c1d\u8bd5 ping \u4e00\u4e2a\u7f51\u7ad9\u6216\u8fd0\u884c apt \u66f4\u65b0\u547d\u4ee4\u3002<\/p>\n

\u7136\u800c\uff0c\u4e8b\u60c5\u53ef\u80fd\u4e0d\u4f1a\u90a3\u4e48\u987a\u5229\uff0c\u4f60\u53ef\u80fd\u4f1a\u770b\u5230\u4e00\u4e9b\u9519\u8bef\u3002\u5982\u679c\u662f\u8fd9\u79cd\u60c5\u51b5\uff0c\u8bf7\u5c1d\u8bd5\u4e00\u4e9b\u989d\u5916\u7684\u6b65\u9aa4\u3002<\/p>\n

\u53ef\u80fd\u7684\u6545\u969c\u6392\u9664<\/strong><\/div>\n

\u5f53\u4f60\u4f7f\u7528 netplan apply \u547d\u4ee4\u65f6\uff0c\u4f60\u6709\u53ef\u80fd\u5728\u8f93\u51fa\u4e2d\u770b\u5230\u7c7b\u4f3c\u8fd9\u6837\u7684\u9519\u8bef\u3002<\/p>\n

\r\nFailed to start netplan-wpa-wlan0.service: Unit netplan-wpa-wlan0.service not found. \r\nTraceback (most recent call last): \r\n  File \"\/usr\/sbin\/netplan\", line 23, in  \r\n    netplan.main() \r\n  File \"\/usr\/share\/netplan\/netplan\/cli\/core.py\", line 50, in main \r\n    self.run_command() \r\n  File \"\/usr\/share\/netplan\/netplan\/cli\/utils.py\", line 179, in run_command \r\n    self.func() \r\n  File \"\/usr\/share\/netplan\/netplan\/cli\/commands\/apply.py\", line 46, in run \r\n    self.run_command() \r\n  File \"\/usr\/share\/netplan\/netplan\/cli\/utils.py\", line 179, in run_command \r\n    self.func() \r\n  File \"\/usr\/share\/netplan\/netplan\/cli\/commands\/apply.py\", line 173, in command_apply \r\n    utils.systemctl_networkd('start', sync=sync, extra_services=netplan_wpa) \r\n  File \"\/usr\/share\/netplan\/netplan\/cli\/utils.py\", line 86, in systemctl_networkd \r\n    subprocess.check_call(command) \r\n  File \"\/usr\/lib\/python3.8\/subprocess.py\", line 364, in check_call \r\n    raise CalledProcessError(retcode, cmd) \r\nsubprocess.CalledProcessError: Command '['systemctl', 'start', '--no-block', 'systemd-networkd.service', 'netplan-wpa-wlan0.service']' returned non-zero exit status 5. \r\n<\/module><\/pre>\n

\u53ef\u80fd\u662f wpa_supplicant \u670d\u52a1\u6ca1\u6709\u8fd0\u884c\u3002\u8fd0\u884c\u8fd9\u4e2a\u547d\u4ee4\uff1a<\/p>\n

\r\nsudo systemctl start wpa_supplicant \r\n<\/pre>\n

\u518d\u6b21\u8fd0\u884c netplan apply\u3002\u5982\u679c\u5b83\u80fd\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u90a3\u5c31\u592a\u597d\u4e86\u3002\u5426\u5219\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u5173\u95ed Ubuntu \u7cfb\u7edf\uff1a<\/p>\n

\r\nshutdown now \r\n<\/pre>\n

\u91cd\u65b0\u542f\u52a8 Ubuntu \u7cfb\u7edf\uff0c\u767b\u5f55\u5e76\u518d\u6b21\u751f\u6210\u548c\u8fd0\u884c netplan apply\uff1a<\/p>\n

\r\nsudo netplan generate \r\nsudo netplan apply \r\n<\/pre>\n

\u73b0\u5728\u53ef\u80fd\u4f1a\u663e\u793a\u8b66\u544a\uff08\u800c\u4e0d\u662f\u9519\u8bef\uff09\u3002\u8fd9\u662f\u8b66\u544a\u800c\u4e0d\u662f\u9519\u8bef\u3002\u6211\u68c0\u67e5\u4e86\u6b63\u5728\u8fd0\u884c\u7684 systemd \u670d\u52a1\uff0c\u53d1\u73b0 netplan-wpa-wlan0.service \u5df2\u7ecf\u5728\u8fd0\u884c\u4e86\u3002\u53ef\u80fd\u662f\u56e0\u4e3a\u5b83\u5df2\u7ecf\u5728\u8fd0\u884c\u4e86\uff0c\u800c\u4e14 netplan apply \u66f4\u65b0\u4e86\u914d\u7f6e\u6587\u4ef6\uff08\u5373\u4f7f\u6ca1\u6709\u4efb\u4f55\u6539\u53d8\uff09\uff0c\u6240\u4ee5\u663e\u793a\u4e86\u8b66\u544a\u3002<\/p>\n

\r\nWarning: The unit file, source configuration file or drop-ins of netplan-wpa-wlan0.service changed on disk. Run 'systemctl daemon-reload' to reload units.\r\n<\/pre>\n

\u8fd9\u5e76\u4e0d\u91cd\u8981\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c apt update \u6765\u68c0\u67e5\u7f51\u7edc\u662f\u5426\u5df2\u7ecf\u6b63\u5e38\u5de5\u4f5c\u3002<\/p>\n

\u6211\u5e0c\u671b\u4f60\u80fd\u591f\u5728\u672c\u6559\u7a0b\u7684\u5e2e\u52a9\u4e0b\uff0c\u5728 Ubuntu \u4e2d\u4f7f\u7528\u547d\u4ee4\u884c\u8fde\u63a5\u5230 WiFi\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u4f60\u5c06\u5b66\u4e60\u5982\u4f55\u5728 Ubuntu \u4e2d\u4ece\u7ec8\u7aef\u8fde\u63a5\u5230\u65e0\u7ebf\u7f51\u7edc\u3002\u5982\u679c\u4f60\u5728\u4f7f\u7528 Ubuntu \u670d\u52a1\u5668\u65f6\uff0c\u65e0\u6cd5\u8bbf\u95ee\u5e38\u89c4\u7684\u684c\u9762\u73af\u5883\uff0c\u8fd9\u5c06\u5bf9\u4f60\u975e\u5e38\u6709\u5e2e\u52a9\u3002<\/p>\n","protected":false},"author":370,"featured_media":124395,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-201557","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201557","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/370"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=201557"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201557\/revisions"}],"predecessor-version":[{"id":201561,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/201557\/revisions\/201561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/124395"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=201557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=201557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=201557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}