Time to chat

openwrt

First, let’s talk about OpenWRt, which is basically what you can think of as a router system.

OpenWrt is a Linux distribution for embedded devices, so OpenWrt runs with low resource usage. The hardware performance of raspberry PI is much higher than that of regular routers. While PI’s absolute hardware advantage gives OpenWrt more room to work, the hardware advantage also comes with a waste of resources (Less than 1/10 of OpenWrt’s resources when running properly on PI). In addition, OpenWrt is not very extensible, so many of the things that you can do on Raspbian/Debian are not available on OpenWrt.

You can’t just swipe raspberry PI through OpenWRt and not have it. So what’s the way?

That’s right, Docker, which allows Linux and OpenWRt to coexist. Raspberry pie doesn’t eat as much dust.

The bypass gateways

So what is a bypass gateway? In fact, he has a few similarities to Spring Cloud.

A common router is like a stand-alone machine at the beginning. It is responsible for everything, such as signal forwarding, DNS, gateway, etc. The “gateway” role is responsible for processing the internal data of the router. However, due to the limited performance of the hardware of the general home router, almost all the hardware resources will be occupied when running some resource-intensive applications (such as sour milk, advertising, etc.), resulting in the instability of the router network/system and many other problems. At this time, we divided the role of the gateway to run on the raspberry PI alone, is it sharing the pressure of the main route, is it a little microservice that flavor? In this way, each role has its own role, raspberry PI also ended its fate to eat ash, better test the sentence of productivity before buy, buy bypass by.

Note:

  • In this paper, Docker image is only applicable to raspberry PI 2B/3B/3B+/4B, which can not be used normally on other devices in theory
  • Running OpenWrt in Docker, PI will work in bypass gateway mode, where PI’s onboard wireless card won’t work (and there’s no WIFI Settings in OpenWrt’s control panel). Therefore, raspberry PI needs to be connected to the router through a network cable to use.

preparation

Docker is definitely a must, you can also install it on Raspberry PI yourself, Mordo has a lot of tutorials, I won’t go into that here, I’m not using the official raspberry PI system,

This is a mirror image of a raspberry PI made by the PI fan base, optimized for the specific features of the PI. Attached is the Github address below:

Portal.

It is recommended to brush into the non-desktop enhanced version, this version comes with Docker, and also has a Web management interface, more detailed are written in the Readme document, your own research. Default user: PI Default password: raspberry

Plug in the cable, SSH login, etc! Here’s another puzzle: How do I know the IP address of raspberry PI? There are many ways:

  • Connect monitor, keyboard, sudo ifconfig (trouble)

  • Enter the router background to view (too troublesome)

  • IP Scanner A tool for scanning LAN IP addresses. portal

When you connect the raspberry PI, the preparation is complete.

Specific steps

Step 1: Enable the promiscuous mode of the NETWORK adapter

sudo ip link set eth0 promisc on
Copy the code

Step 2: Create a Docker network

Attention, here needs to be combined with their own network modification, can not copy!! Sudo ifconfig can check the IP address of raspberry PI, but just don’t know [khan], more way

If you have just logged in to SSH and the IP address is 192.168.31.7, then raspberry PI is in the 192.168.31.x network segment

–subnet=192.168.x.0/24 and –gateway=192.168.x.1 are to be replaced with the IP addresses of the corresponding network segment. (Please modify the X here according to your own network)

After the replacement:

Docker network create -d macvlan --subnet=192.168.31.0/24 --gateway=192.168.31.1 -o parent=eth0 macnetCopy the code

So this is our Docker Network LS and we can see the network that we just created

pi@raspbian:~$ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
e5988f578007        bridge              bridge              local
107c16227dd4        docker_gwbridge     bridge              local
3ceb60d85b9c        host                host                local
b1929166e45c        macnet              macvlan             local
93ad7ae8da72        none                null                local

Copy the code

I also went out of my way to check macVLAN here

Macvlan is a virtual nic solution:

  • Macvlan does not create a network, but only a virtual nic.
  • Macvlan willSharing a Physical NICThe linkThe external network, the effect is the same as the bridge mode.

There’s a reference link at the end of this article to learn more.

Step 3: Pull the mirror.

