openwrt下wifi设置详细过程

1.缺省情况下,openwrt中的无线是关闭的,系统起来后,ifconfig和ifconfig -a, iwconfig均看不到wlan0接口

原始的wireless配置文件如下:

root@OpenWrt:/# cat /etc/config/wireless 

config wifi-device  radio0

        option type     mac80211

        option channel  11

        option macaddr  00:90:4b:24:ff:2a

        option hwmode   11ng

        option htmode   HT20

        list ht_capab   SHORT-GI-40

        list ht_capab   DSSS_CCK-40

        # REMOVE THIS LINE TO ENABLE WIFI:

        option disabled 1

 

config wifi-iface

        option device   radio0

        option network  lan

        option mode     ap

        option ssid     OpenWrt

        option encryption none

 

root@OpenWrt:/# 

root@OpenWrt:/# cat /etc/config/network 

 

config 'interface' 'loopback'

        option 'ifname' 'lo'

        option 'proto' 'static'

        option 'ipaddr' '127.0.0.1'

        option 'netmask' '255.0.0.0'

 

config 'interface' 'lan'

        option 'ifname' 'eth0'

        option 'type' 'bridge'

        option 'proto' 'static'

        option 'ipaddr' '192.168.1.1'

        option 'netmask' '255.255.255.0'

 

config 'interface' 'wwan'

        option 'proto' 'dhcp'

 

root@OpenWrt:/# 

可以先删除以前的,再用wifi命令生成,如下:

rm -f /etc/config/wireless; wifi detect > /etc/config/wireless

 

mtg板子lan--连笔记本网口,Ip地址选dhcp模式,则笔记本会获得一个192.168.1.x的IP地址,

br-lan的ip地址为192.168.1.1,则在笔记本的地址栏输入192.168.1.1,打开板子的openwrt luci web 界面,network--->wifi,

如图一,点一下enable


串口打印如下:

root@OpenWrt:/# [   35.704581] ADDRCONF(NETDEV_UP): wlan0: link is not ready

[   35.732884] device wlan0 entered promiscuous mode

[   35.742912] br-lan: port 2(wlan0) entering forwarding state

[   35.748496] br-lan: port 2(wlan0) entering forwarding state

[   37.953439] device wlan0 left promiscuous mode

[   37.958101] br-lan: port 2(wlan0) entering forwarding state

[   38.122524] device wlan0 entered promiscuous mode

[   38.127514] br-lan: port 2(wlan0) entering forwarding state

[   38.133145] br-lan: port 2(wlan0) entering forwarding state

此时在用ifconfig和iwconfig查看均能看到wlan0接口

再查看wireless配置文件如下:

root@OpenWrt:/# cat /etc/config/wireless 

 

config 'wifi-device' 'radio0'

        option 'type' 'mac80211'

        option 'channel' '11'

        option 'macaddr' '00:90:4b:24:ff:2a'

        option 'hwmode' '11ng'

        option 'htmode' 'HT20'

        list 'ht_capab' 'SHORT-GI-40'

        list 'ht_capab' 'DSSS_CCK-40'

 

config 'wifi-iface'

        option 'device' 'radio0'

        option 'network' 'lan'

        option 'mode' 'ap'

        option 'ssid' 'OpenWrt'

        option 'encryption' 'none'

 

root@OpenWrt:/# 

可见前面的    # REMOVE THIS LINE TO ENABLE WIFI:

        option disabled 1

两行已经没有了

 

2. web上点一下wifi标签,则会回到图一的状态,点scan,则会扫描出很多AP,选择要用的AP,并将其的BSSID号复制下来,后面有用,

这里的BSSID号即为AP的MAC地址

选择要用的AP,点join network,会出现Join Network: Settings页面,如图二,



WPA passphrase: 此处输入AP访问密码,如Flexcomm_WIFI的密码为123456789a,TP-LINK_CPN/TP-LINK_CPN1的密码为12345678

name of the new network: 缺省为wwan

Create/Assign firewall-zone: 缺省为wan:wwan:(empty)

 

