Network configuration (简体中文)/Wireless (简体中文)

From ArchWiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Tango-preferences-desktop-locale.png本文或本节需要翻译。要贡献翻译,请访问简体中文翻译团队Tango-preferences-desktop-locale.png

翻译状态:本文是 Network configuration/Wireless翻译。上次翻译日期:2016-10-01。如果英文版本有所更改,则您可以帮助同步翻译。

配置无线网络一般分两步:第一步是识别硬件、安装正确的驱动程序并进行配置,安装盘中已经包含驱动,但是通常需要额外安装;第二步是选择一种管理无线连接的方式。这篇文章涵盖了这两方面,并提供了无线管理工具的链接地址。

设备驱动

默认的 Arch Linux 内核是模块化的,,硬件的设备驱动作为内核模块保存在硬盘上。启动时 udev 会根据硬件加载不同的驱动模块,这就创建了需要的网络接口。

有些无线芯片需要额外的固件,默认安装的 linux-firmware 提供了很多固件。如果缺失需要的固件,请查看 #安装 driver/firmware.

Udev 不是完美的,有些内核模块需要手动安装. 有些时候 Udev 会同时加载相互冲突的多个模块,就需要屏蔽 不需要的模块。

检查设备状态

根据设备是 PCI 还是 USB 连接,执行 lspci -klsusb -v 检查设备驱动是否已经加载:

$ lspci -k
06:00.0 Network controller: Intel Corporation WiFi Link 5100
	Subsystem: Intel Corporation WiFi Link 5100 AGN
	Kernel driver in use: iwlwifi
	Kernel modules: iwlwifi

如果是 USB 设备,执行 dmesg | grep usbcore 可以看到类似下面的输出 usbcore: registered new interface driver rtl8187

通过 ip link 查看无线 (设备名[损坏的链接:无效的章节],通常是类似 wlp2s1) 的设备。启用设备:

# ip link set <设备名> up

如果设备加载,接口正常启用,说明不需要安装额外的驱动和固件。

安装 driver/firmware

错误信息SIOCSIFFLAGS: No such file or directory 说明需要固件才能工作,

检查内核中的固件信息:

# dmesg | grep firmware
[   7.148259] iwlwifi 0000:02:00.0: loaded firmware version 39.30.4.1 build 35138 op_mode iwldvm

如果没有类似的输出,先执行命令,例如iwlwifi,然后查找对应的错误信息:

# dmesg | grep iwlwifi
[   12.342694] iwlwifi 0000:02:00.0: irq 44 for MSI/MSI-X
[   12.353466] iwlwifi 0000:02:00.0: loaded firmware version 39.31.5.1 build 35138 op_mode iwldvm
[   12.430317] iwlwifi 0000:02:00.0: CONFIG_IWLWIFI_DEBUG disabled
...
[   12.430341] iwlwifi 0000:02:00.0: Detected Intel(R) Corporation WiFi Link 5100 AGN, REV=0x6B

根据获得的信息,在下面网址查找硬件支持:

注意有些厂商的产品即使有相同的名称,实际使用的芯片却是不同的。必须通过usb-id (USB设备) 或 pci-id (PCI设备) 进行判断。

如果列表中没有,可能你的设备只提供了 Windows 驱动(比如 Broadcom, 3com 等)。这时需要用 ndiswrapper[失效链接 2020-08-04 ⓘ].

Ndiswrapper 可以在 Linux 中使用 Windows 驱动。兼容性列表在 这里[失效链接 2020-08-04 ⓘ]. 需要 Windows 中安装的 .inf.sys 文件。如果有更新的网卡,请通过互联网搜索型号名称 + 'linux' 以获取更多信息。

无线网络管理

为了管理已经安装好的无线驱动,并且使无线能正常工作,需要安装一个无线连接管理工具。下面章节将帮助您确定一个最佳管理方法。

过程和需要使用的工具,将依赖于下面几个因素:

  • 配置方式,从完全手动执行每一步到软件自动管理、自动启动
  • 是否使用加密及加密类型
  • 是否需要区分网络配置,是否经常切换不同网络(比如手提电脑)
  • 如果要在不同网络间切换,使用工具会更方便

无论选的那个方案,最好先尝试手动方法。这将有助于您了解不同步骤的意义,并在出问题时解决之。 如果可以的话(比如说你在管理你自己的无线接入点),尝试连接一个开放的无线网络来检查是否所有的配置都在正常工作。然后再尝试加密的无线接入点,比如WEP(更易于配置)或者WPA。

此表列出可以使用的激活和管理无线网络的方法,按照加密和管理方式分类,给出了需要的工具。虽然还有其他办法,但这些是最常使用的:

管理方法 接口激活 无线连接管理
(/=alternatives)
IP 地址分配
(/=alternatives)
手动设置
无加密或 WEP 加密
ip iw/iwconfig ip/dhcpcd/dhclient/networkd
手动管理
WPA 或 WPA2 PSK 加密
ip iw/iwconfig + wpa_supplicant ip/dhcpcd/dhclient
自动管理
支持网络配置
netctlWicdNetworkManager 等等

这些工具会自动安装手动配置需要的工具。

手动设置

软件包 wireless_tools 提供了建立无线连接的基础工具。如果你需要使用 WPA/WPA2 加密,还需要 wpa_supplicant。 这些强大的用户空间终端工具提供了完全的控制手段。

