OpenWrt 的世界︰樹莓派 □○

甲骨文網

金文大篆

甘蔗

漁網

就讓我們從寶島的『甘蔗』說起,蔗的造字有著入土中汲取水源,彷彿乙太網路卡連上 Internet 的纜線插頭節節的運送水分轉化成糖,就好比網絡通訊堆疊層層封裝內容,它的 API 方便其它軟體應用一般;最後綠葉茂密能行光合作用;正像是網頁瀏覽器、臉書、谷歌 …… 的應用方興未艾。這枝『甘蔗』的就是 TCP Transmission Control Protocol 通訊控制規範,想確保通訊內容無誤依序抵達以及提供寫應用軟體的人方便的軟體界面。假如談到即時應用,比如網路影音或網路電話等等,常常會使用另一個稱作 UDP connectionless User Datagram Protocol 的協議,它只盡力傳送資訊,不能確保抵達,也不能保證有序的收到,把這一切都交給應用軟體自理。這樣的 UDP 有用嗎??

甘蔗的根汲取水源,那水是從哪裡來的呢?甘蔗並不管水是來自地下水源網絡或是人工的溝渠灌溉。這就是 IP Internet Protocol 網際網路規範作的事,向上提供 TCP 和 UDP 的資訊連線,向下隱藏不同網路硬體設備間的差異,讓大家都說同一國語言,定址每一個連接裝置以及分封轉送任意內容到任何連上際網網路的東西上!那什麼是分封轉送呢?首先這就得從大數學家歐拉 Euler  柯尼斯堡的『七橋問題』講起了!你能不過任何一座橋兩次一筆走完這七座橋嗎?

220px-Konigsberg_bridges

179px-7_bridges.svg

180px-Konigsburg_graph.svg

把『』字抽象化網路的概念就在『接點』與『路徑』。接點連接路徑,路徑通往其它接點。這個『接點』在網際網路上就是稱作『路由器』router 的設備,提供連上的接點暢通的路徑,能夠抵達 IP 所定址的任何公眾的網際網路地址 ── Public/Real IP ,比如說路邊一棟大樓的地址 ──,而在你使用的私人網域裡,有一種路由器它可以多人分享一個真實的 IP 地址 ── 這是因為連接設備提供了 Virtual 虛擬  IP ,就像在郵政地址上寫的某一棟樓的幾樓那室一樣 ──,事實上只用了一個連上網際網路的公眾地址, 一個由 ISP 網際網路服務供應商所提供的地址。這裡所說的這個連接設備也就是能自己知道幾樓那室 ── NAT Network address translation ──去轉送真實IP 的網路地址轉換Router

那『分封』Packet 又是什麼呢?如果你比較連接兩地鐵路公路的差異,最主要的就是一時之間,只能有一輛火車行經某一段鐵軌,這時其他火車都得等它先過;而公路上確能有多種汽車同時通行各個路段。假如連接某兩個接點的網際網路的路徑只有一條,那該是用火車的辦法,一個人通訊結束,另一個人才能開始用?當然不是,它用著汽車的方式,把每個人的通訊分成一小包 packet 一小包的傳送,這樣的分時分享方法就叫做分封。由於用著分封的方式,連接任兩個接點的網際網路的路徑可能有多條後發的小包可能先至也就不一定,這就是 TCP 和 UDP 的主要差異之一。再者每一小包上有一個稱作存活時間 TTL 的控制機制,每經過一個接點路由器它的數值就會被減一,這是為著不讓抵達不了── 比如斷了路徑的接點;公路上拋錨的車該將它拖走 ── 的分封小包,持續在網路上傳送浪費頻寬,所以當 TTL 歸零時路由器就會將小包丟棄;TCP 會試著維持已建立的連線,而 UDP 沒有連線機制故不會。當然我們此時也就能設想,如果一個網址同時很多人去拜訪,那就會『塞車』,如果這時有更多人想連上,它可能就會 DOS Denial Of Service 終止服務了。

