歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> 無線網卡在Linux下活起來

無線網卡在Linux下活起來

日期:2017/2/27 11:21:04   编辑:關於Linux

出處:http://tech.ccidnet.com/pub/article/c302_a177259_p1.html

作者:孫學全
來源:賽迪網-開放系統世界

    為了體驗無線網絡的便捷性,筆者購買了一台筆記本電腦。不過由於其內置的PCI無線網卡在Linux下一直沒有驅動程序,所以形同虛設。

    一個偶然的機會,筆者在網上發現了NdisWrapper軟件項目(http: //ndiswrapper.sourceforge.net)。該項目並不編寫Linux驅動,而是通過一個內核模塊來調用Windows下的Ndis 驅動程序,從而巧妙地解決了這些無線網卡沒有Linux驅動的問題。該項目目前支持的無線網卡有Admtek 8211、Atheros AR5004、Broadcom 4301、Broadcom 4309、Broadcom 94306、InProcomm IPN2120和Intel PRO/Wireless Lan 2100。

    筆者的網卡為Intel PRO/Wireless Lan 2100,安裝的Linux發行版本是SuSE 9.0 Professional,內核版本是2.4.21-166,采用0.3版的NdisWrapper(該軟件目前的版本是0.4版,需要2.6或 2.4.23以上的內核支持)。該軟件雖然提供了非常詳盡的文檔,但因為考慮到安裝過程中存在的一些問題,所以在這裡給出完整的安裝說明。下述命令均以 root身份執行。

    1.到http://prdownloads.sourceforge.net/ndiswrapper/ ndiswrapper-0.3.tar.gz?download下載ndiswrapper-0.3.tar.gz文件。

    2.解壓縮該文件,此時會在當前目錄下生成ndiswrapper目錄。命令如下:
    # tar zxvf ndiswrapper-0.3.tar.gz

    3.進入ndiswrapper目錄,編輯driver/Makefile文件,加入如下語句:
    CFLAGS += $(shell [ -f /lib/modules/$(shell uname -r)/build/include/linux/modversions.h ] && echo -DEXPORT_SYMTAB -DMODVERSIONS -include /lib/modules/$(shell uname -r)/build/include/linux/modversions.h )

    如果不加入上述語句,在執行“depmod -a”命令時,會出現以下錯誤:
    depmod: *** Unresolved symbols in /lib/modules/2.4.21-166-default/misc/ndiswrapper.o

    4.使用“make”命令編譯ndiswrapper。

    5.到http://www.asus.com/pub/ASUS/nb/M2N/v12056logo_xp.zip下載Centrino無線網卡的Windows驅動程序,通過“unzip”命令解壓縮。

    6.創建/usr/local/share/ndiswrapper目錄,將.sys和.inf文件拷貝到新建目錄。命令如下:
    # mkdir /usr/local/share/ndiswrapper
    # cp w70n51.sys w70n51.inf /usr/local/share/ndiswrapper

    7.查找無線網卡的Vendor ID和Device ID,具體做法如下:
    (1)執行“lspci | grep 2100”命令,結果如下,其中02:02.0為無線網卡的PCI ID:
    02:02.0 Network controller: Intel Corp. PRO/Wireless LAN 2100 3B Mini PCI Adapter (rev 04)

    (2)根據PCI ID執行“lspci -n|grep 02:02.0”命令查找無線網卡的Vendor ID和Device ID,結果如下:
    02:02.0 Class 0280: 8086:1043 (rev 04)

    由上可知,無線網卡對應的Vendor ID為8086,Device ID為1043。

    8.使用“insmod driver/ndiswrapper.o”命令調用內核模塊。

    9.調用無線網卡的Windows驅動程序,命令如下:
    # utils/loaddriver

    上面代碼中, 為無線網卡的Vendor ID,為Device ID,為Windows驅動程序中sys文件的全路徑,為inf文件的全路徑。執行下面的命令,如果不出現錯誤,無線網卡的燈就已經亮起:
    #utils/loaddriver 8086 2043 /usr/local/share/ndiswrapper/w70n51.sys /usr/local/share/ndiswrapper/w70n51.inf

    10.設置無線網絡,具體步驟如下:
    (1)用“iwconfig”命令來顯示無線網卡(eth0、eth1或eth2)的信息。在以下的步驟中,用ethX表示無線網卡的名稱。
    (2)設置無線網卡的操作模式為Managed,命令如下:
    # iwconfig ethX mode Managed
    (3)如果采用了WEP加密,需要設置WEP密碼,命令如下:
    # iwconfig ethX key password
    對40位和128位加密,password分別為6位和10位的十六進制數字。
    (4)設置SSID,其中ESSID為Access Point的SSID。命令如下:
    # iwconfig ethX essid ESSID

    (5)創建/etc/sysconfig/network/ifcfg-ethX文件,使得機器每次啟動時,無線網卡都會自動獲得IP地址。該文件內容如下:

BOOTPROTO=‘dhcp’
MTU=‘’
REMOTE_IPADDR=‘’
STARTMODE=‘onboot’
UNIQUE=‘’

    11.通過下面的命令啟動無線網卡:
    #ifconfig ethX up

    12.最後將上述的配置自動化,使得開機自動啟動無線網卡。具體分為以下幾個步驟:
    (1)使用下面的命令將ndiswrapper.o文件拷貝到系統的內核模塊目錄下:
    # cp driver/ndiswrapper.*o /lib/modules/$(uname -r)/misc

    (2)使用“depmod -a”命令更新系統的模塊信息。

    (3)拷貝loaddriver文件到某個目錄(比如/usr/local/bin)下。命令如下:
    # cp utils/loaddriver /usr/local/bin

    (4)拷貝inf和sys文件到某個目錄(比如/usr/local/share/ndiswrapper)下。命令如下:    # cp bcmwl5.sys bcmwl5.inf /usr/local/share/ndiswrapper

    (5)使用下面的命令為無線網卡創建別名:
    #alias ethX=ndiswrapper

    (6)修改/etc/modprobe.conf文件,增加如下語句,在開機時自動調用NdisWrapper:
    post-install ethX /usr/local/bin/loaddriver 8086 1043 /usr/local/share/ndiswrapper/*.sys /usr/local/share/ndiswrapper/*.inf

    至此,整個設置完成。以後每次進入Linux時,無線網卡就會被激活,並自動獲得IP地址。這樣就可以在Linux下使用無線網卡的Windows驅動自由地使用Centrino筆記本的無線網絡了。




Copyright © Linux教程網 All Rights Reserved