Linux

由於多個錯誤,無法啟動 Hostapd

  • September 16, 2020

嘗試啟動 Hostapd 時出現多個錯誤我將發佈在嘗試啟動它並查看狀態後得到的錯誤輸出:

  root@l0calh0st:~# service hostapd status
● hostapd.service - Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
  Loaded: loaded (/lib/systemd/system/hostapd.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Sun 2018-01-07 16:42:38 CET; 4s ago
 Process: 1682 ExecStart=/usr/sbin/hostapd -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF} (code=exited, sta

Jan 07 16:42:38 l0calh0st systemd[1]: Starting Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticato
Jan 07 16:42:38 l0calh0st hostapd[1682]: Configuration file:
Jan 07 16:42:38 l0calh0st hostapd[1682]: Could not open configuration file '' for reading.
Jan 07 16:42:38 l0calh0st hostapd[1682]: Failed to set up interface with
Jan 07 16:42:38 l0calh0st hostapd[1682]: Failed to initialize interface
Jan 07 16:42:38 l0calh0st systemd[1]: hostapd.service: Control process exited, code=exited status=1
Jan 07 16:42:38 l0calh0st systemd[1]: hostapd.service: Failed with result 'exit-code'.
Jan 07 16:42:38 l0calh0st systemd[1]: Failed to start Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authe

我不知道為什麼他沒有找到他似乎在搜尋的配置文件’‘又什麼都沒有……!我沒有編輯任何東西……!在這裡,如果我嘗試正常啟動它:

root@l0calh0st:~# service  hostapd start
Job for hostapd.service failed because the control process exited with error code.
See "systemctl status hostapd.service" and "journalctl -xe" for details.

如果使用命令“journalct1 -xe”我得到:

root@l0calh0st:~# journalctl -xe
-- Unit systemd-tmpfiles-clean.service has finished starting up.
-- 
-- The start-up result is RESULT.
Jan 07 16:57:44 l0calh0st systemd[1]: Starting Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator...
-- Subject: Unit hostapd.service has begun start-up
-- Defined-By: systemd
-- Support: https://www.debian.org/support
-- 
-- Unit hostapd.service has begun starting up.
Jan 07 16:57:44 l0calh0st hostapd[1865]: Configuration file:
Jan 07 16:57:44 l0calh0st hostapd[1865]: Could not open configuration file '' for reading.
Jan 07 16:57:44 l0calh0st hostapd[1865]: Failed to set up interface with
Jan 07 16:57:44 l0calh0st hostapd[1865]: Failed to initialize interface
Jan 07 16:57:44 l0calh0st systemd[1]: hostapd.service: Control process exited, code=exited status=1
Jan 07 16:57:44 l0calh0st systemd[1]: hostapd.service: Failed with result 'exit-code'.
Jan 07 16:57:44 l0calh0st systemd[1]: Failed to start Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator.
-- Subject: Unit hostapd.service has failed
-- Defined-By: systemd 
-- Unit hostapd.service has failed.
-- 
-- The result is RESULT.
lines 1521-1543/1543 (END)

編輯:好的,我找到了文件“hostapd.service”,但我沒有看到任何註釋掉的內容。(#?):

[Unit]
Description=Advanced IEEE 802.11 AP and IEEE 802.1X/WPA/WPA2/EAP Authenticator
After=network.target

[Service]
Type=forking
PIDFile=/run/hostapd.pid
EnvironmentFile=/etc/default/hostapd
ExecStart=/usr/sbin/hostapd -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF}

[Install]
WantedBy=multi-user.target

這是 /etc/default/hostapd 文件:

# Defaults for hostapd initscript
#
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
#
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
#DAEMON_CONF=""

# Additional daemon options to be appended to hostapd command:-
#   -d   show more debug messages (-dd for even more)
#   -K   include key data in debug messages
#   -t   include timestamps in some debug messages
#
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.
#
#DAEMON_OPTS=""

您的系統正在使用systemd. 在某些發行版中,我注意到使用遺留service包裝器可以隱藏一些使用 systemd-nativesystemctl命令可見的錯誤消息。但看起來這裡有足夠的資訊。

/lib/systemd/system/hostapd.service文件中,確定用於啟動的實際命令的行hostapd顯然是這樣的:

ExecStart=/usr/sbin/hostapd -P /run/hostapd.pid -B $DAEMON_OPTS ${DAEMON_CONF}

systemd由於它包含預設設置之外的環境變數(請參閱man systemd.exec詳細資訊),因此該hostapd.service文件可能應該有一個選項,例如Environment=,EnvironmentFile=PassEnvironment=. 大概是這樣的:

EnvironmentFile=/etc/default/hostapd.conf

如果存在這樣的文件,它可能有一些註釋掉的預設值,您需要編輯以匹配您的系統配置,然後取消註釋,然後才能開始hostapd.

通常這些文件是由你的發行版維護者準備的,並且有描述你需要做什麼的有用的註釋。如果沒有,/usr/share/doc/hostapd-*/您應該首先閱讀目錄中的一些特定於發行版的資訊。

引用自:https://unix.stackexchange.com/questions/415405