docker pull harryzhang6/openwrt:latest
Copy the code

We can view local images using Docker images

pi@raspbian:~$ docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
harryzhang6/openwrt   latest              5c354d2e6f6f        3 hours ago         235MB
Copy the code

In this case, the mirror pulled successfully.

Step 4: Create and start the container

docker run --restart always --name openwrt -d --network macnet --privileged harryzhang6/openwrt:latest /sbin/init
Copy the code
  • --restart alwaysParameter indicates that the container is always restarted when exiting, so that the service is always available as far as possible.
  • --name openwrtThe argument defines the name of the container;
  • -dParameter definitions make the container run in Daemon mode;
  • --network macnetParameter definition adds the container tomaxnetNetwork;
  • --privilegedThe argument defines that the container runs in privileged mode.

Let’s docker PS check to see if the container started successfully

pi@raspbian:~$ docker ps
CONTAINER ID        IMAGE                        COMMAND             CREATED             STATUS              PORTS               NAMES
755d018206fd        harryzhang6/openwrt:latest   "/sbin/init"        2 minutes ago       Up 2 minutes                            openwrt
Copy the code

After confirming the successful startup, the next step is to go to the container configuration

Step 5: Enter the container and modify its parameters

Note: Some of the configuration for this step is the same as above and cannot be copied

docker exec -it openwrt bash
Copy the code

First, we need to edit the OpenWrt network configuration file:

vim /etc/config/network
Copy the code

We need to change the Lan port Settings:

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static' 
        option ipaddr '192.168.31.100'// Option netmask needs to be changed'255.255.255.0'
        option ip6assign '60'
        option gateway '192.168.31.1'// Option broadcast needs to be changed'192.168.123.255'
        option dns '192.168.31.1'// Need to changeCopy the code

Here is my configuration, need to change. Option Gateway and Option DNS Enter the ROUTER IP address. If the IP address obtained by raspberry PI is 192.168.31.154, the router IP address is 192.168.31.1.

The Option IPaddr item defines the OpenWrt IP address. After the network segment is set, the last IP address segment can be changed as you like (provided that it meets the rules and does not conflict with the existing assigned IP addresses).

Step 6: Restart the network

/etc/init.d/network restart
Copy the code

Step 7: Go to the OpenWRT management page

Enter the option IPaddr you just defined in Step 5 in your browser, which in my case is 192.168.31.1, to see the admin interface in the background

User name: root

Password:

Step 8: Disable the DHCP service

On the Netport-Interface-LAN-Modify page, select Ignore this interface (DHCP service is not provided on this interface) in the lower part and save & Apply.

Step 9: Set the active route DHCP

It’s not unnecessary here,

Enter the router background and set the DEFAULT gateway of DHCP and DNS server of the active route to the IP address in the Option IPaddr item in step 5.

Since you do not want every device to pass through the OpWRT, only the device that you set up can use the OpenWRT gateway.

Restart the router if you have changed the active route DHCP.

This is almost the end of the tutorial. Attached below is a tutorial for manually specifying gateways

Manually specify a gateway

If the router firmware does not support user-defined DHCP service gateways and DNS addresses (often seen in router firmware), or only some devices in the LAN need to access the bypass gateway, perform the following configurations on the access devices:

Windows:

In the Properties window of the wireless hotspot, click IP Settings – Edit. In the dialog box that is displayed, change the IP assignment mode to Manual, turn on IPV4, and set related parameters based on the network segment you are in and the previous Settings of Android.

The android

You need to change the IP acquisition mode to “static” or “manual” in the WIFI Settings of Android, where:

The IP address must be in the same network segment as the preceding one. The prefix length is 24. Enter the bypass gateway IP address of the two DNS servers.

Openwrt screenshots

There are a few themes, but this one looks better.

Look at the memory footprint. It works

END

Finally, the OpenWRt image does not have AP functionality. There is no WIFI option, but most functions are available.

The openWrt container starts with the Raspberry PI system without manual intervention.

Raspberry pie is finally gone !!!!

Refer to the link

  • www.jianshu.com/p/2b8b6c738…

  • mlapp.cn/376.html

  • Github.com/openfans-co…