再点submit,则会显示wifi配置界面,和图一中直接选edit之后的界面一样,如图三,再将前面保存的BSSID粘贴到BSSID栏中,其他的参数都不要改


再点save&apply

此时串口打印如下:

root@OpenWrt:/# [   26.962420] br-lan: port 1(eth0) entering forwarding state

[   26.987437] device eth0 left promiscuous mode

[   26.991893] br-lan: port 1(eth0) entering disabled state

[   27.040168] eth0: link down

[   30.500184] ADDRCONF(NETDEV_UP): eth0: link is not ready

[   31.003220] ADDRCONF(NETDEV_UP): eth0: link is not ready

[   31.040777] eth0: link up, speed 100 Mb/s, full duplex

[   31.046025] ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

[   31.195658] device eth0 entered promiscuous mode

[   31.259063] br-lan: port 1(eth0) entering forwarding state

[   31.264621] br-lan: port 1(eth0) entering forwarding state

[   32.373424] ADDRCONF(NETDEV_UP): wlan0: link is not ready

[   35.279518] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

 

root@OpenWrt:/# 

查看配置文件为:

root@OpenWrt:/# cat /etc/config/wireless 

 

config 'wifi-device' 'radio0'

        option 'type' 'mac80211'

        option 'macaddr' '00:90:4b:24:ff:2a'

        option 'hwmode' '11ng'

        option 'htmode' 'HT20'

        list 'ht_capab' 'SHORT-GI-40'

        list 'ht_capab' 'DSSS_CCK-40'

        option 'disabled' '0'

        option 'channel' '6'

        option 'country' 'CO'

        option 'txpower' '17'

 

config 'wifi-iface'

        option 'ssid' 'Flexcomm_WIFI'

        option 'encryption' 'psk2'

        option 'device' 'radio0'

        option 'mode' 'sta'

        option 'network' 'wwan'

        option 'key' '123456789a'

        option 'bssid' '00:1C:F0:C3:84:AC '

 

root@OpenWrt:/# 

root@OpenWrt:/# ifconfig wlan0

wlan0     Link encap:Ethernet  HWaddr 00:90:4B:24:FF:2A  

          inet addr:192.168.5.182  Bcast:192.168.5.255  Mask:255.255.255.0

          inet6 addr: fe80::290:4bff:fe24:ff2a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:82 errors:0 dropped:0 overruns:0 frame:0

          TX packets:27 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:32 

          RX bytes:6239 (6.0 KiB)  TX bytes:3576 (3.4 KiB)

 

root@OpenWrt:/# iwconfig wlan0

wlan0     IEEE 802.11abgn  ESSID:"Flexcomm_WIFI"  

          Mode:Managed  Frequency:2.437 GHz  Access Point: 00:1C:F0:C3:84:AC   

          Bit Rate=135 Mb/s   Tx-Power=17 dBm   

          RTS thr:off   Fragment thr:off

          Encryption key:off

          Power Management:off

          Link Quality=53/70  Signal level=-57 dBm  

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:4   Missed beacon:0

 

root@OpenWrt:/# 

可见wlan0已经成功连上了AP,并自动获得了IP地址,AP为192.168.5.x网段的,并开了DHCP服务,所以wlan0能自动获得IP地址

 

root@OpenWrt:/# ping 192.168.5.1    //ping网关能通

PING 192.168.5.1 (192.168.5.1): 56 data bytes

64 bytes from 192.168.5.1: seq=0 ttl=64 time=4.500 ms

64 bytes from 192.168.5.1: seq=1 ttl=64 time=4.163 ms

^C

--- 192.168.5.1 ping statistics ---

2 packets transmitted, 2 packets received, 0% packet loss

round-trip min/avg/max = 4.163/4.331/4.500 ms

root@OpenWrt:/# ping www.baidu.com     //ping 外网能通

PING www.baidu.com (220.181.111.147): 56 data bytes

64 bytes from 220.181.111.147: seq=0 ttl=54 time=222.212 ms

