设置:rasbian raspberry pi 4.4.14-v7+ 以及用于网络相关内容的 systemd。
使用内部 Broadcom wifi
接入点:另一个带有 Hostapd 1:2.3-1+deb8u3 和 4.4.14-v7+ 的 RPi3
我将“客户端”称为尝试连接到 Hostapd 接入点 (WPA2) 的 RPI
Hostapd 在 wifi 接口上使用 isc-dhcp 服务器,工作正常(发送租约、更新租约、DHCPACK 等..)
要求:
我无法通过 /etc/network/interfaces 接受后备模式,也无法通过 fe ifplugd 接受类似的设置,这些设置依赖于该文件。
目前我们使用 dhclient 而不是默认的 dhcpcd。
其他网络管理器以及任何图形工具都是不可能的。
问题:
如果短时间内无法访问接入点(重新启动、断电等),则客户端需要完全重新启动才能使 wifi 再次工作
此时我还没有通过 wpa_supplicant 连接到 AP。 (hostapd_cli all_sta不显示我的客户端Wifi MAC)
iwconfig wlan0 wlan0 IEEE 802.11bgn ESSID:off/any
模式:托管接入点:未关联 Tx-Power=31 dBm
重试短限制:7 RTS thr:off 片段 thr:off 加密密钥:off 电源管理:off
解决此问题的“旧”版本是通过 ifplugd 脚本(ifup/ifdown 操作)和/或在 /etc/network/interfaces 中设置 wpa-roam 并使用兼容层“networking.service - LSB:提升网络接口”。 ”
另一种选择是使用 cronjob 来检测失败的连接并重新启动 $SOMETHING。
遗憾的是我无法弄清楚那$SOMETHING 是什么。
由于我只想使用 systemd-network 方式,因此我没有加载“网络”单元。
在我看来,wpa_supplicant确实尝试再次扫描AP,但不知何故拒绝匹配的AP SSID。
这是设置。
加载的服务:
systemctl -t 服务
UNIT LOAD ACTIVE SUB DESCRIPTION
bluetooth.service loaded active running Bluetooth service
console-setup.service loaded active exited LSB: Set console font and keymap
cron.service loaded active running Regular background program processing daemon
dbus.service loaded active running D-Bus System Message Bus
dphys-swapfile.service loaded active exited LSB: Autogenerate and use a swap file
fake-hwclock.service loaded active exited Restore / save the current clock
[email protected] loaded active running Getty on tty1
hciuart.service loaded active running Configure Bluetooth Modems connected by UART
hdparm.service loaded active exited LSB: Tune IDE hard disks
kbd.service loaded active exited LSB: Prepare console
keyboard-setup.service loaded active exited LSB: Set preliminary keymap
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the current kernel
[email protected] loaded active exited Wireless network connectivity (wlan0)
ntp.service loaded active running LSB: Start NTP daemon
openvpn.service loaded active exited OpenVPN service
postfix.service loaded active running LSB: Postfix Mail Transport Agent
raspi-config.service loaded active exited LSB: Switch to ondemand cpu governor (unless shift key is pressed)
rc-local.service loaded active running /etc/rc.local Compatibility
rsyslog.service loaded active running System Logging Service
ssh.service loaded active running OpenBSD Secure Shell server
systemd-fsck-root.service loaded active exited File System Check on Root Device
[email protected] loaded active exited File System Check on /dev/mmcblk0p1
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-modules-load.service loaded active exited Load Kernel Modules
systemd-networkd.service loaded active running Network Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
[email protected] loaded active exited Load/Save RF Kill Switch Status of rfkill0
[email protected] loaded active exited Load/Save RF Kill Switch Status of rfkill1
systemd-setup-dgram-qlen.service loaded active exited Increase datagram queue length
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
systemd-user-sessions.service loaded active exited Permit User Sessions
triggerhappy.service loaded active running LSB: triggerhappy hotkey daemon
udev-finish.service loaded active exited Copy rules generated while the root was ro
[email protected] loaded active running User Manager for UID 0
猫 /etc/systemd/network/00-wireless.network
#General configuration wlan0
[Match]
Name=wlan0
[Network]
DHCP=ipv4
我确实在 /var/log/wpa_supplicant.log 中设置了一些额外的调试信息,因此 ExecStart 比平常要长一些。
猫 /etc/systemd/系统/[电子邮件受保护]
[Unit]
Description=Wireless network connectivity (%i)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/ip l set %i up
ExecStart=/sbin/wpa_supplicant -t -dd -f /var/log/wpa_supplicant.log -dd -B -i %i -c /etc/wpa_supplicant/wpa_supplicant.conf
ExecStart=/sbin/dhclient %i
ExecStop=/sbin/ip l set %i down
[Install]
WantedBy=multi-user.target
猫 /etc/wpa_supplicant/wpa_supplicant.conf
country=DE
ctrl_interface=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
ssid="testap"
psk="testconn"
}
一些日志:
启动客户端:
系统控制状态[电子邮件受保护]
● [email protected] - Wireless network connectivity (wlan0)
Loaded: loaded (/etc/systemd/system/[email protected]; enabled)
Active: active (exited) since Fri 2016-08-05 12:21:17 CEST; 3min 32s ago
Process: 431 ExecStart=/sbin/dhclient %i (code=exited, status=0/SUCCESS)
Process: 425 ExecStart=/sbin/wpa_supplicant -t -dd -f /var/log/wpa_supplicant.log -dd -B -i %i -c /etc/wpa_supplicant/wpa_supplicant.conf (code=exited, status=0/SUCCESS)
Process: 387 ExecStart=/sbin/ip l set %i up (code=exited, status=0/SUCCESS)
Main PID: 431 (code=exited, status=0/SUCCESS)
启动客户端(一切正常,连接稳定并且在之前的测试中可以工作数小时/数天)
日志ctl-u[电子邮件受保护]-b
-- Logs begin at Fri 2016-08-05 12:21:05 CEST, end at Fri 2016-08-05 12:22:53 CEST. --
Aug 05 12:21:08 testclient systemd[1]: Starting Wireless network connectivity (wlan0)...
Aug 05 12:21:09 testclient dhclient[431]: DHCPREQUEST on wlan0 to 255.255.255.255 port 67
Aug 05 12:21:13 testclient dhclient[431]: DHCPREQUEST on wlan0 to 255.255.255.255 port 67
Aug 05 12:21:17 testclient dhclient[431]: DHCPREQUEST on wlan0 to 255.255.255.255 port 67
Aug 05 12:21:17 testclient dhclient[431]: DHCPACK from 192.168.100.1
Aug 05 12:21:17 testclient dhclient[431]: bound to 192.168.100.11 -- renewal in 60 seconds.
Aug 05 12:21:17 testclient systemd[1]: Started Wireless network connectivity (wlan0).
Aug 05 12:22:17 testclient dhclient[549]: DHCPREQUEST on wlan0 to 192.168.100.1 port 67
Aug 05 12:22:17 testclient dhclient[549]: DHCPACK from 192.168.100.1
Aug 05 12:22:17 testclient dhclient[549]: bound to 192.168.100.11 -- renewal in 53 seconds.
重启AP:
Aug 5 12:26:55 testclient systemd-networkd[422]: wlan0 : lost carrier
Aug 5 12:26:55 testclient dhclient: DHCPREQUEST on wlan0 to 192.168.100.1 port 67
Aug 5 12:27:00 testclient dhclient: DHCPREQUEST on wlan0 to 192.168.100.1 port 67
Aug 5 12:27:12 testclient dhclient: DHCPREQUEST on wlan0 to 192.168.100.1 port 67
Aug 5 12:27:32 testclient dhclient: DHCPREQUEST on wlan0 to 192.168.100.1 port 67
这让我相信我在 systemd-network 单元中缺少“丢失的运营商”选项来重新启动无线服务。
如果我在 SE 和 google 上的搜索技巧确实失败了,我错过了哪些部分或者我可以在哪里获得更多信息。谢谢。
注意:根据 raspberrypi.se 帮助,我不应该使用 rpi se 网站,而应该使用 UX,我确实这样做了。如果我误解了“与 Linux/Unix 问题直接相关的问题。请使用 Unix & Linux Exchange”部分,请移步。
我尝试了多个参考资料,但其中大多数要么已经过时,要么对我的情况没有帮助。
https://raspberrypi.stackexchange.com/questions/4120/how-to-automatically-reconnect-wifi https://wiki.archlinux.org/index.php/WPA_supplicant
http://weworkweplay.com/play/automatically-connect-a-raspberry-pi-to-a-wifi-network/