您的位置:首页 > 运维架构 > Linux

linux无线网卡配置2

2013-10-14 11:18 423 查看
为什么linux下无线不可用?

今天, 突然想用无线上网, 正要用iwconfig配置无线设置, 发现系统里根本就没有对应的
无线接口, 但在windows系统下, 无线却用得很是正常.

[scr wifi]$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 00:24:54:9d:4e:e0 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.139/24 brd 192.168.1.255 scope global eth0
inet 10.3.1.4/24 brd 10.3.1.255 scope global eth0:0
3: sit0: <NOARP> mtu 1480 qdisc noop state DOWN
link/sit 0.0.0.0 brd 0.0.0.0

从"ip a"的输出来看, 并没有类似于wlan0的接口, 第一感觉应该是没有安装相应驱动.

验证一下:

[root ~]# iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
sit0 no wireless extensions.

确实, 这三接口都不支持无线, 这是对的.

[scr wifi]$ dmesg | grep wlan
[scr wifi]$ lspci -vnn
... ...
03:00.0 Network controller [0280]: Broadcom Corporation BCM4313 802.11b/g LP-PHY [14e4:4727] (rev 01)
Subsystem: Askey Computer Corp. Device [144f:7179]
Flags: bus master, fast devsel, latency 0, IRQ 16
07:00.0 Ethernet controller [0200]: Marvell Technology Group Ltd. 88E8059 PCI-E Gigabit Ethernet Controller [11ab:4381] (rev 11)
Subsystem: Samsung Electronics Co Ltd Device [144d:c551]
Flags: bus master, fast devsel, latency 0, IRQ 45
Memory at fc800000 (64-bit, non-prefetchable) [size=16K]
I/O ports at 5000 [size=256]
[virtual] Expansion ROM at fc400000 [disabled] [size=128K]
Capabilities: <access denied>
Kernel driver in use: sky2
Kernel modules: sky2
... ...

从"lspci -vnn"的输出, 终于可以确定是没有安装无线驱动, 因为"Broadcom
Corporation BCM4313 802.11b/g LP-PHY" 没有对应的"kernel driver"等. 好吧, 下面
我们把驱动安装上!

"Ethernet controller"是以态网, 就是有有线网络.

2. Broadcom Corporation BCM4313 802.11b/g LP-PHY 对应的驱动是什么? 在那下载?

