在树莓派3B上安装完openwrt系统,其中网口和WIFI接口是需要配置后才能使用的。这里主要记录一下配置方法。
通过查看/proc/net/dev 目录下的文件,可以知道当前设备存在的接口分别为wlan0(WIFI),eth0(网口),br-lan接口。
root@OpenWrt:/# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 6528 96 0 0 0 0 0 0 6528 96 0 0 0 0 0 0
wlan0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
eth0: 8264 134 0 1 0 0 0 0 2366 17 0 0 0 0 0 0
br-lan: 4634 76 0 17 0 0 0 0 1714 11 0 0 0 0 0 0
记录一下初始的接口状态信息:
root@OpenWrt:/# ifconfig
br-lan Link encap:Ethernet HWaddr B8:27:EB:1F:83:06
inet addr:192.168.1.1 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fdc6:737:96d5::1/60 Scope:Global
inet6 addr: fe80::ba27:ebff:fe1f:8306/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:191 errors:0 dropped:53 overruns:0 frame:0
TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12302 (12.0 KiB) TX bytes:1714 (1.6 KiB)
eth0 Link encap:Ethernet HWaddr B8:27:EB:1F:83:06
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:249 errors:0 dropped:1 overruns:0 frame:0
TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15932 (15.5 KiB) TX bytes:2366 (2.3 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:160 errors:0 dropped:0 overruns:0 frame:0
TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10880 (10.6 KiB) TX bytes:10880 (10.6 KiB)
root@OpenWrt:/# ifconfig wlan0 up
[ 332.259732] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
此命令之后,可以通过ifconfig命令看到wlan0接口信息
root@OpenWrt:/# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr B8:27:EB:4A:D6:53
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
#打印当前wireless的相关配置信息
root@OpenWrt:/# uci show wireless
wireless.radio0=wifi-device
wireless.radio0.type='mac80211' #驱动类型为mac80211模式
wireless.radio0.channel='11' #wifi信道
wireless.radio0.hwmode='11g' #wifi协议为11g
wireless.radio0.path='platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
wireless.radio0.htmode='HT20' #20Mhz带宽
wireless.radio0.disabled='1' #从改配置,可以获取到当前wireless处于disable状态
wireless.default_radio0=wifi-iface
wireless.default_radio0.device='radio0'
wireless.default_radio0.network='lan'
wireless.default_radio0.mode='ap' #ap模式
wireless.default_radio0.ssid='OpenWrt' #wifi名称
wireless.default_radio0.encryption='none' #无加密,open模式
#通过UCI命令修改wireless的状态
root@OpenWrt:/# uci set wireless.radio0.disabled='0'
root@OpenWrt:/# uci commit wireless
#重启wifi系统
root@OpenWrt:/# wifi
root@OpenWrt:/# [ 583.957859] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[ 583.966292] br-lan: port 2(wlan0) entered blocking state
[ 583.972672] br-lan: port 2(wlan0) entered disabled state
[ 583.979136] device wlan0 entered promiscuous mode
[ 584.200549] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[ 584.208967] br-lan: port 2(wlan0) entered blocking state
[ 584.216103] br-lan: port 2(wlan0) entered forwarding state
root@OpenWrt:/# [ 594.331238] device wlan0 left promiscuous mode
[ 594.336691] br-lan: port 2(wlan0) entered disabled state
[ 595.544979] IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
[ 595.555528] br-lan: port 2(wlan0) entered blocking state
[ 595.562644] br-lan: port 2(wlan0) entered disabled state
[ 595.569929] device wlan0 entered promiscuous mode
[ 595.791790] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[ 595.800039] br-lan: port 2(wlan0) entered blocking state
[ 595.807038] br-lan: port 2(wlan0) entered forwarding state
#启动后可看到hostapd进程
root@OpenWrt:/# ps | grep hostapd
1195 root 1812 S /usr/sbin/hostapd -s -P /var/run/wifi-phy0.pid -B /v
1219 root 1200 R grep hostapd
同时,也可以扫描到名称为OpenWrt的WIFI网络。
3. 查看当前连接的用户信息
root@OpenWrt:/# iwinfo wlan0 assoclist
50:2B:73:CC:9E:CB -14 dBm / unknown (SNR -14) 2000 ms ago
RX: 72.2 MBit/s 5986 Pkts.
TX: 72.2 MBit/s 24722 Pkts.
expected throughput: unknown
通过ifconfig命令已经获取到当前br-lan口的IP地址为192.168.1.1。一般我们家中的网关地址也同样为192.168.1.1,这样的话,如果将树莓派直接和家里的路由器连接在一起,就会出现重复网关地址重复的情况,为了避免出现此情况,首先需要修改一下树莓派的br-lan地址配置。
uci set network.lan.ipaddr=192.168.10.1 # Program a static IP address
uci commit network
/etc/init.d/network restart
/etc/init.d/dnsmasq restart
连接WIFI,查看当前PC地址为192.168.10.163.
可以直接通过192.168.10.1 IP地址访问设备openwrt系统。
通过brctl命令可以看到,当前系统中,是将eth0和wlan0同时桥接到了br-lan上。此时,我的理解是将eth0作为了LAN口使用。
root@OpenWrt:/# brctl show
bridge name bridge id STP enabled interfaces
br-lan 7fff.b827eb1f8306 no eth0
wlan0
但是,我们如果想连接外网的话,这个时候就想着将eth0口作为WAN口使用。
接下来记录一下eth0接口类型修改的步骤: