Linux无线网卡配置

无线网卡的自动配置可以使用netcfg2软件,具体内容请参考ArchLinux Wiki Netcfg.

本文主要是针对手动配置,便于理解无线网卡的正常工作的过程。

操作环境: ArchLinux Linux myhost 2.6.36-ARCH 
硬件: USB 无线网卡 TL-WN821N
  1. 安装wireless_tools 和 madwifi
pacman -S wireless_tools madwifi
  1. 查看网卡状态
lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 002: ID 093a:2510 Pixart Imaging, Inc. Optical Mouse
Bus 001 Device 003: ID 0cf3:7015 Atheros Communications, Inc. 

在USB接口001/003上检测到网卡。

iwconfig

lo        no wireless extensions.

eth0      no wireless extensions.

wlan0     IEEE 802.11bgn  ESSID:off/any  
          Mode:Managed  Access Point: Not-Associated   Tx-Power=0 dBm   
          Retry  long limit:7   RTS thr:off   Fragment thr:off
          Encryption key:off
          Power Management:off

无线网卡为 wlan0

  1. 激活网卡
ifconfig wlan0 up
  1. 扫描WiFi
iwlist wlan0 scan

wlan0     Scan completed :
          Cell 01 - Address: 54:E6:FC:22:E1:D2
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=53/70  Signal level=-57 dBm  
                    Encryption key:on
                    ESSID:"TP-LINK_22E1D2"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=000000292a41bd80
                    Extra: Last beacon: 960ms ago
                    IE: Unknown: 000E54502D4C494E4B5F323245314432
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030101
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: WPA Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK

发现WPA2-PSK/WPA-PSK方式加密的AP: TP-LINK_22E1D2

因为加密方式为 WPA-PSK 所以得用 wpa_supplicant 而不能使用 iwconfig wlan0 key xxx 形式,iwconfig key方式适用于WEP。

  1. 配置 wpa_supplicant

新建文件 /etc/my_wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
network={
	ssid="TP-LINK_22E1D2"
	psk="密码"
}

其中network下的内容,可以使用wpa_passphrase AP_NAME PASSWORD生成。

  1. 连接wlan0到网络,并以后台方式运行
wpa_supplicant -B -i wlan0 -c /etc/my_wpa_supplicant.conf

#-B Background 在后台以daemon 运行
#-i interface 
#-c 配置文件
  1. 设置网络参数

手动设置

  • 设置ip地址
ifconfig wlan0 192.168.1.131

ifconfig #查看状态

wlan0     Link encap:Ethernet  HWaddr 54:E6:FC:03:0D:6B  
          inet addr:192.168.1.131  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:95 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:32434 (31.6 Kb)  TX bytes:576 (576.0 b)
  • 设置网关
route add default gw 192.168.1.1 dev wlan0

route #查看route状态

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 wlan0
default         192.168.1.1     0.0.0.0         UG    0      0        0 wlan0

通过udhcpc设置

kiilall udhcpc
udhcpc -i wlan0 -n
  1. 设置完毕

每次重新启动后需要重新设置,如果懒得每次设置的话,在本地/etc/rc.d/rc.local末尾加上

wpa_supplicant -B -i wlan0 -c /etc/my_wpa_supplicant.conf 
ifconfig wlan0 192.168.1.131
route add default gw 192.168.1.1 dev wlan0

或者

wpa_supplicant -B -i wlan0 -c /etc/my_wpa_supplicant.conf 
kiilall udhcpc
udhcpc -i wlan0 -n

可以使用wpa_cli指令管理wpa_supplicant进程,详细的使用方法,使用wpa_cli --help查看。
常用:

#关闭连接
wpa_cli terminate
#连接状态
wpa_cli status

你可能感兴趣的:(Linux)