歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> BSD >> Freebsd中拿無線網卡當AP用

Freebsd中拿無線網卡當AP用

日期:2017/2/28 11:25:16   编辑:BSD


買來一塊108M的PCI無線網卡 型號為D-LINK DWLG520 , 是屬於被Freebsd6.0支持的無線網卡,使用的是Atheros 5212芯片,支持HOSTAP模式(能讓你的網卡作為AP使用的關鍵).
第一步,安裝無線網卡硬件, 系統中已原有一塊8139網卡
第二步,開機進入Freebsd 用Root登陸
#dmesg | more 沒有發現任何無線設備,這這時想起沒有把驅動編譯到內核中當然不會發現這個設備啦
於是執行(注:ath為被Freebsd定義的網卡驅動名字):
#kldload if_ath ;
if_ath_load="YES"
系統自動把另外兩個ath的.ko模塊也加載到內核中了
再執行ifconfig命令,發現多了一個ath0的設備
ath0: flags=8943 mtu 1500
ether 00:03:2f:12:34:56
於是運行
#ifconfig ath0 inet ssid 108m mode 11g mediaopt hostap up
ifconfig_ath0="inet ssid 108m mode 11g mediaopt hostap"
這樣就起用了網卡的ap模式
這時ifconfig ath0 看看
ath0: flags=8943 mtu 1500
ether 00:03:2f:12:34:56
media: IEEE 802.11 Wireless Ethernet autoselect mode 11g
status: associated
ssid 108m channel 1 bssid 00:03:2f:12:34:56
authmode OPEN privacy OFF txpowmax 36 protmode CTS dtimperiod 1
bintval 100
此時用一台筆記本電腦的無線網卡就能發現一個108M的無線網絡接入點了,但是只能還連接到AP自身而已,
如果筆記本電腦需要訪問有線以太網絡,還是把ath0 和另外的一塊8139網卡橋接起來方便
如何橋接??
Freebsd的網橋實現有兩種完全不同的方式
一種是傳統的實現 freebsd 很早的版本就有的.
#kldload bridge
#sysctl net.link.ether.bridge.enable=1
這時提示:
rl0: promiscuous mode enabled
ath0: promiscuous mode enabled
bridge_load="YES"
net.link.ether.bridge.enable=1
第二種網橋是Freebsd6.0 新從netbsd中引入的 if_bridge ;
Freebsd官方說以後的版本中要用if_bridge淘汰上面的bridge方式.
內核中要有
device if_bridge
device wlan
device ath
device ath_hal
device ath_rate_onoe
然後重新編譯,安裝內核 後reboot 系統中就多了一個ath0的設備
# dmesg | grep ath
ath_hal: 0.9.14.9 (AR5210, AR5211, AR5212, RF5111, RF5112, RF2413)
npx0: on motherboard
ath0: mem 0xec000000-0xec00ffff irq 11 at device 10.0 on pci1
ath0: Ethernet address: 00:03:2f:12:34:56
ath0: mac 5.6 phy 4.1 radio 1.7
然後開始使用橋
#ifconfig bridge0 create
#ifconfig bridge0
bridge0: flags=8041 mtu 1500
ether ac:de:48:0f:a6:16
priority 32768 hellotime 2 fwddelay 15 maxage 20
(注:刪除bridge0接口 用 #ifconfig bridge0 destroy)
然後加入網橋的成員
#ifconfig bridge0 addm rl0 addm ath0
(注:刪除網橋成員rl0用 #ifconfig bridge0 deletem rl0)
同樣提示:
rl0: promiscuous mode enabled
ath0: promiscuous mode enabled
#ifconfig bridge0 bridge0: flags=8041 mtu 1500 ether ac:de:48:0f:a6:16 priority 32768 hellotime 2 fwddelay 15 maxage 20 member: ath0 flags=3 member: rl0 flags=3
讓上面的設置開機自動生效
ifconfig_ath0="inet ssid 108m mode 11g mediaopt hostap" cloned_interfaces="bridge0" ifconfig_bridge0="addm rl0 addm ath0 "
注:本人現使用第二種方式
補充三點:
net.link.ether.inet.log_arp_movements=0
net.link.ether.inet.log_arp_wrong_iface=0
避免過多arp警告之類的信息出現在控制台
三、發現使用第二種網橋後,無線網卡客戶端無法PPPoE撥號,似乎pppoe數據包無法通過網橋,經實際測試,用第一種網橋方式,無線網卡客戶端可以pppoE撥號 (ADSL貓是通過Switch與BSD的rl0網卡連接的),根據需要自己選擇哪種方式吧!
至此大功告成!! 用你筆記本的無線網卡連接上盡情使用吧 :)
12月15日 重要更新(大大提高了AP的穩定性)
請把你的系統源代碼更新到最新6.0stable,我是更新到12月15日 ,因為 Freebsd的開發者sam對ath的流量算法sample進行了較大改進, 所以請把ath的控制部分,由onoe 改為sample方式
相關內核配置如下
device ath
device ath_hal
#device ath_rate_onoe
device ath_rate_sample
device wlan
#uname -a
至此, 消除了原來會出現在控制台的2個嚴重影響ap穩定性的下列錯誤
ath0: device timeout
ath0: stuck beacon; resetting (bmiss count 4)
Copyright © Linux教程網 All Rights Reserved