这些例子假设无线设备是 wlan0, 请将其替换为正确的设备名。

注意: 根据硬件和加密方式的不同,下面一些步骤可以省略。有些设备需要在建立关联时激活接口或扫描访问点,并提供 IP 地址。需要进行一些尝试,例如 WPA/WPA2 用户可以直接到第三步激活无线网络。

和其它网络接口一样,无线设备也是通过 iproute2 软件包提供的 ip 命令进行。

基本的工具如下,这些用户空间工具可以对无线连接进行完整控制。

  • iw - 仅支持 nl80211 标准,不支持老的 WEXT (Wireless EXTentions) 标准。如果 iw 没有显示网卡,可能是这个原因。
  • wireless_tools - 已经过时,但是依然广泛使用。WEXT 设备使用此工具。
  • wpa_supplicant - 提供 WPA/WPA2 加密支持,同时支持 nl80211 和 WEXT。

下面表格给出了 iwwireless_tools 命令的对比(更多示例参阅 这里)。

注意:
  • 安装介质上提供了手工管理和 netctl 管理的工具
  • 示例中使用网络接口 wlan0 和热点 your_essid
  • 大部分命令需要以 root 权限执行,否则会无输出就退出。
iw 命令 wireless_tools 命令 描述
iw dev wlan0 link iwconfig wlan0 获取连接状态
iw dev wlan0 scan iwlist wlan0 scan 扫描可用热点
iw dev wlan0 set type ibss iwconfig wlan0 mode ad-hoc 设置操作模式为 ad-hoc.
iw dev wlan0 connect your_essid iwconfig wlan0 essid your_essid 连接到开放网络
iw dev wlan0 connect your_essid 2432 iwconfig wlan0 essid your_essid freq 2432M 连接到开放网络的一个频道
iw dev wlan0 connect your_essid key 0:your_key iwconfig wlan0 essid your_essid key your_key 用16进制加密密码访问 WEP 加密网络
iw dev wlan0 connect your_essid key 0:your_key iwconfig wlan0 essid your_essid key s:your_key 用 ASCII 密码访问 WEP 加密网络.
iw dev wlan0 set power_save on iwconfig wlan0 power on 启用省电模式
注意: 根据硬件和加密设备的不同,有些步骤可以跳过。一些网卡需要在关联到热点前先激活或扫描热点,需要一些实验才能确定。WPA/WPA2 用户可以按照#关联中的步骤激活网络。

获取有用信息

iw 官方文档 包含更多示例。

  • 获取接口名:
$ iw dev
phy#0
	Interface wlan0
		ifindex 3
		wdev 0x1
		addr 12:34:56:78:9a:bc
		type managed
		channel 1 (2412 MHz), width: 40 MHz, center1: 2422 MHz
  • 检查连接状态,未连接时,可以看到:
$ iw dev wlan0 link
Not connected.

连接到 AP 后可以看到:

$ iw dev wlan0 link
Connected to 12:34:56:78:9a:bc (on wlan0)
	SSID: MyESSID
	freq: 2412
	RX: 33016518 bytes (152703 packets)
	TX: 2024638 bytes (11477 packets)
	signal: -53 dBm
	tx bitrate: 150.0 MBit/s MCS 7 40MHz short GI

	bss flags:	short-preamble short-slot-time
	dtim period:	1
	beacon int:	100
  • 获取统计数据:
$ iw dev wlan0 station dump
Station 12:34:56:78:9a:bc (on wlan0)
	inactive time:	1450 ms
	rx bytes:	24668671
	rx packets:	114373
	tx bytes:	1606991
	tx packets:	8557
	tx retries:	623
	tx failed:	1425
	signal:  	-52 dBm
	signal avg:	-53 dBm
	tx bitrate:	150.0 MBit/s MCS 7 40MHz short GI
	authorized:	yes
	authenticated:	yes
	preamble:	long
	WMM/WME:	yes
	MFP:		no
	TDLS peer:	no

激活内核接口

(可能需要) 一些无线网卡在使用 wireless_tools前需要激活内核接口:

# ip link set wlan0 up

如果出现错误 RTNETLINK answers: Operation not possible due to RF-kill, 请确保硬件开关已经打开。参阅 #Rfkill 警告[损坏的链接:无效的章节]

要验证接口确实打开:

# ip link show wlan0
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
    link/ether 12:34:56:78:9a:bc brd ff:ff:ff:ff:ff:ff

<BROADCAST,MULTICAST,UP,LOWER_UP> 中的UP 显示接口已经打开。

查看接入点

# iw dev wlan0 scan |less
注意: 如果显示 "Interface doesn't support scanning",可能是忘了安装固件。有时不以 root 运行 iwlist 也会产生这个问题。同样无线网络可能被软禁于,请运行 rfkill list all 进行检查。

