2018/03/18

樹莓派上的OpenWrt一瞥

摘要

本文概要記錄在樹莓派3代單板電腦上運行LEDE版的OpenWrt作業系統的注意事項。


本文

OpenWrt是適用於嵌入式系統的一個Linux發行版,其特點為高度模組化、並且擁有強大的網路零組件。
LEDE專案是OpenWrt專案的一個衍生專案,目標除了跟OpenWrt一樣建構一個注重功能的嵌入式Linux發行版之外,還希望解決原本欠缺穩定性和文件的缺點。
LEDE支援諸多平台,包含樹莓派單板電腦。
請參照這裡這裡下載、安裝、和設定樹莓派3代單板電腦;一個將樹莓派3代的WAN設定為透過DHCP索取位址並取得192.168.0.17的IP位址、對LAN設定為192.168.1.1的IP位址並以DHCP發放位址、以及對WLAN的SSID/passphrase設定為LEDE-Leo/12345678的安裝測試步驟的注意事項記錄如下。
1. 這裡是下載頁面,映像檔的鏈結為https://downloads.lede-project.org/releases/17.01.4/targets/brcm2708/bcm2710/lede-17.01.4-brcm2708-bcm2710-rpi-3-ext4-sdcard.img.gz
 2. 以Win32DisckImager將映像檔燒錄到SD卡。
3. 開機。
4. 調整組態設定檔/etc/config/network和/etc/config/wireless。設定結果如下。
root@LEDE:/# 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 globals 'globals'
        option ula_prefix 'fd8a:4ded:a5d4::/48'

config interface 'lan'
        option type 'bridge'
#       option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option proto 'dhcp'
        option ifname 'eth0'


root@LEDE:/#

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

config wifi-device 'radio0'
        option type 'mac80211'
        option channel '11'
        option hwmode '11g'
        option path 'platform/soc/3f300000.mmc/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
        option htmode 'HT20'
#       option disabled '1'
        option disabled '0'


config wifi-iface 'default_radio0'
        option device 'radio0'
        option network 'lan'
        option mode 'ap'
        option ssid 'LEDE-Leo'
        option encryption 'psk2'
        option key '12345678'


root@LEDE:/#

5. 觀察網路的狀態。結果如下。
root@LEDE:/# ifconfig
br-lan    Link encap:Ethernet  HWaddr B8:27:EB:34:18:7D
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe34:187d/64 Scope:Link
          inet6 addr: fd8a:4ded:a5d4::1/60 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:1722 (1.6 KiB)

eth0      Link encap:Ethernet  HWaddr B8:27:EB:61:4D:28
          inet addr:192.168.0.17  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fe61:4d28/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:22 errors:0 dropped:0 overruns:0 frame:0
          TX packets:29 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3017 (2.9 KiB)  TX bytes:3452 (3.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:28 errors:0 dropped:0 overruns:0 frame:0
          TX packets:28 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:2405 (2.3 KiB)  TX bytes:2405 (2.3 KiB)

wlan0     Link encap:Ethernet  HWaddr B8:27:EB:34:18:7D
          inet6 addr: fe80::ba27:ebff:fe34:187d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:2676 (2.6 KiB)

root@LEDE:/#


root@LEDE:/# route -e
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         192.168.0.1     0.0.0.0         UG        0 0          0 eth0
192.168.0.0     *               255.255.255.0   U         0 0          0 eth0
192.168.0.1     *               255.255.255.255 UH        0 0          0 eth0
192.168.1.0     *               255.255.255.0   U         0 0          0 br-lan
root@LEDE:/#


root@LEDE:/# cat /etc/config/dhcp

config dnsmasq
        option domainneeded '1'
        option boguspriv '1'
        option filterwin2k '0'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option nonegcache '0'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option localservice '1'

config dhcp 'lan'
        option interface 'lan'
        option start '100'
        option limit '150'
        option leasetime '12h'
        option dhcpv6 'server'
        option ra 'server'

config dhcp 'wan'
        option interface 'wan'
        option ignore '1'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'

root@LEDE:/#

root@LEDE:/# cat /tmp/resolv.conf.auto
# Interface wan
nameserver 192.168.0.1
search hitronhub.home
root@LEDE:/#

root@LEDE:/# cat /etc/resolv.conf
search lan
nameserver 127.0.0.1
root@LEDE:/#

6. 令一台具備2.4GHz Wi-Fi介面的行動裝置跟燒錄了LEDE映像檔的樹莓派3代連線。
6.1. 樹莓派3代的狀態如下。
一個範例如下。
root@LEDE:/# iw dev wlan0 station dump
Station f4:f5:db:da:d5:19 (on wlan0)
        inactive time:  2000 ms
        rx bytes:       48766
        rx packets:     307
        tx bytes:       184376
        tx packets:     328
        tx failed:      0
        signal:         -34 [-34] dBm
        tx bitrate:     65.0 MBit/s
        rx bitrate:     6.0 MBit/s
        authorized:     yes
        authenticated:  yes
        associated:     yes
        WMM/WME:        yes
        TDLS peer:      yes
        DTIM period:    2
        beacon interval:100
        short slot time:yes
        connected time: 81 seconds
root@LEDE:/#

root@LEDE:/# arp -a
IP address       HW type     Flags       HW address            Mask     Device
192.168.1.156    0x1         0x2         f4:f5:db:da:d5:19     *        br-lan
192.168.0.1      0x1         0x2         64:77:7d:45:50:d2     *        eth0
root@LEDE:/#

root@LEDE:/# ping 192.168.1.156 -c 1
PING 192.168.1.156 (192.168.1.156): 56 data bytes
64 bytes from 192.168.1.156: seq=0 ttl=64 time=217.132 ms

--- 192.168.1.156 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 217.132/217.132/217.132 ms
root@LEDE:/#

6.2. 行動裝置的狀態如下。


沒有留言:

張貼留言