前面說道,這樣的 UDP 有用嗎??比方說電視廣播吧,它只管廣播,並不理會用戶有沒有收到,也不檢查錯誤再次傳送;這是因為影音按著時間播放,時間已過去了的,沒有道理再次傳送。然而即使人想那樣作,那又要怎麼觀賞節目呢?所以說 UDP 有什麼用呢?就看自己如何想?又要怎麼用了?

─── 《網路道荼、蓼

 

想要深化『網際網路』之認識,那就實作一個『路由器』吧☆

雖然 OpenWrt/LEDE 發行了支援樹莓派 3B、3B+ 的 18.06.01 版︰

Raspberry Pi

The Raspberry Pi is a single-board computer without an Ethernet Network Switch. There are many more Single-board computers without one.

OpenWrt for Raspberry Pi 2 is compiled with the ARM hard-float kernel ABI (armhf). This means that non-integer math is done in hardware instead of in software. Raspberry Pi 1 (and Zero) support only soft-float (armel) which is slower than hard float.

Supported Versions

The Raspberry Pi is supported in the brcm2708 target.
Subtargets are bcm2708 for Raspberry Pi 1, bcm2709 for the Raspberry Pi 2, bcm2710 for the Raspberry Pi 3.

Model Version Current Release Unsupported Functions OEM Info Forum Topic  
Raspberry Pi A 18.06.1        
Raspberry Pi B 18.06.1        
Raspberry Pi B+ 18.06.1        
Raspberry Pi 2 B 18.06.1     https://forum.openwrt.org/viewtopic.php?id=56397  
Raspberry Pi 3 B 18.06.1 Country Code setting raspberry-pi-3-model-b/    
Raspberry Pi 3 B+ 18.06.1 Country Code setting raspberry-pi-3-model-b-plus/ https://forum.openwrt.org/t/18-06-on-raspberry-pi-3-b/18670/10  
Raspberry Pi Zero W   18.06.1   pi-zero-wireless/    

Wireless Country Code Issue

The Country Code under Wireless in OpenWrt does not work, and you do need to set/change the country code in the latest Raspbian, and then you can go back to OpenWrt; the new country code will be used. Starting with Raspberry Pi 3 B+, the on-board wireless won’t even start if there is no country code (set in Raspbian) See: https://forum.openwrt.org/t/cannot-use-channels-12-and-13-on-raspberry-pi-3-in-ap-config/3707/3

 

不過不管是用 3B 還是 3B+ ,作者測試結果,網路問題多多哩?

18.06 on Raspberry Pi 3 B+

I have noticed a few things that are still an issue:

  1. The release builds don’t boot. Neither 18.06 or 18.06.1. Snapshots between 18.06 and 18.06.1 work, and snapshots post 18.06.1 work. Seems like something is different in the build process for the two (most likely in the FAT partition where the GPU and kernel live).
  2. The 3 B+ has a gigabit NIC, and when using Raspbian or other distros I can get a gigabit link and push > 100 mbps. I just loaded the latest snapshot (r7819-0ddb34b from 9/03) and I am still only getting 100mbit link. Perhaps this is due to the bcrm27xx builds still using the 4.9 kernel instead of 4.14 like some of the other platforms.
  3. The ethernet port only works when attached to a bridge. It can’t be the only physical interface attached to an OpenWrt interface.
  4. The link lights on the Pi’s ethernet port don’t work in OpenWrt.

 

所以才從 LEDE 17.01.4 樹莓派 3B 開始呦!

Index of (root) / releases / 17.01.4 / targets / brcm2708 / bcm2710 /


Image Files

These are the image files for the brcm2708/bcm2710 target. Check that the sha256sum of the file you downloaded matches the sha256sum below.
Shortened image file names below have the same prefix: lede-17.01.4-brcm2708-bcm2710-...

Image for your Device sha256sum File Size Date
rpi-3-ext4-sdcard.img.gz e76bbbb6bac72345aea0b15a0cf5df99004ecc99db43c7d5843af1cad48f3281 8297.3 KB Wed Oct 18 13:27:32 2017

 

假使已經閱讀

Documentation

OpenWrt/LEDE is a highly extensible GNU/Linux distribution for embedded devices (typically wireless routers). LEDE is based on the OpenWrt project. Unlike many other distributions for routers, LEDE is built from the ground up to be a full-featured, easily modifiable operating system for embedded devices. In practice, this means that you can have all the features you need with none of the bloat, powered by a modern Linux kernel.