需要关注的信息:

  • SSID: 网络的名称.
  • Signal: 用 dbm (-100 to 0) 报告的无线信号强度。数值越接近零,信号越好。观察高质量连接和低质量连接的数值差异可以了解设备的信号范围。
  • Security: 没有直接报告, 检查 capability 开头的行,如果有 Privacy 信息,例如 capability: ESS Privacy ShortSlotTime (0x0411), 表示网络具有某种程度的保护,
    • 如果有 RSN 信息,网络被 Robust Security Network(WPA2) 协议保护。
    • 如果有 WPA 信息,网络被 Wi-Fi Protected Access 协议保护。
    • RSNWPA 信息块中,可能看到如下信息:
      • Group cipher: 数值包括 TKIP, CCMP, both, others.
      • Pairwise ciphers: 数值包括 TKIP, CCMP, both, others. 可能和 Group cipher 数值不同.
      • Authentication suites: 数值包括 PSK, 802.1x, others. 家用路由器通常可以看到 PSK (i.e. 密码). 在大学中,通常会链接到需要登录名和密码的 802.1x 网络。需要知道其使用的密码管理方式(例如 EAP), 封装方法 (例如 PEAP). 详情请参考 这里这里.
    • 如果没有看到 RSNWPA,但是看到了 Privacy, 表示使用的是 WEP.

运行模式

设置无线网卡的操作模式,如果连接到漫游网络,需要设置操作模式为 ibss

# iw wlan0 set type ibss
注意: 有些网卡需要先关闭无线接口(ip link set wlan0 down)才能修改模式。

关联

根据加密方式不同,需要使用密码将无线设备关联到接入点。

假设要使用的接入点 ESSID 为 MyEssid:

  • 无加密
# iw wlan0 connect MyEssid
  • WEP

使用十六进制或 ASCII 密码(格式是自动识别出来的,因为 WEP 密码长度是固定的):

# iw dev wlan0 connect your_essid key 0:your_key

使用十六进制或 ASCII 密码,第三个是默认 (从0计数,共四个):

# iw dev wlan0 connect your_essid key d:2:your_key
  • WPA/WPA2
# wpa_supplicant -i interface -c <(wpa_passphrase your_SSID your_key)

假设设备使用 wext 驱动。如果无法工作,可能需要调整选项,参见 WPA supplicant

