DKe*_*ler 7 systemd hostapd systemd-networkd
我正在设置的路由器上有两个以太网端口和一个无线端口。我正在使用 systemd-networkd。我首先重命名端口,然后创建一个桥接,然后桥接以太网端口之一和无线板,以在具有单个 IP 和 DHCP/DNSMASQ 的组合 LAN 端口上创建。另一个以太网是 wan 端口。在这里您可以看到 networkctl 输出。lan 是桥。您会看到 wlan 与 lan2 具有相同的状态(这是 NIC 并且工作正常)。所以网桥和所有路由都很好。
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 wan ether routable configured
3 lan2 ether carrier configuring
4 wlan wlan carrier configuring
5 lan ether routable configured
Run Code Online (Sandbox Code Playgroud)
所以......我很接近。它只是使用 systemd-networkd 让 hostapd 在正确的时间启动。AP 出现,但无线接口似乎未绑定到网桥。客户端可以输入 WPA 密码并被接受,但随后就无法连接。日志不能帮助我识别问题,但我很确定无线端口没有修复到网桥上。这可以解释为什么 AP 功能看起来很好,但实际上并没有与给出的 IP 地址建立连接。
有经验的人可以提供一些建议吗?正如您所看到的,我编写的 hostapd.service 尝试延迟启动 hostapd 直到网络完成,特别是直到创建桥为止。也许这与 hostapd 延迟网络有关,但网络在 hostapd 启动之前将 wlan 添加到 LAN 桥...有点像 catch22。
主机配置文件
interface=wlan
# the interface used by the AP
hw_mode=g
# g simply means 2.4GHz band
channel=10
# the channel to use
#ieee80211d=1
# limit the frequencies used to those allowed in the country
#country_code=US
# the country code
ieee80211n=1
# 802.11n support
#wmm_enabled=1
# QoS support
#ignore_broadcast_ssid=0
ssid=645-gateway
# the name of the AP
auth_algs=1
# 1=wpa, 2=wep, 3=both
wpa=2
# WPA2 only
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
wpa_passphrase=elf645Keb1920
Run Code Online (Sandbox Code Playgroud)
主机服务
[Unit]
Description=Hostapd IEEE 802.11 AP, IEEE 802.1X/WPA/WPA2/EAP/RADIUS Authenticator
Wants=network-online.target
After=systemd-networkd.service
After=sys-subsystem-net-devices-wlan.device
After=sys-subsystem-net-devices-lan.device
BindsTo=sys-subsystem-net-devices-lan.device
[Service]
Type=forking
PIDFile=/run/hostapd.pid
ExecStart=/usr/sbin/hostapd /etc/hostapd/hostapd.conf -P /run/hostapd.pid -B
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
30-br-wlan-lan.network
[Match]
Name=wlan
[Network]
Bridge=lan
Run Code Online (Sandbox Code Playgroud)
小智 5
你很接近,我也处于同样的情况。经过多年的摆弄,我终于找到了正确的配置。
对于 中的 systemd-networkd 配置/etc/systemd/network/
,您需要以下文件:
.netdev
用于您的桥接设备.network
用于您的桥接设备.network
用于您的以太网设备(LAN 和 WAN).network
用于您的 WiFi 设备.network
如果您在同一设备上运行多个 SSID,则还可以选择更多其他 wifi SSID。这是我的桥接设备配置,这里没什么特别的。然而,我花了几年时间才发现我丢失了该文件,因为即使报告为失败.netdev
,网络也显然运行正常。networkctl
br0
cat /etc/systemd/network/10-bridge.netdev
[NetDev]
Name=br0
Kind=bridge
Run Code Online (Sandbox Code Playgroud)
cat /etc/systemd/network/20-bridge.network
[Match]
Name=br0
[Network]
Description=...
Address=...
Address=...
Run Code Online (Sandbox Code Playgroud)
显然,每个参与的设备都br0
必须声明Bridge=br0
。
cat /etc/systemd/network/21-enp2s0_bridged.network
[Match]
Name=enp2s0
[Link]
RequiredForOnline=no
[Network]
Description=Add enp2s0 to the bridge
Bridge=br0
Run Code Online (Sandbox Code Playgroud)
cat /etc/systemd/network/21-wlp5s0_bridged.network
[Match]
Name=wlp5s0
[Link]
RequiredForOnline=no
[Network]
Description=Add wlp5s0 to the bridge
Bridge=br0
Run Code Online (Sandbox Code Playgroud)
为了在正确的时间启动 hostapd,它需要具有以下依赖项hostapd.service
:
[Unit]
部分
After=network.target
BindsTo=sys-subsystem-net-devices-%i.device
Run Code Online (Sandbox Code Playgroud)
替换%i
为您的 wifi 设备名称[Install]
部分
WantedBy=multi-user.target
WantedBy=sys-subsystem-net-devices-%i.device
Run Code Online (Sandbox Code Playgroud)
再次替换%i
为您的 wifi 设备名称。不需要其他依赖项。特别是,Wants=network-online.target
不应在这种情况下使用,因为您希望 hostapd在网络联机之前启动。请参阅和的定义network.target
network-online.target
。
Debian 系统上有一个很好的示例单元文件/lib/systemd/system/hostapd@.service
,上面的配置是从中复制的。如果您在同一 hostapd 实例上只配置了一个 SSID 或多个 SSID,则不需要单元模板,但您确实需要设备模板BindsTo
(Debian 上附带的非模板/lib/systemd/system/hostapd.service
缺少它)。另请注意,sys-subsystem-net-devices-%i.device
当没有多个 SSID 时,仅在“主”wifi 接口上需要依赖项。
# networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 enp1s0 ether routable configured
3 enp2s0 ether enslaved configured
4 enp3s0 ether no-carrier configuring
5 enp4s0 ether off unmanaged
6 br0 bridge routable configured
7 wg0 wireguard routable configured
8 sit0 sit off unmanaged
9 he-ipv6 sit routable configured
10 wlp5s0 wlan enslaved configured
11 wlan-iot wlan routable configured
12 wlan-guest wlan routable configured
12 links listed.
Run Code Online (Sandbox Code Playgroud)
和一个快乐的系统管理员!:)
仍然可能会networkctl
报告 wlp5s0 失败并systemd-networkd
记录:
wlp5s0:无法加入 netdev:设备不允许奴役到网桥。不支持的操作 wlp5s0:失败
但这似乎不会导致网络故障,并且 a再次systemctl restart systemd-networkd.service
变绿networkctl
。我怀疑这是与我使用 hostapd 配置的方式进行交互bridge=br0
。也许应该删除该行。
归档时间: |
|
查看次数: |
6613 次 |
最近记录: |