OpenWrt/LEDE Guides

Quick Start Guide User Guide Developer Guide
Start here if you are new to OpenWrt. Find out how to upgrade the firmware your home router to use OpenWrt and make your network at home much better. Read more… Start here if you already have OpenWrt running on your router. OpenWrt has hundreds of optional packages that give you VPNs, VLANs, and other capabilities. Read more… Start here if you want to create custom builds of OpenWrt or contribute to its development. There are a large number of tools that make the development easy. Read more…
hardware documentation Tech reference
A collection of articles about the hardware and devices the OpenWrt firmware runs on. Read more… Technical reference articles about OpenWrt components. Read more…

Where can I learn more?

The three guides above (Newcomer, User, and Developer Guides) have links to virtually all the information about OpenWrt/LEDE. You can also use the Search function from any wiki page, or work you through the complete listing of documentation pages shown below.

 

是否會卡在『預設』呢??

Accessing the OpenWrt web admin GUI

OpenWrt has a web admin GUI called “LuCi”.

  • If your OpenWrt device has been configured as a router or gateway with default settings, LuCi is listening on your local IP subnet’s default gateway address http://192.168.1.1.
  • If your OpenWrt device has been configured as WiFi access point, network client or switch, LuCi’s address depends on the IP address you have manually configured for your OpenWrt device. You can also try, to use a local network scanner or your regular router’s status page to find out the device IP address.

You need to use the “root” password to successfully access LuCi, ‘root’ is the default admin account of your OpenWrt device. On a freshly installed OpenWrt device, there is no password set yet for the ‘root’ account, you can just enter right away. Please make sure, to set an individual ‘root’ password as soon as possible.

If you are unable to access your OpenWrt device, due to messed up IP address/root password configuration, refer to the troubleshooting section of the user guide, to reset the OpenWrt device’s settings.

 

此時可以藉著

Linux networking IP port aliasing tutorial

This tutorial works through an example of how IP aliasing can be used to provide multiple network addresses on a single physical interface. This demonstrates using IP version 4 addresses only.

Most distributions include IP aliasing compiled into the kernel. If that is not the case for your particular distro then you can load the module using the insmod command.

One reason for using this could be to make a computer look as though it is multiple computers, so for example you could have one server that is acting as both a gateway (router) and a DHCP server and DNS using 3 different IP addresses, perhaps with a future plan to use a hardware router and to move the functionality to seperate DNS and DHCP servers. Or indeed the opposite you could decide to replace the 3 different hardware devices with a single server to reduce the administration overhead.

In this case you can have 3 different addresses which are all on the same computer without having to install lots of physical network interfaces.

Another reason, which is the one I will use in this tutorial, is that you want to have the computer on two different logical network subnets whilst using a single physical interface. The reason I originally needed to do this is that I purchased a network device that comes pre-configured with an IP address on the 192.168.0.0/24 address range, but my linux machine is on the 192.168.1.0/24 address range. I therefore configured an alias so that I can connect to the new device to configure it onto my 192.168.1.0/24 network address.

 

文本,利用同環境的另一台樹莓派來解難!!

