无线网络(Wifi)

From Gentoo Wiki
Jump to: navigation, search
This page is a translated version of the page Wifi and the translation is 100% complete.

Other languages:
English • ‎español • ‎日本語 • ‎한국어 • ‎русский • ‎中文(中国大陆)‎
Resources

在这篇文章里我们将描述一下wifi无线网卡的设置

安装系统时的WiFi设置

如果在安装Gentoo过程中需要设置WiFi连接,需要提醒一下的是Gentoo最小安装光盘只支持一部分的无线网卡驱动,并且只提供wpa_cli命令(不提供wpa_gui)来设置WPA/WPA2/Enterprise等无线连接。

如果Gentoo最小安装光盘没有包含您需要设置的网卡驱动或者您需要wpa_supplicant的图形界面来设置,可以选择其他的live CD,例如System Rescue CD。需要提醒一下的是当使用non-Gentoo live CD的时候可能需要这些特殊步骤

硬件检测

首先检测wifi驱动。lspci 或者 lsusb这两个命令能查看到相应的wifi驱动。

如果是你的wifi能够在Linux LiveCD或者USB连接成功:

root #lspci -k

则你的驱动能在相应的以Kernel driver in use:开头的输出信息中找到。

如果你不能在启动盘中连接wifi,则需要保存当前系统所有的硬件信息列表。该列表能让你后面找到相对应的硬件驱动:

root #lspci -n

复制以上命令输出的对应的PCIID部分,然后把它粘贴到http://kmuto.jp/debian/hcl/。

对于USB网卡来说,过程也是大致相同的。首先拿到系统中所有的USB设备信息:

user $lsusb

这个命令会生成对应的PCI ID,生产商(manufacturer),make,模型(model),还有USB设备对应的系统的芯片组(chipset)。在所有的信息中,可能芯片组(chipset)是最有用的信息。Google搜索一下"linuxwireless.org <对应的chipset>" 通常是最找到对应的USB NIC驱动和固件(firmware)名字的最快方式。

另外,lshw也能用于获取相应的信息:

root #lshw | grep -i driver

这个命令会生成所有驱动信息的列表,无论是PCI网卡还是USB网卡。

内核

鉴于驱动程序,现在是配置Linux内核的时候了。

IEEE 802.11

Activate at least cfg80211 and mac80211. Some wireless drivers also require a rate control algorithm.

KERNEL linux-4.1
[*] Networking support  --->
    [*] Wireless  --->
        <*>   cfg80211 - wireless configuration API
        [ ]     nl80211 testmode command
        [ ]     enable developer warnings
        [ ]     cfg80211 regulatory debugging
        [ ]     cfg80211 certification onus
        [*]     enable powersave by default
        [ ]     cfg80211 DebugFS entries
        [ ]     use statically compiled regulatory rules database
        [ ]     cfg80211 wireless extensions compatibility
        <*>   Generic IEEE 802.11 Networking Stack (mac80211)
        [*]   Minstrel
        [*]     Minstrel 802.11n support
        [ ]       Minstrel 802.11ac support
              Default rate control algorithm (Minstrel)  --->
        [ ]   Enable mac80211 mesh networking (pre-802.11s) support
        -*-   Enable LED triggers
        [ ]   Export mac80211 internals in DebugFS
        [ ]   Trace all mac80211 debug messages
        [ ]   Select mac80211 debugging features  ----

Minstrel and its 802.11n support is a rate control algorithm.

WEXT

The "cfg80211 wireless extensions compatibility" option aka WEXT will support old wireless-tools and iwconfig.

KERNEL
[*] Networking support  --->
    [*] Wireless  --->
        [*]     cfg80211 wireless extensions compatibility

设备驱动程序

接下来,需要根据先前检测到的驱动程序和硬件启用相应内核选项的正确集合。 The recommendation is to build drivers as modules. 如果无线网络使用WPA或WPA2加密,还要确保在内核中启用AES密码支持。

KERNEL
    Device Drivers  --->
    [*] Network device support  --->
        [*] Wireless LAN  --->
 
            Select the driver for your Wifi network device, e.g.:
            <M> Broadcom 43xx wireless support (mac80211 stack) (b43)
            [M]    Support for 802.11n (N-PHY) devices
            [M]    Support for low-power (LP-PHY) devices
            [M]    Support for HT-PHY (high throughput) devices
            <M> Intel Wireless WiFi Next Gen AGN - Wireless-N/Advanced-N/Ultimate-N (iwlwifi)
            <M>    Intel Wireless WiFi DVM Firmware support                             
            <M>    Intel Wireless WiFi MVM Firmware support
            <M> Intel Wireless WiFi 4965AGN (iwl4965)
            <M> Intel PRO/Wireless 3945ABG/BG Network Connection (iwl3945)
            <M> Ralink driver support  --->
                <M>   Ralink rt27xx/rt28xx/rt30xx (USB) support (rt2800usb)
 
