hostapd實現WIFI 熱點(AP)

在UBUNTU系統或者其他類似linux系統上,使用hostapd,可以實現WIFI的無線接入熱點(AP)
以便提供給其他需要無線接入聯網的設備,如筆記本,手機實現無線上網功能。也即是無線路由的功能。
什麼是hostapd
hostapd 是用戶控件的守護進程用於無線接入點(AP)和授權服務器(authentication servers).
她實現了IEEE802.11的AP管理,IEEE802.1X/WPA/WPA2/EAP授權,RADIUS 客戶端,EAP服務器和RADIUS 授權服務器,目前最新版本支持Linux系統(HOST AP,madwifi,mac80211-based驅動)和FreeBSD(net80211)。
hostapd設計爲一個守護程序(進程),後臺運行,進行一些相關控制授權的操作。屬於一個開源項目。
相關鏈接:
http://w1.fi/hostapd/
http://linuxwireless.org/en/users/Documentation/hostapd

查看自己的無線網卡信息:

  1. wsn@wsn-laptop:~$ hwinfo --netcard  
  2. ...  
  3. 28: PCI e00.0: 0282 WLAN controller  
  4.   [Created at pci.318]  
  5.   UDI: /org/freedesktop/Hal/devices/pci_14e4_4315  
  6.   Unique ID: y9sn.reAAs+k0MA5  
  7.   Parent ID: hoOk.F8Gordq8HH2  
  8.   SysFS ID: /devices/pci0000:00/0000:00:1c.2/0000:0e:00.0  
  9.   SysFS BusID: 0000:0e:00.0  
  10.   Hardware Class: network  
  11.   Model: "Dell Wireless 1397 WLAN Mini-Card"  
  12.   Vendor: pci 0x14e4 "Broadcom"  
  13.   Device: pci 0x4315 "BCM4312 802.11b/g"  
  14.   SubVendor: pci 0x1028 "Dell"  
  15.   SubDevice: pci 0x000c "Wireless 1397 WLAN Mini-Card"  
  16.   Revision: 0x01  
  17.   Driver: "b43-pci-bridge"  
  18.   Driver Modules: "ssb"  
  19.   Device File: wlan0  
  20.   Features: WLAN  
  21.   Memory Range: 0xf3000000-0xf3003fff (rw,non-prefetchable)  
  22.   IRQ: 18 (557260 events)  
  23.   HW Address: 00:22:5f:85:e7:a7  
  24.   Link detected: yes  
  25.   WLAN channels: 1 2 3 4 5 6 7 8 9 10 11 12 13 14  
  26.   WLAN frequencies: 2.412 2.417 2.422 2.427 2.432 2.437 2.442 2.447 2.452 2.457 2.462 2.467 2.472 2.484  
  27.   WLAN encryption modes: WEP40 WEP104 TKIP CCMP  
  28.   WLAN authentication modes: open sharedkey wpa-psk wpa-eap  
  29.   Module Alias: "pci:v000014E4d00004315sv00001028sd0000000Cbc02sc80i00"  
  30.   Driver Info #0:  
  31.     Driver Status: ssb is active  
  32.     Driver Activation Cmd: "modprobe ssb"  
  33.   Config Status: cfg=new, avail=yes, need=no, active=unknown  
  34.   Attached to: #16 (PCI bridge)  

Ubuntu下,如何獲取hostapd?

1. 終端輸入命
  1. sudo apt-get install hostapd  
2. 最新版本可以通過git命令
  1. sudo apt-get install git-core  
  2. git clone git://w1.fi/srv/git/hostap.git  
3. 選擇自己所需版本
  1. http://w1.fi/hostapd/  

如何使用hostapd

將獲取到的包解壓,進入hostapd.
  1. tar xzvf hostapd-x.y.z.tar.gz  
  2. cd hostapd-x.y.z/hostapd  
複製一份默認的配置文件
  1. cp defconfig .config  
編輯.config文件,找到
#CONFIG_DRIVER_NL80211=y
修改爲
CONFIG——DIRVIERNL80211
最後編譯:
sudo make
如果編譯報錯,原因多是libnl庫出錯,通過安裝或升級libnl庫即可
該庫主要提供基於LINUX內核的netlink protocol相關APs函數。
這裏下載獲取,要求版本0.8以上
  1. http://www.infradead.org/~tgr/libnl/  
如果還出錯,那麼需要安裝libssl-dev:
該庫提供ssl開發庫
  1. sudo apt-get install libssl-dev  
編譯好後,得到hostapd執行文件
如何使用hostapd?
hostapd的功能,也就是筆記本通過有線網口介入,hostapd利用筆記本的無線網卡,實現無線路由。
編輯hostapd.conf文件
可以根據自己的網卡,參照這裏
  1. http://linuxwireless.org/en/users/Documentation/hostap  
一個簡單的配置文件:
  1. interface=wlan0  
  2. bridge=br0  
  3. driver=nl80211  
  4. ssid=ssa  
  5. hw_mode=g  
  6. channel=11  
  7. dtim_period=1  
  8. rts_threshold=2347  
  9. fragm_threshold=2346  
  10. auth_algs=3  
  11. wpa=1  
  12. wpa_passphrase=12345678  
  13. wpa_key_mgmt=WPA-PSK  
  14. wpa_pairwise=TKIP CCMP  
  15. rsn_pairwise=CCMP  
搭建網橋:
  1. sudo apt-get install bridge-utils  
建立網橋:
  1. sudo brctl adbr br0  
  2. sudo ifconfig br0 192.168.2.236 netmask 255.255.255.0  
  3. sudo route add default gw 192.168.2.254  
連接網橋兩端:
  1. sudo brctl addif br0 eth0  
  2. sudo brctl addif br0 wlan0  
最後:
  1. sudo ./hostapd hostapd.conf  
如果一切順利,將在終端看到一下類似字樣:
  1. root@wsn-laptop:/home/wsn/Desktop/hostapd-0.7.3/hostapd# ./hostapd hostapd.conf   
  2. Configuration file: hostapd.conf  
  3. Using interface wlan0 with hwaddr 00:22:5f:85:e7:a7 and ssid 'ubuntu-502d'  
android手機打開wifi並且設置靜態ip
如ip:192.168.3.75 
掩碼: 255.255.255.0  
網管: 192.168.3.1

即可以連接到名爲ubuntu-502的無線熱點了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章