如果连接成功,在新终端中执行后续命令或(或者通过 Ctrl+c 退出并使用 -B 参数在后台再次执行上述命令。WPA supplicant 页面包含更多参数和配置文件的信息。

通过下面命令确认是否连接成功:

# iw dev wlan0 link

获取 IP 地址

使用 DHCP:

# dhcpcd wlan0

静态 IP:

# ip addr add 192.168.0.2/24 dev wlan0
# ip route add default via 192.168.0.1
提示: dhcpcd 提供了 钩子[损坏的链接:无效的章节], 可以使用它自动在无线接口上启动 WPA supplicant

示例

下面是一个用 WPA supplicant 和 DHCP 设置无线网络的完整示例.

# ip link set dev wlp13s1 up
# wpa_supplicant -B -i wlp13s1 -c /etc/wpa_supplicant/wpa_supplicant.conf
# dhcpcd wlp13s1

要关闭连接,可以禁用接口:

# ip link set dev wlp13s1 down

要使用静态 IP,将 dhcpcd 命令替换为:

# ip addr add 192.168.0.10/24 broadcast 192.168.0.255 dev wlp13s1
# ip route add default via 192.168.0.1

禁用接口前,需要先刷新 IP 地址和网关:

# ip addr flush dev wlp13s1
# ip route flush dev wlp13s1

自动设置

有许多可选方法,但是注意它们是互斥的,不能同时运行两个守护进程。下面是比较表格:

连接管理器 profiles 支持 漫游
(自动连接和重连)
PPP 支持
(3G modem)
官方
GUI
控制台工具
ConnMan Yes Yes Yes No connmanctl
Netctl Yes Yes Yes No netctl,wifi-menu
NetworkManager Yes Yes Yes Yes nmcli,nmtui
Wicd Yes Yes No Yes wicd-curses

Connman

ConnMan 可以替代 NetworkManager 或 Wicd, 设计上考虑低资源消耗,以上网本和其它移动设备为目标。模块化设计并利用 dbus API,提供了 wpa_supplicant 抽象.

参阅: ConnMan

Netctl

netctl 与 systemd 一起工作。基于配置文件,可以检查和连接多种网络类型。使用简单,并不比图形工具难。 参阅: Netctl (简体中文)

Wicd

Wicd 是可以同时处理无线和有线网络的管理器。用 Python 和 Gtk 写成,依赖关系比 NetworkManager 少,所以是轻量级桌面的理想选择。位于官方软件仓库.

参见: Wicd (简体中文).

NetworkManager

NetworkManager 是高级网络管理工具,在大部分流行发行版中使用。除了能管理有线链接,NetworkManager还提供了一个易于使用的图形界面程序来选择想要的无线移动链接。

详情请见 NetworkManager (简体中文)

WPA2 企业模式

WPA2 企业模式是 WPA(Wi-Fi Protected Access)的工作模式之一。It provides better security and key management than WPA2 Personal, and supports other enterprise-type functionality, such as VLANs and NAP. However, it requires an external authentication server, called RADIUS server to handle the authentication of users. This is in contrast to Personal mode which does not require anything beyond the wireless router or access points (APs), and uses a single passphrase or password for all users.

WPA2 企业模式 是 WPA(Wi-Fi Protected Access)的工作模式之一。相比 WPA2 Personal 而言,它提供了更好的安全性和密钥管理功能,同时也提供了 VLANS 和 NAP 之类的企业功能。当然,它需要额外的 RADIUS 认证服务器来为用户提供认证服务,这就和只需要无线路由器或者接入点,所有用户都使用同一个密码的个人模式不同。

The Enterprise mode enables users to log onto the Wi-Fi network with a username and password and/or a digital certificate. Since each user has a dynamic and unique encryption key, it also helps to prevent user-to-user snooping on the wireless network, and improves encryption strength.

企业模式允许用户使用用户名和密码或者数字证书来登陆 Wi-Fi。因为每个用户都拥有一个动态唯一的加密密码,因此企业模式可以防止通过无限网络的用户探听,并提高加密强度。

This section describes the configuration of network clients to connect to a wireless access point with WPA2 Enterprise mode. See Software access point#RADIUS for information on setting up an access point itself.

本章节讲解 network clients 使用WPA2企业模式来连接无线接入点的配置。查看 Software access point#RADIUS 来获得如何设置接入点自身的相关信息。

注意: Enterprise mode requires a more complex client configuration, whereas Personal mode only requires entering a passphrase when prompted. Clients likely need to install the server’s CA certificate (plus per-user certificates if using EAP-TLS), and then manually configure the wireless security and 802.1X authentication settings.

For a comparison of protocols see the following table.

警告: It is possible to use WPA2 Enterprise without the client checking the server CA certificate. However, you should always seek to do so, because without authenticating the access point the connection can be subject to a man-in-the-middle attack. This may happen because while the connection handshake itself may be encrypted, the most widely used setups transmit the password itself either in plain text or the easily breakable #MS-CHAPv2. Hence, the client might send the password to a malicious access point which then proxies the connection.

eduroam

eduroam (education roaming) is an international roaming service for users in research, higher education and further education, based on WPA2 Enterprise.

警告:
  • Check connection details first with your institution before applying any profiles listed in this section. Example profiles are not guaranteed to work or match any security requirements.
  • When storing connection profiles unencrypted, restrict read access to the root account by specifying chmod 600 profile as root.
提示: Configuration for NetworkManager and #wpa_supplicant can be generated with the eduroam Configuration Assistant Tool.

手工/自动配置

wpa_supplicant

WPA supplicant 可直接配置并使用于dhcp客户端或systemd。 参照/etc/wpa_supplicant/wpa_supplicant.conf 来配置连接细节信息。

NetworkManager

NetworkManager can generate WPA2 Enterprise profiles with graphical front ends. nmcli and nmtui do not support this, but may use existing profiles.

connman

ConnMan needs a separate configuration file before connecting to the network. See connman-service.config(5) and ConnMan#Connecting to eduroam[损坏的链接:无效的章节] for details.

netctl

netctl supports #wpa_supplicant configuration through blocks included with WPAConfigSection=. See netctl.profile(5) for details.

警告: Special quoting rules apply: see the SPECIAL QUOTING RULES section in netctl.profile(5).
提示: Custom certificates can be specified by adding the line 'ca_cert="/path/to/special/certificate.cer"' in WPAConfigSection.

排错

MS-CHAPv2

WPA2-Enterprise wireless networks demanding MSCHAPv2 type-2 authentication with PEAP sometimes require pptpclient in addition to the stock ppp package. netctl seems to work out of the box without ppp-mppe, however. In either case, usage of MSCHAPv2 is discouraged as it is highly vulnerable, although using another method is usually not an option. See also [1] and [2].

提示和技巧

Rfkill 说明

许多笔记本都有一个硬件按钮或开关用于关闭无线网卡,然而无线网卡也可以通过内核来屏蔽。这一任务可由 rfkill 处理。显示当前状态:

# rfkill list
0: phy0: Wireless LAN
	Soft blocked: yes
	Hard blocked: yes

如果网卡处于硬件屏蔽(hard-blocked)状态,请使用硬件按钮或开关来开启它。 如果无线网卡并没有被硬件屏蔽但处于软件屏蔽(soft-blocked),请使用以下命令:

# rfkill unblock wifi
注意: 按下硬件按钮可能会让无线网卡从硬件屏蔽,软件未屏蔽状态变为硬件未屏蔽,软件屏蔽状态。 可以通过调整 rfkill 内核模块的一些选项改变这一现象。

切换无线网卡的硬件按钮是厂商专用的内核模块处理的,经常是 WMI 模块。特别是非常新的硬件型号,可能还没有得到最新稳定内核的完全支持。这种情况下,在内核 bug 跟踪系统搜索信息,并将型号报告给对应厂商内核模块的维护者(如果还没有报告的话)经常会有帮助。

参见 https://askubuntu.com/questions/62166/siocsifflags-operation-not-possible-due-to-rf-kill

遵循监管区域要求

监管区域用于配置无线驱动,确保对无线硬件的使用符合由 FCC、ETSI 及其他组织制定的当地法规。监管区域使用ISO 3166-1二位字母国家代码。例如,美国的监管区域代码是“US”,中国则是“CN”,等等。

监管区域影响无线信道的可用性。在2.4GHz波段,美国允许使用1-11信道,日本是1-14,世界上多数其它地区则是1-13。在5GHz波段,允许使用信道的规则要复杂得多。这两种情况的更详细信息见这一WLAN信道列表

监管区域也影响对来自无线设备的等效各向同性辐射功率(EIRP)所作的限制。这衍生自发射功率(tx power)并以dBm/mBm(1dBm=100mBm)或mW(对数尺度)衡量。在2.4GHz波段,美国和加拿大最大限制30dBm,欧洲大部分是20dBm,世界上其他地区则是20dB-30dBm。在5GHz波段,最大值通常更低。更详细的信息请参考 wireless-regdb(EIRP dBm 值在每行第二对括号里)。

错误设置监管区域可能会有用——例如,在其他信道拥挤时可以使用未用信道,或者提升发射功率以扩大传输范围。然而不推荐这种做法,因为可能会违反当地法规以及造成与其他无线电设备的干扰。

要配置监管区域,安装 crda 并重启(以重新加载 cfg80211 模块及所有相关驱动)。检查启动日志以确认 cfg80211 正在调用CRDA:

# dmesg | grep cfg80211

以下命令可将当前监管区域设为美国:

# iw reg set US

用以下命令查询:

$ iw reg get
注意:
  • 你的设备国家代码可能为“00”,它是包含了通用设置的“世界监管区域”。如果无法解除此设置,则CRDA可能配置有误。
  • 根据 CRDA 的 README,从内核版本4.15开始就不再需要它,因为内核会自动从固件加载监管数据库。然而也有说法称这一加载操作需要特定的内核设置。

然而设置监管区域可能不会改变您的设置。有些设备在固件/EEPROM中设置了一个监管区域,为设备规定了限制,这意味着通过软件设置监管区域只能增加限制而不能减少。例如,一个 CN(中国)设备可以用软件设置为 US(美国)监管区域,但由于中国的 EIRP 最大值为20dBm,设备将无法以美国的最大值30dBm进行发射。

例如,查看一个 Atheros 设备的固件中是否设置了监管区域:

# dmesg | grep ath:

对于其他芯片组,搜索“EEPROM”、“regdomain”或设备驱动的名字可能会有用。

要查看监管区域更改是否成功,以及查询可用信道数和允许发射功率:

$ iw list | grep -A 15 Frequencies:

监管区域的持久设置可以通过编辑 /etc/conf.d/wireless-regdom 并解除相应区域的注释实现。 wpa_supplicant 也可以在 /etc/wpa_supplicant/wpa_supplicant.conf 中的 country= 行应用监管区域。

也可以通过添加模块参数(如 options cfg80211 ieee80211_regdom=EU),配置 cfg80211 内核模块,从而使用指定的监管区域。然而这是一种老旧的监管实现

更多信息请阅读 wireless.kernel.org 监管文档

节能

Power saving#Network interfaces

排错

这个单元包含一般性的问题快照(troubleshooting)和提示, 问题与设备与固件驱动并没有什么严格意义上的关系。 对于驱动与固件上的问题, 请看 #驱动与固件排错.

临时上网

如果你有问题性的设备并且需要Internet访问, 例如, 下载一些软件或向社区寻求帮助, 你可以通过Android自带的USB共享网络功能。 更多信息详见[[Android tethering#USB tethering]。

Observing Logs

A good first measure to troubleshoot is to analyze the system's logfiles first. In order not to manually parse through them all, it can help to open a second terminal/console window and watch the kernels messages with

# dmesg -w

while performing the action, e.g. the wireless association attempt.

When using a tool for network management, the same can be done for systemd with

# journalctl -f 

Frequently a wireless error is accompanied by a deauthentication with a particular reason code, for example:

wlan0: deauthenticating from XX:XX:XX:XX:XX:XX by local choice (reason=3)

Looking up the reason code might give a first hint. Maybe it also helps you to look at the control message flowchart, the journal messages will follow it.

The individual tools used in this article further provide options for more detailed debugging output, which can be used in a second step of the analysis, if required.

Failed to get IP address

  • If getting an IP address repeatedly fails using the default dhcpcd client, try installing and using dhclient instead. Do not forget to select dhclient as the primary DHCP client in your connection manager!
  • If you can get an IP address for a wired interface and not for a wireless interface, try disabling the wireless card's power saving features (specify off instead of on).
  • If you get a timeout error due to a waiting for carrier problem, then you might have to set the channel mode to auto for the specific device:
# iwconfig wlan0 channel auto

Before changing the channel to auto, make sure your wireless interface is down. After it has successfully changed it, you can bring the interface up again and continue from there.

Valid IP address but cannot resolve host

If you are on a public wireless network that may have a captive portal, make sure to query an HTTP page (not an HTTPS page) from your web browser, as some captive portals only redirect HTTP. If this is not the issue, it may be necessary to remove any custom DNS servers from resolv.conf.

Setting RTS and fragmentation thresholds

Wireless hardware disables RTS and fragmentation by default. These are two different methods of increasing throughput at the expense of bandwidth (i.e. reliability at the expense of speed). These are useful in environments with wireless noise or many adjacent access points.

Packet fragmentation improves throughput by splitting up packets with size exceeding the fragmentation threshold. The maximum value (2346) effectively disables fragmentation since no packet can exceed it. The minimum value (256) maximizes throughput, but may carry a significant bandwidth cost.

# iw phy0 set frag 512

RTS improves throughput by performing a handshake with the access point before transmitting packets with size exceeding the RTS threshold. The maximum threshold (2347) effectively disables RTS since no packet can exceed it. The minimum threshold (0) enables RTS for all packets, which is probably excessive for most situations.

# iw phy0 set rts 500
注意: phy0 is the name of the wireless device as listed by $ iw phy.

Random disconnections

Cause #1

If dmesg says wlan0: deauthenticating from MAC by local choice (reason=3) and you lose your Wi-Fi connection, it is likely that you have a bit too aggressive power-saving on your Wi-Fi card[3]. Try disabling the wireless card's power saving features (specify off instead of on).

If your card does not support enabling/disabling power save mode, check the BIOS for power management options. Disabling PCI-Express power management in the BIOS of a Lenovo W520 resolved this issue.

Cause #2

If you are experiencing frequent disconnections and dmesg shows messages such as

ieee80211 phy0: wlan0: No probe response from AP xx:xx:xx:xx:xx:xx after 500ms, disconnecting

try changing the channel bandwidth to 20MHz through your router's settings page.

Cause #3

On some laptop models with hardware rfkill switches (e.g., Thinkpad X200 series), due to wear or bad design, the switch (or its connection to the mainboard) might become loose over time resulting in seemingly random hardblocks/disconnects when you accidentally touch the switch or move the laptop. There is no software solution to this, unless your switch is electrical and the BIOS offers the option to disable the switch. If your switch is mechanical (most are), there are lots of possible solutions, most of which aim to disable the switch: Soldering the contact point on the mainboard/wifi-card, glueing or blocking the switch, using a screw nut to tighten the switch or removing it altogether.

Cause #4

Another cause for frequent disconnects or a complete failure to connect may also be a sub-standard router, incomplete settings of the router, or interference by other wireless devices.

To troubleshoot, first best try to connect to the router with no authentication.

If that works, enable WPA/WPA2 again but choose fixed and/or limited router settings. For example:

  • If the router is considerably older than the wireless device you use for the client, test if it works with setting the router to one wireless mode
  • Disable mixed-mode authentication (e.g. only WPA2 with AES, or TKIP if the router is old)
  • Try a fixed/free channel rather than "auto" channel (maybe the router next door is old and interfering)
  • Disable 40Mhz channel bandwidth (lower throughput but less likely collisions)
  • If the router has quality of service settings, check completeness of settings (e.g. Wi-Fi Multimedia (WMM) is part of optional QoS flow control. An erroneous router firmware may advertise its existence although the setting is not enabled)

驱动与固件排错

This section covers methods and procedures for installing kernel modules and firmware for specific chipsets, that differ from generic method.

See Kernel modules for general informations on operations with modules.

Ralink

rt2x00

Ralink 芯片组的统一驱动,代替了 rt2500, rt61, rt73 等。Linux 内核从 2.6.24 开始包含此驱动,但是有些设备可能需要额外固件。可以使用标准 wpa_supplicantiwconfig 工具配置。

有些芯片组需要固件文件,可以安装软件包 linux-firmware

参见: Using the new rt2x00 beta driver

  • Since kernel 3.0, rt2x00 includes also these drivers: rt2800pci, rt2800usb. rt2860sta 被主分支驱动 rt2800pci 替代,rt2870start2800usb 替代。
  • 通过 iwpriv 可以配置很多参数,文档在 Ralink 源代码包 中。

rt3090

For devices which are using the rt3090 chipset it should be possible to use rt2800pci driver, however, is not working with this chipset very well (e.g. sometimes it's not possible to use higher rate than 2Mb/s).

The best way is to use the rt3090-dkmsAUR[损坏的链接:package not found] driver from AUR. Make sure to blacklist the rt2800pci module and setup the rt3090sta module to load[损坏的链接:无效的章节] at boot.

注意: This driver also works with rt3062 chipsets. Also the rt3090AUR[损坏的链接:package not found] package is not supported by the latest kernel and has been orphaned rt3090-dkmsAUR[损坏的链接:package not found] should be used instead.

rt3290

The rt3290 chipset is recognised by the kernel rt2800pci module. However, some users experience problems and reverting to a patched Ralink driver seems to be beneficial in these cases.

rt3573

2012年新出的芯片组,需要 Ralink 的闭源驱动,有不同的厂商使用他们,参阅Belkin N750 示例

rt5572

支持 5 Gh 频率,需要 Ralink 的闭源驱动,编译指令位于这里[失效链接 2021-11-15 ⓘ]

Realtek

rtl8192cu

The driver is now in the kernel, but many users have reported being unable to make a connection although scanning for networks does work.

Package 8192cu-dkmsAUR in the AUR includes many patches, try this if it doesn't work fine with the driver in kernel.

rtl8192e

The driver is part of the current kernel package. 启动时可能装入模块失败,错误信息是:

rtl819xE:ERR in CPUcheck_firmware_ready()
rtl819xE:ERR in init_firmware() step 2
rtl819xE:ERR!!! _rtl8192_up(): initialization is failed!
r8169 0000:03:00.0: eth0: link down

一个暂时的解决方法是卸载模块:

# modprobe -r r8192e_pci

等一会后,重新装入模块:

# modprobe r8192e_pci

rtl8188eu

Some dongles, like the TP-Link TL-WN725N v2 (not sure, but it seems that uses the rtl8179 chipset), use chipsets compatible with this driver. In Linux 3.12 the driver has been moved to kernel staging source tree. For older kernels use out-of-tree driver sources built with dkms - install 8188eu-dkmsAUR. At the times of 3.15 kernel rtl8188eu driver is buggy and has many stability issues.

rtl8723ae/rtl8723be

The new rtl8723ae module is included in the mainline Linux kernel since version 3.6, the rtl8723be module since 3.15.

Some users may encounter errors with powersave on this card. This is shown with occasional disconnects that are not recognized by high level network managers (netctl, NetworkManager). This error can be confirmed by running dmesg -w or journalctl -f and looking for output related to powersave and the rtl8723ae/rtl8723be module. If you are having this issue, use the fwlps=0 kernel option, which should prevent the WiFi card from automatically sleeping and halting connection.

/etc/modprobe.d/rtl8723ae.conf
options rtl8723ae fwlps=0

or

/etc/modprobe.d/rtl8723be.conf
options rtl8723be fwlps=0

如果信号质量很差,可能是一个天线不工作,无法运行在自动模式。可以用 ant_sel=1ant_sel=2 内核选项强制选择天线。

rtl8812au/rtl8821au

Newer 802.11 a/b/g/n usb adapters, such as the Glam Hobby AC600 (Ourlink) may require rtl8812 or rtl8821 drivers before working.

The 8812 driver can be found as rtl8812au-dkms-gitAUR.

# modprobe 8812au

If that does not work (like for the AC600 dongles), try the 8812/8821 module rtl8812au_rtl8821au-dkms-gitAUR[损坏的链接:package not found].

# modprobe rtl8812au_rtl8821au

These require DKMS so make sure you have your proper kernel headers installed.

Atheros

MadWifi team 开发组维护了三个模块:
  • madwifi 是最老的驱动, Arch kernel 从 2.6.39.1 开始已经不再包含。
  • ath5k 将逐步替代 ath_pci,有些芯片组使用效果很好,但有些还不能很好工作(后面有介绍)
  • ath9k 是新的官方驱动,适用于新 Atheros 硬件。

There are some other drivers for some Atheros devices. See Linux Wireless documentation for details.

ath5k

参考:

If you find web pages randomly loading very slow, or if the device is unable to lease an IP address, try to switch from hardware to software encryption by loading the ath5k module with nohwcrypt=1 option. See Kernel modules#Setting module options for details.

有些笔记本的 LED 指示灯有问题,可以:

echo none > "/sys/class/leds/ath5k-phy0::tx/trigger"
echo none > "/sys/class/leds/ath5k-phy0::rx/trigger"

ath9k

ath9k 是 Atheros 官方支持的驱动,支持所有带 802.11n 功能的芯片组,最大传输速度 180 Mbps. 这个页面 列出了所有支持的硬件。

工作模式:Station, AP and Adhoc.

ath9k 是官方内核的一部分。如果在极个别情况下遇到稳定性问题,可以使用 compat-wireless 软件包。ath9k 邮件列表[失效链接 2020-08-04 ⓘ] 提供了支持和开发的相关信息。

参考:

ath9k

External resources:

As of Linux 3.15.1, some users have been experiencing a decrease in bandwidth. In some cases this can fixed by editing /etc/modprobe.d/ath9k.conf and adding the line:

options ath9k nohwcrypt=1
注意: Check with the command lsmod what module(-name) is in use and change it if named otherwise (e.g. ath9k_htc).

In the unlikely event that you have stability issues that trouble you, you could try using the backports-patchedAUR package. An ath9k mailing list[失效链接 2020-08-04 ⓘ] exists for support and development related discussions.

Power saving

Although Linux Wireless says that dynamic power saving is enabled for Atheros ath9k single-chips newer than AR9280, for some devices (e.g. AR9285) powertop might still report that power saving is disabled. In this case enable it manually.

On some devices (e.g. AR9285), enabling the power saving might result in the following error:

# iw dev wlan0 set power_save on
command failed: Operation not supported (-95)

The solution is to set the ps_enable=1 option for the ath9k module:

/etc/modprobe.d/ath9k.conf
options ath9k ps_enable=1

Intel

ipw2100 与 ipw2200

内核完全支持,但是需要安装额外的固件。根据芯片组型号,安装 软件包 ipw2100-fwipw2200-fw

提示: You may use the following module options:
  • use the rtap_iface=1 option to enable the radiotap interface
  • use the led=1 option to enable a front LED indicating when the wireless is connected or not

iwlegacy

iwlegacy is the wireless driver for Intel's 3945 and 4965 wireless chips. The firmware is included in the linux-firmware package.

udev should load the driver automatically, otherwise load iwl3945 or iwl4965 manually. See Kernel modules for details.

If you have problems connecting to networks in general or your link quality is very poor, try to disable 802.11n:

/etc/modprobe.d/iwl4965.conf
options iwl4965 11n_disable=1

iwlwifi

iwlwifi is the wireless driver for Intel's current wireless chips, such as 5100AGN, 5300AGN, and 5350AGN. See the full list of supported devices. The firmware is included in the linux-firmware package.

If you have problems connecting to networks in general or your link quality is very poor, try to disable 802.11n and enable software encryption:

/etc/modprobe.d/iwlwifi.conf
options iwlwifi 11n_disable=1
options iwlwifi swcrypto=1

If you have a problem with slow uplink speed in 802.11n mode, for example 20Mbps, try to enable antenna aggregation:

/etc/modprobe.d/iwlwifi.conf
options iwlwifi 11n_disable=8

Do not be confused with the option name, when the value is set to 8 it does not disable anything but re-enables transmission antenna aggregation.[4] [5]

In case this does not work for you, you may try disabling power saving for your wireless adapter.

Some have never gotten this to work. Others found salvation by disabling N in their router settings after trying everything. This is known to have be the only solution on more than one occasion. The second link there mentions a 5ghz option that might be worth exploring.

注意: The linux-lts-3.14 kernel may take several minutes to load the firmware and make the wireless card ready for use. The issue is reported to be fixed in linux-3.17 kernel.[6]
Bluetooth coexistence

If you have difficulty connecting a bluetooth headset and maintaining good downlink speed, try disabling bluetooth coexistence [7]:

/etc/modprobe.d/iwlwifi.conf
options iwlwifi bt_coex_active=0
禁用 LED 闪烁
注意: This works with the iwlegacy and iwlwifi drivers.

默认设置中 LED 闪烁是开着的,有些人不喜欢,可以systemd-tmpfiles[损坏的链接:无效的章节]禁止闪烁:

/etc/tmpfiles.d/phy0-led.conf
w /sys/class/leds/phy0-led/trigger - - - - phy0radio

Run systemd-tmpfiles --create phy0-led.conf for the change to take effect, or reboot.

To see all the possible trigger values for this LED:

# cat /sys/class/leds/phy0-led/trigger
提示: If you do not have /sys/class/leds/phy0-led, you may try to use the led_mode="1" module option. It should be valid for both iwlwifi and iwlegacy drivers.
# cat /sys/class/leds/phy0-led/trigger

Broadcom

See Broadcom wireless.

Tenda w322u

Treat this Tenda card as an rt2870sta device. See #rt2x00.

orinoco

这应当是内核的一部分,是已经被安装的。

Some Orinoco chipsets are Hermes II. You can use the wlags49_h2_cs driver instead of orinoco_cs and gain WPA support. To use the driver, blacklist orinoco_cs first.

prism54

The driver p54 is included in kernel, but you have to download the appropriate firmware for your card from this site and install it into the /usr/lib/firmware directory.

过时的 prism54 和新内核模块 p54pcip54usb 同时装入造成冲突,使用 lsmod | grep prism54 查看是否装入了过时模块,如果是,那么就 屏蔽 prism54 并根据上面方法修改固件名称。

ACX100/111

警告: The drivers for these devices are broken and do not work with newer kernel versions.

Packages: tiacx tiacx-firmware (deleted from official repositories and AUR)

See official wiki for details.

zd1211rw

zd1211rw 是ZyDAS ZD1211 802.11b/g USB WLAN芯片的驱动,最近的版本的内核已经包括了。zd1211rw [8]有被支持的设备列表。 你只需要这样安装固件zd1211-firmwareAUR

hostap_cs

Host AP is a Linux driver for wireless LAN cards based on Intersil's Prism2/2.5/3 chipset. The driver is included in Linux kernel.

注意: Make sure to blacklist the orinico_cs driver, it may cause problems.

Other drivers/devices

Tenda w322u

Treat this Tenda card as an rt2870sta device. See #rt2x00.

orinoco

This should be a part of the kernel package and be installed already.

Some Orinoco chipsets are Hermes II. You can use the wlags49_h2_cs driver instead of orinoco_cs and gain WPA support. To use the driver, blacklist orinoco_cs first.

prism54

The driver p54 is included in kernel, but you have to download the appropriate firmware for your card from this site and install it into the /usr/lib/firmware directory.

注意: There is also older, deprecated driver prism54, which might conflict with the newer driver (p54pci or p54usb). Make sure to blacklist prism54.

ACX100/111

警告: The drivers for these devices are broken and do not work with newer kernel versions.

Packages: tiacx tiacx-firmware (deleted from official repositories and AUR)

See official wiki for details.

zd1211rw

zd1211rw is a driver for the ZyDAS ZD1211 802.11b/g USB WLAN chipset, and it is included in recent versions of the Linux kernel. See [9] for a list of supported devices. You only need to install the firmware for the device, provided by the zd1211-firmwareAUR package.

hostap_cs

Host AP is a Linux driver for wireless LAN cards based on Intersil's Prism2/2.5/3 chipset. The driver is included in Linux kernel.

注意: Make sure to blacklist the orinico_cs driver, it may cause problems.

ndiswrapper

Ndiswrapper并不是一个真正的驱动,但是如果你无法找到适合你的无线网卡驱动的适合, 它就派上用场了.有的时候, 它是非常有用的.为了使用Ndiswrapper, 你需要Windows驱动中的*.inf文件(*.sys文件应该和*.info在同一个目录中)。如果你需要从 *.exe 文件解压缩,你可以使用 cabextract.

警告: 确保使用合适架构(也就是32/64位)的驱动。

下面是安装ndiswrapper的几个步骤:


1. 安装 ndiswrapper-dkms 2. 安装驱动到 /etc/ndiswrapper/*

ndiswrapper -i filename.inf

3. 列出所有的安装的驱动

ndiswrapper -l

4. 配置文件写到 /etc/modprobe.d/ndiswrapper.conf

ndiswrapper -m
depmod -a

现在基本上就要安装完ndiswrapper了; 依照 这里设置启动时加载这个模块。

modprobe ndiswrapper
iwconfig

如果正常的话, 你应该可以看到wlan0接口了. 如果有问题的话, 你可以阅读: Ndiswrapper installation wiki[失效链接 2020-08-04 ⓘ]. ndiswrapper howtondiswrapper FAQ.

backports-patched

backports-patchedAUR 为老内核提供了新内核中无线网卡驱动的移植,项目从 2007 年开始,以前名称是 compat-wireless, 现在重命名为 backports. 如果使用旧内核并且有无线问题,可以试试这个软件包。

参见

其他资源