Broadcom Corporation BCM4313 802.11b/g LP-PHY 对应的驱动是什么? 这我也不知道,
不过这好办, google一下就ok了. 最终找到了一个非常靠普的:
http://www.broadcom.com/support/802.11/linux_sta.php , 该网页上有两个驱动包, 一
个是32位的, 另一个是64位; 但这一驱动合适我的机子吗? "README"文件
(http://www.broadcom.com/docs/linux_sta/README.txt)就是回答这一问题的根据了.

根据README, 先检查一下, 我机子上的无线网卡是否被这一驱动包支持:

[scr wifi]$ pwd
// To find the Device ID's of Broadcom cards on your machines do:
[scr wifi]$ lspci -n | grep 14e4
03:00.0 0280: 14e4:4727 (rev 01)

对比了一下, 4727确实是支持的, 下面的工作就是把驱动包下载下来, 然后按README一步
一步进行就OK了. 不过对于fedora没这个必要, 因为在已提供了对应的yum源.

3. 安装驱动(fedora版)

[root wifi]$ pwd
// 安装相应的yum源
[root wifi]$ rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpmhttp://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
// 安装驱动
[root wifi]$ yum -y install kmod-wl

完成后, 我们再验证一下是否已成功安装:

[scr wifi]$ iwconfig
lo no wireless extensions.
eth0 no wireless extensions.
eth1 IEEE 802.11 Nickname:""
Access Point: Not-Associated
Link Quality:2 Signal level:183 Noise level:162
Rx invalid nwid:0 invalid crypt:0 invalid misc:0
sit0 no wireless extensions.

多了一下"eth1", 是"IEEE 802.11"的, 说明安装已成功. 这命名比较奇怪, linux下无线
接口不应该是"wlanX"吗...

再验证一下:
[scr wifi]$ lspci -vnn
... ...
03:00.0 Network controller [0280]: Broadcom Corporation BCM4313 802.11b/g LP-PHY [14e4:4727] (rev 01)
Subsystem: Askey Computer Corp. Device [144f:7179]
Flags: bus master, fast devsel, latency 0, IRQ 16
Memory at fc700000 (64-bit, non-prefetchable) [size=16K]
Capabilities: <access denied>
Kernel driver in use: wl
Kernel modules: wl
07:00.0 Ethernet controller [0200]: Marvell Technology Group Ltd. 88E8059 PCI-E Gigabit Ethernet Controller [11ab:4381] (rev 11)
Subsystem: Samsung Electronics Co Ltd Device [144d:c551]
Flags: bus master, fast devsel, latency 0, IRQ 45
Memory at fc800000 (64-bit, non-prefetchable) [size=16K]
I/O ports at 5000 [size=256]
[virtual] Expansion ROM at fc400000 [disabled] [size=128K]
Capabilities: <access denied>
Kernel driver in use: sky2
Kernel modules: sky2
... ...

可以看到, 对应的驱动(wl)已经安装上了.

4. 配置无线网络

4.1 用 iwconfig 和 iwlist

先扫一下, 看看都有什么AP可用:
[root ~]# iwlist eth1 scanning
eth1 Scan completed :
Cell 01 - Address: 5C:63:BF:40:6B:1E
ESSID:"hellome"
Mode:Managed
Frequency:2.437 GHz (Channel 6)
Quality:2/5 Signal level:-71 dBm Noise level:-95 dBm
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
Encryption key:on
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; 24 Mb/s; 36 Mb/s
48 Mb/s; 54 Mb/s

有一个, ESSID是"hellome", 正是我自己的路由器, 对应密码是"7878787878", PSK加密.

设置要连接到的AP, 和密码:
[root ~]# iwconfig eth1 essid 'hellome'
[root ~]# iwconfig eth1 key 7878787878
Errorforwirelessrequest "[b]SetEncode[/b]" (8B2A) :
SET failed on device eth1 ; Invalid argument.

设置essid没任何问题, 但设置key却不行! google一下, 有网友说是 iwconfig 工具不支
持PSK加密方式, 无奈只能用别的了.

4.2 用 wpa_supplicant

wpa_supplicant是一个用于管理无线网络的工具包, 很是好用, 它可以通过命令行的方式
来设置, 也可以通过读取配置文件的方式.

先新建或修改一下配置文件:

[root ~]# vi /etc/wpa_supplicant/wpa_supplicant.conf
# 可有可无, 没有的话无法用wpa_cli terminate来关闭wpa_supplicant
ctrl_interface=/var/run/wpa_supplicant
# 确保只有root用户能读取WPA的配置, 可有可无, 尤其是在嵌入式设备上
ctrl_interface_group=0
# 使用wpa_supplicant来扫描和选择AP, 也可以设置成0或2, 但只有1才能正确工作
ap_scan=1
network={
ssid="hellome" # AP的名字
psk="7878787878" # AP的key
}

设置IP并运行wpa_supplicant:

[root ~]# pwd
// 起用eth1
[root ~]# ifconfig eth1 up
// 设置ip地址
[root ~]# ifconfig eth1 192.168.1.156
// ## 运行 wpa_supplicant :
// # // -B 代表后台运行
// # // -Dwext 代表网卡芯片是wext
// # // -ieth1 代表使用设备eth1
// # // -c 指定配置文件
[root ~]# wpa_supplicant -B -Dwext -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf

当网络改变时,重新配置/etc/wpa_supplicant/wpa_supplicant.conf,先killall [b]wpa_supplicant[/b]
[b]再[/b]
[b][b][b][root ~]# ifconfig eth1 up
// 设置ip地址
[root ~]# ifconfig eth1 192.168.2.156[/b][/b][/b]
[b][b]wpa_supplicant -B -Dwext -ieth1 -c/etc/wpa_supplicant/wpa_supplicant.conf。[/b][/b]
测试一下, 网络是否已连通(192.168.1.1是我的路由器的ip):

[root ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_req=1 ttl=64 time=1.74 ms
64 bytes from 192.168.1.1: icmp_req=2 ttl=64 time=1.58 ms
64 bytes from 192.168.1.1: icmp_req=3 ttl=64 time=1.98 ms
^C

OK! 没问题, 能连上路由器了, 现试一下biadu:

[root ~]# ping www.baidu.com
ping: unknown host www.baidu.com

居然不通! 有可能是没路由或没DNS服务:

[root ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
172.16.198.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1
172.16.77.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet8

嗯! 真的是路由问题, 默认路由没有. 增加默认路由:

[root ~]# route add default gw 192.168.1.1
[root ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
172.16.198.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1
172.16.77.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet8
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth1

再试:

[root ~]# ping www.baidu.com
PING www.a.shifen.com(220.181.111.147) 56(84) bytes of data.
64 bytes from 220.181.111.147: icmp_req=1 ttl=51 time=106 ms
64 bytes from 220.181.111.147: icmp_req=2 ttl=51 time=104 ms
^C

OK!

可以把以上命令写到 /etc/rc.d/rc.local 文件下, 这样开机无线就自动配置好了.

5. reference

Broadcom Corporation 802.11 Linux STA driver
http://www.broadcom.com/support/802.11/linux_sta.php
http://www.broadcom.com/docs/linux_sta/README.txt

Linux WPA/WPA2/IEEE 802.1X Supplicant
http://hostap.epitest.fi/wpa_supplicant/

Example wpa_supplicant configuration file
http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap.git;a=blob_plain;f=wpa_supplicant/wpa_supplicant.conf

wpa_supplicant使用笔记
http://hi.baidu.com/aberlee/blog/item/acb0a3d3ca0f64d9a9ec9af0.html/cmtid/76f0f80165cf8e081c958324
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: