配置为 AP 的 WiFi 接口在系统重启后关闭

配置为 AP 的 WiFi 接口在系统重启后关闭

我正在尝试使用 hostapd 在 AP 模式下设置我的 WiFi 接口。但是,系统重新启动后,启动会挂起大约 2 分钟:

A start job is running for Wait for Network to be Configured

看来 WiFi 接口没有启动,这就是 systemd-networkd-wait-online.service 挂起的原因。如果我在 systemd-networkd-wait-online.service 中将 WiFi 接口设置为忽略,则不会,但这并不能解决一般问题。

系统启动后,执行ip addr命令后我会看到以下输出:

3: wlxc04a0010118a: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether c0:4a:00:10:11:8a brd ff:ff:ff:ff:ff:ff

正如我所料,接口已关闭。

sudo ip link set wlxc04a0010118a up不改变接口状态。为了将其启动并解决我的问题,我必须执行systemctl restart hostapd.service

然后ip addr命令返回:

3: wlxc04a0010118a: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether c0:4a:00:10:11:8a brd ff:ff:ff:ff:ff:ff
    inet 172.24.1.1/24 brd 172.24.1.255 scope global wlxc04a0010118a
       valid_lft forever preferred_lft forever

我想解决这个问题,并在系统启动后配置 WiFi AP,而不需要此手动步骤,因为其他服务依赖于此接口,最终也必须在接口启动时手动启动。我尝试了很多方法但仍然无法解决这个问题。我将不胜感激你的帮助。

我的/etc/hostapd/hostapd.conf

interface=wlxc04a0010118a
# Use the nl80211 driver with the brcmfmac driver
driver=nl80211
ssid=Wifinetwork
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
#ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_passphrase=Wifipassword
rsn_pairwise=CCMP

接口配置:/lib/systemd/network/80-wifi-ap.network

[Match]
Name=wlxc04a0010118a

[Network]
Address=172.24.1.1/24
DHCPServer=no
IPForward=ipv4
IPMasquerade=no

/etc/dnsmasq.conf

interface=wlxc04a0010118a      # Use interface wlan0  
listen-address=172.24.1.1  # Explicitly specify the address to listen on  
bind-dynamic      # Bind to the interface to make sure we aren't sending things elsewhere  
server=8.8.8.8       # Forward DNS requests to Google DNS  
domain-needed        # Don't forward short names  
bogus-priv           # Never forward addresses in the non-routed address spaces.  
dhcp-option=6,172.24.1.1,192.168.1.1
domain=domain1
dhcp-range=172.24.1.50,172.24.1.150,12h 

systemctl status hostapd.servicehostapd 重新启动之前的结果:

● hostapd.service - Hostapd IEEE 802.11 Access Point
     Loaded: loaded (/etc/systemd/system/hostapd.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-11-10 16:42:02 UTC; 4min 48s ago
    Process: 780 ExecStartPre=/sbin/ip link set wlxc04a0010118a up (code=exited, status=0/SUCCESS)
    Process: 794 ExecStart=/usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/hostapd.pid (code=exited, sta>
   Main PID: 966 (hostapd)
      Tasks: 1 (limit: 4596)
     Memory: 2.4M
     CGroup: /system.slice/hostapd.service
             └─966 /usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/hostapd.pid

Nov 10 16:41:58 domain1 systemd[1]: Starting Hostapd IEEE 802.11 Access Point...
Nov 10 16:41:58 domain1 hostapd[794]: Configuration file: /etc/hostapd/hostapd.conf
Nov 10 16:42:00 domain1 hostapd[794]: Using interface wlxc04a0010118a with hwaddr c0:4a:00:10:11:8a and ssid ">
Nov 10 16:42:02 domain1 hostapd[794]: wlxc04a0010118a: interface state UNINITIALIZED->ENABLED
Nov 10 16:42:02 domain1 hostapd[794]: wlxc04a0010118a: AP-ENABLED
Nov 10 16:42:02 domain1 systemd[1]: hostapd.service: Can't open PID file /run/hostapd.pid (yet?) after start: >
Nov 10 16:42:02 domain1 systemd[1]: Started Hostapd IEEE 802.11 Access Point.

systemctl status hostapd.servicehostapd 重启后的结果:

 hostapd.service - Hostapd IEEE 802.11 Access Point
     Loaded: loaded (/etc/systemd/system/hostapd.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-11-10 17:32:36 UTC; 6min ago
    Process: 1499 ExecStartPre=/sbin/ip link set wlxc04a0010118a up (code=exited, status=0/SUCCESS)
    Process: 1514 ExecStart=/usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/hostapd.pid (code=exited, s>
   Main PID: 1522 (hostapd)
      Tasks: 1 (limit: 4596)
     Memory: 816.0K
     CGroup: /system.slice/hostapd.service
             └─1522 /usr/sbin/hostapd -B /etc/hostapd/hostapd.conf -P /var/run/hostapd.pid

Nov 10 17:32:30 domain1 systemd[1]: Stopping Hostapd IEEE 802.11 Access Point...
Nov 10 17:32:30 domain1 systemd[1]: hostapd.service: Succeeded.
Nov 10 17:32:30 domain1 systemd[1]: Stopped Hostapd IEEE 802.11 Access Point.
Nov 10 17:32:30 domain1 systemd[1]: Starting Hostapd IEEE 802.11 Access Point...
Nov 10 17:32:30 domain1 hostapd[1514]: Configuration file: /etc/hostapd/hostapd.conf
Nov 10 17:32:34 domain1 hostapd[1514]: Using interface wlxc04a0010118a with hwaddr c0:4a:00:10:11:8a and ssid>
Nov 10 17:32:36 domain1 hostapd[1514]: wlxc04a0010118a: interface state UNINITIALIZED->ENABLED
Nov 10 17:32:36 domain1 hostapd[1514]: wlxc04a0010118a: AP-ENABLED
Nov 10 17:32:36 domain1 systemd[1]: hostapd.service: Can't open PID file /run/hostapd.pid (yet?) after start:>
Nov 10 17:32:36 domain1 systemd[1]: Started Hostapd IEEE 802.11 Access Point.

答案1

因为我已经安装了XFCE桌面环境NetworkManager也已经安装了。看来它以某种方式破坏了我的配置,并且我的 WiFi 接口保持关闭状态。为了避免这种情况,我必须制作这个文件: /etc/NetworkManager/conf.d/unmanaged.conf包含以下内容:

unmanaged-devices=interface-name:wlxc04a0010118a

现在NetworkManager不管理这个接口。但是,系统在启动过程中仍然挂起:

A start job is running for Wait for Network to be Configured

为了避免这种情况,我必须添加:

[Link]
RequiredForOnline=no

归档/lib/systemd/network/80-wifi-ap.network。现在系统启动时不会出现此暂停,并且 wifi AP 按预期工作。我仍然不确定为什么我必须添加这个RequiredForOnline=no。看来 wifi 接口在启动过程的这个阶段无法设置,但可能很快就会设置,因为最终接口运行良好。

相关内容