(https://bbs.archlinux.org/viewtopic.php?id=178625)
上一篇文章讲到如何用命令行连接wifi,大家可以去看看。
本文参考 https://bbs.archlinux.org/viewtopic.php?id=178625
wpa_supplicant
# config wpa_supplicant
#/etc/wpa_supplicant/wpa_supplicant-wlp5s0.conf
# enable wpa_supplicant
systemctl enable wpa_supplicant@wlp5s0
config systemd-network
# config systemd-network
# /etc/systemd/network/00-wireless-dhcp.network
[Match]
Name=wlp5s0
[Network]
DHCP=yes
# enable systemd-networkd.service
systemctl enable systemd-networkd.service
wpa_supplicant
dhcpcd
/etc/wpa_supplicant/wpa_supplicant-网卡名.conf
/etc/systemd/network/00-wireless-dhcp.network
wpa_supplicant
ip link
# 1: lo
# 2: enp4s0
# 3: wlp5s0
注意我的网卡名是 wlp5s0
,下文中的wlp5s0
都需替换成你的
wpa_supplicant.conf
文件将生成的wpa_supplicant.conf
放到/etc/wpa_supplicant/
文件夹下,并重命名,格式为:
wpa_supplicant-网卡名.conf
例如我的就是:
wpa_supplicant-wlp5s0.conf
man wpa_supplicant.conf
知道原始配置文件在
/usr/share/doc/wpa_supplicant/wpa_supplicant.conf
wpa_passphrase
生成配置文件# wpa_passphrase MyNetwork SuperSecretPassphrase > /etc/wpa_supplicant/wpa_supplicant-wlp5s0.conf
priority
越大优先级越高
country=CN
update_config=1
network={
ssid="SSID"
psk="Passwd"
key_mgmt=WPA-PSK
priority=9
id_str="identify which wifi is"
}
network={
ssid="SSID"
psk="Passwd"
key_mgmt=WPA-PSK
priority=8
id_str="identify which wifi is"
}
systemctl
启动wpa_supplicant
服务systemctl enable wpa_supplicant@wlp5s0
注意arch bbs 原回答多写了.conf
,后面也有跟帖指出了这个问题。
systemd-networkd
创建/etc/systemd/network/00-wireless-dhcp.network
,archbbs中说这个名字随意。
[Match]
Name=wlp5s0
[Network]
DHCP=yes
systemctl
设置启动服务systemd-networkd.service
systemctl enable systemd-networkd.service
在1.3的systemctl enable wpa_supplicant@wlp5s0
中,我们看到:
Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /usr/lib/systemd/system/[email protected].
查看/usr/lib/systemd/system/[email protected]
,其中有一行:
ExecStart=/usr/bin/wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant-%I.conf -i%I
这里的%I
就是systemctl enable wpa_supplicant@wlp5s0
中的wlp5s0
,它通过%I
来传递设备名,所以我们也就知道之前为什么要把配置文件这样命名了
/etc/wpa_supplicant/wpa_supplicant-网卡名.conf