pi@raspberrypi:~ sudo ifconfig eth0:0 192.168.1.2 pi@raspberrypi:~ ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 5.168.168.4  netmask 255.255.255.0  broadcast 5.168.168.255
        inet6 fd80:3d97:ea71:0:2c83:ba6a:5df6:1474  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::9df5:9aaa:5f08:ab31  prefixlen 64  scopeid 0x20<link>
        inet6 fd80:3d97:ea71::3c2  prefixlen 128  scopeid 0x0<global>
        ether b8:27:eb:01:5f:eb  txqueuelen 1000  (Ethernet)
        RX packets 1555  bytes 131506 (128.4 KiB)
        RX errors 0  dropped 529  overruns 0  frame 0
        TX packets 288  bytes 43976 (42.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.2  netmask 255.255.255.0  broadcast 192.168.1.255
        ether b8:27:eb:01:5f:eb  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 26  bytes 15940 (15.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 26  bytes 15940 (15.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:54:0a:be  txqueuelen 1000  (Ethernet)
        RX packets 10  bytes 1484 (1.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 54  bytes 10500 (10.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

pi@raspberrypi:~ $ ssh -l root 192.168.1.1
The authenticity of host '192.168.1.1 (192.168.1.1)' can't be established.
RSA key fingerprint is SHA256:iQytfgCAT2gOUEH5YV6tRuoic2zNmhTjp0zca1wnKW4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.1' (RSA) to the list of known hosts.


BusyBox v1.25.1 () built-in shell (ash)

     _________
    /        /\      _    ___ ___  ___
   /  LE    /  \    | |  | __|   \| __|
  /    DE  /    \   | |__| _|| |) | _|
 /________/  LE  \  |____|___|___/|___|                      lede-project.org
 \        \   DE /
  \    LE  \    /  -----------------------------------------------------------
   \  DE    \  /    Reboot (17.01.4, r3560-79f57e422d)
    \________\/    -----------------------------------------------------------

=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@LEDE:~# 

 

竟然發現根本沒有 LuCi Web 界面勒?文字編譯器僅有 vi !☻

笑笑☺ 只好打通『網際玄關』啊︰

root@LEDE:~# ifconfig br-lan:0 5.168.168.28
root@LEDE:~# ifconfig 
br-lan    Link encap:Ethernet  HWaddr B8:27:EB:C2:B0:6E  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::ba27:ebff:fec2:b06e/64 Scope:Link
          inet6 addr: fd80:3d97:ea71::1/60 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:271 errors:0 dropped:34 overruns:0 frame:0
          TX packets:132 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:23580 (23.0 KiB)  TX bytes:18150 (17.7 KiB)

br-lan:0  Link encap:Ethernet  HWaddr B8:27:EB:C2:B0:6E  
          inet addr:5.168.168.28  Bcast:5.255.255.255  Mask:255.0.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0      Link encap:Ethernet  HWaddr B8:27:EB:C2:B0:6E  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:271 errors:0 dropped:0 overruns:0 frame:0
          TX packets:132 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:23580 (23.0 KiB)  TX bytes:19686 (19.2 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:56 errors:0 dropped:0 overruns:0 frame:0
          TX packets:56 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:3752 (3.6 KiB)  TX bytes:3752 (3.6 KiB)

root@LEDE:~# route add default gw 5.168.168.1
root@LEDE:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         5.168.168.1     0.0.0.0         UG    0      0        0 br-lan
5.0.0.0         *               255.0.0.0       U     0      0        0 br-lan
192.168.1.0     *               255.255.255.0   U     0      0        0 br-lan

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

root@LEDE:~# opkg update
Downloading http://downloads.lede-project.org/releases/17.01.4/targets/brcm2708/bcm2710/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/reboot_core
Downloading http://downloads.lede-project.org/releases/17.01.4/targets/brcm2708/bcm2710/packages/Packages.sig
Signature check passed.
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/base/Packages.gz
Updated list of available packages in /var/opkg-lists/reboot_base
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/base/Packages.sig
Signature check passed.
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/luci/Packages.gz
Updated list of available packages in /var/opkg-lists/reboot_luci
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/luci/Packages.sig
Signature check passed.
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/reboot_packages
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/packages/Packages.sig
Signature check passed.
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/routing/Packages.gz
Updated list of available packages in /var/opkg-lists/reboot_routing
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/routing/Packages.sig
Signature check passed.
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/telephony/Packages.gz
Updated list of available packages in /var/opkg-lists/reboot_telephony
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/telephony/Packages.sig
Signature check passed.

root@LEDE:~# opkg install luci
Upgrading luci on root from git-17.290.79498-d3f0685-1 to git-18.201.27126-7bf0367-1...
Downloading http://downloads.lede-project.org/releases/17.01.4/packages/arm_cortex-a53_neon-vfpv4/luci/luci_git-18.201.27126-7bf0367-1_all.ipk
Configuring luci.
root@LEDE:~# /etc/init.d/uhttpd start
root@LEDE:~# /etc/init.d/uhttpd enable
root@LEDE:~#

 

※ 有圖為證︰