-*- Cryptographic API --->
    -*- AES cipher algorithms
    -*- AES cipher algorithms (x86_64)
    <*> AES cipher algorithms (AES-NI)
Important
In case the driver is built into the kernel (<*>) instead of as a module (<M>), then the firmware needs to be built into the kernel as well.
Do not forget to rebuild the kernel after changing its configuration.

LED支持

要启用不同数据包接收/发送事件的LED触发器,请使用以下选项编译内核:

KERNEL
Device Drivers  --->
    [*] LED Support  --->
        <*>   LED Class Support
 
[*] Networking support  --->
    [*] Wireless  --->
        [*] Enable LED triggers

硬件

除了内核驱动程序,一些芯片组还需要固件。如果需要,请在以下列表中找到它并安装它:

root #emerge --ask sys-kernel/linux-firmware
Wifi device Driver Firmware Note
Atheros AR9271 & AR7010 ath9k_htc sys-kernel/linux-firmware
Broadcom 43xx wireless support b43 / b43legacy sys-firmware/b43-firmware Aircrack-ng ready, most probably the best choice if your bcm43xx device is supported
Broadcom PCIe and SDIO/USB devices brcmsmac / brcmfmac sys-kernel/linux-firmware Lacks powersaving, LED support and other features
Broadcom 43xx wireless support wl net-wireless/broadcom-sta Proprietary, no AP or Monitor modes, Comparison of bcm43xx drivers
Intel PRO/Wireless 2200BG ipw2200 sys-firmware/ipw2200-firmware
Intel PRO/Wireless 3945ABG/BG iwlegacy sys-kernel/linux-firmware
Intel Wireless WiFi 4965AGN iwl4965 sys-kernel/linux-firmware
All other Intel Wireless devices iwlwifi sys-kernel/linux-firmware See the iwlwifi article for detailed instructions.
Qualcomm Atheros QCA6174 ath10k_pci ath10k-firmware See Qualcomm_Atheros_QCA6174#Firmware
Ralink/MediaTek USB devices e.g. rt2800usb sys-kernel/linux-firmware
Realtek RTL8191SE & RTL8192SE rtl8192se sys-kernel/linux-firmware
Realtek 8723AU/8723BU/8191EU/8192EU/8188EU/8188RU rtl8xxxu sys-kernel/linux-firmware May need the CONFIG_RTL8XXXU_UNTESTED kernel option to find all devices. Only those verified by kernel developers are enabled by default.

如果驱动所需固件没有在列表中,那么需要您手动去下载并把它放在/lib/firmware下。

网络设备名称

Network device names eth0, wlan0, etc. as provided by the kernel could be changed on boot (see dmesg) by the /lib/udev/rules.d/80-net-name-slot.rules udev rule.

To keep the classic naming this rule can be overwritten with an equally named empty file in the /etc/udev/rules.d directory:

root #touch /etc/udev/rules.d/80-net-name-slot.rules

WPA supplicant

如果用WPA或WPA2设置无线网络设, then wpa_supplicant needs to be used. For more information on configuring wireless networking in Gentoo Linux, please read the Wireless networking chapter in the Gentoo Handbook.


测试

After a reboot with the new kernel or after loading the modules, the device can be checked for availability by using following methods:

/sys 文件系统

通过使用 ls -altree 命令(由app-text/tree 包提供))列出 /sys/class/net 目录内容来获取设备名称:

user $tree /sys/class/net
/sys/class/net/
├── enp2s14 -> ../../devices/pci0000:00/0000:00:1e.0/0000:02:0e.0/net/enp2s14
├── lo -> ../../devices/virtual/net/lo
├── sit0 -> ../../devices/virtual/net/sit0
└── wlp8s0 -> ../../devices/pci0000:00/0000:00:1c.0/0000:08:00.0/net/wlp8s0

ip命令

To obtain the device name and verify that the wireless card is detected, execute the following ip command:

user $ip addr
3: wlan0:   ...

ifconfig 命令

ifconfig 命令是 sys-apps/net-tools 包提供的。使用 ifconfig -a列出所有检测到的网卡,即使那些尚未启用/尚未活动的网卡:

user $ifconfig -a
wlan0     ...

网卡可以用下面的方法激活:

root #ifconfig -v wlan0 up
SIOCSIFFLAGS: Operation not possible due to RF-kill
WARNING: at least one error occurred. (-1)

In this example, enabling the wireless card failed as a radio frequency kill state is set (usually to keep power consumption at bay and not connect by accident to a wireless network).

iw命令

If the wireless network card driver supports the nl80211 stack, then the iw command as offered by the net-wireless/iw package can show the detected wireless cards:

root #iw dev
   phy#0
	Interface wlan0
		ifindex 4
		type managed

dmesg

检查 dmesg 的输出。

user $dmesg | grep -i -E 'xx:xx.x|wlan|iwl|80211'

Be sure to replace


故障排除

另请参阅

外部资源