64 bytes from 220.181.111.147: seq=1 ttl=54 time=290.069 ms

64 bytes from 220.181.111.147: seq=2 ttl=54 time=212.674 ms

^C

--- www.baidu.com ping statistics ---

3 packets transmitted, 3 packets received, 0% packet loss

round-trip min/avg/max = 212.674/241.651/290.069 ms

root@OpenWrt:/# 

root@OpenWrt:/# 

此时web页面wifi页状态显示连接,如图四:

 


说明:如果上面ping外网不通,可能是DNS没有设置

选一个可用的DNS,如8.8.8.8 为google的DNS服务器地址

可以在web页,DHCP and DNS页面中设置DNS forwardings: 8.8.8.8, save&apply

这样设置之后,就能ping通大网了

 

接mtgd的笔记本(网口接mtgd lan口)也可以直接上大网了。

 

 

3.直接在命令行下手动配置wifi如下:

可以先删除老的配置文件rm -rf /etc/config/wireless

新建一个配置文件 wifi detect > /etc/config/wireless

 

在上面生成的配置文件/etc/config/wireless基础上修改,改成如下:

 

主要设置'disabled','channel','network','mode','ssid','encryption' ,'key','bssid'

即主要设置option参数

设置之后保存退出,再运行wifi命令

root@OpenWrt:/# vi /etc/config/wireless 

 

 

config 'wifi-device' 'radio0'

        option 'type' 'mac80211'

        option 'macaddr' '00:90:4b:24:ff:2a'

        option 'hwmode' '11ng'

        option 'htmode' 'HT20'

        list 'ht_capab' 'SHORT-GI-40'

        list 'ht_capab' 'DSSS_CCK-40'

        option 'country' 'CN'   

        option 'disabled' '0'  

        option 'channel' '1' 

        option 'txpower' '17'

                             

config 'wifi-iface'             

        option 'device' 'radio0'

        option 'network' 'wwan'  --------这个地方一定不能为lan,否则连不通,可为wan,wwan等,wwan只是一个别名

        option 'mode' 'sta'        

        option 'ssid' 'TP-LINK_CPN'

        option 'encryption' 'psk2'        

        option 'key' '12345678'           

        option 'bssid' '5C:63:BF:FD:CF:FC'

~                                         

root@OpenWrt:/# wifi  //启动wifi,可见下面已经连接

[   61.914007] cfg80211: Calling CRDA for country: CN

[   62.058611] cfg80211: Regulatory domain changed to country: CN

[   62.064531] cfg80211:     (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)

[   62.072894] cfg80211:     (2402000 KHz - 2482000 KHz @ 40000 KHz), (N/A, 2000 mBm)

[   62.080467] cfg80211:     (5735000 KHz - 5835000 KHz @ 40000 KHz), (N/A, 3000 mBm)

[   63.112131] ADDRCONF(NETDEV_UP): wlan0: link is not ready

root@OpenWrt:/# [    0.464589] ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready

 

root@OpenWrt:/# iwconfig wlan0

wlan0     IEEE 802.11abgn  ESSID:"TP-LINK_CPN"  

          Mode:Managed  Frequency:2.412 GHz  Access Point: 5C:63:BF:FD:CF:FC   

          Bit Rate=180 Mb/s   Tx-Power=17 dBm   

          RTS thr:off   Fragment thr:off

          Encryption key:off

          Power Management:off

          Link Quality=70/70  Signal level=-29 dBm  

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:7   Missed beacon:0

 

root@OpenWrt:/# ifconfig wlan0

wlan0     Link encap:Ethernet  HWaddr 00:90:4B:24:FF:2A  

          inet addr:192.168.8.108  Bcast:192.168.8.255  Mask:255.255.255.0

          inet6 addr: fe80::290:4bff:fe24:ff2a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:66 errors:0 dropped:0 overruns:0 frame:0

          TX packets:39 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:32 

          RX bytes:14386 (14.0 KiB)  TX bytes:4828 (4.7 KiB)

 

root@OpenWrt:/# 

你可能感兴趣的:(Linux)