Inspired by other projects that run hostapd in a Docker container. This goes one step further and boots a full network OS intended for embedded devices called OpenWrt, so you can manage all aspects of your network from a user-friendly web UI.
 
 
 
 
Go to file
Jordan Sokolic eea82e1c8b wait just a little more 2020-04-17 13:47:50 +03:00
etc Revert "junk" 2020-04-12 09:50:42 +03:00
monitoring rates in bits/sec instead of bytes/sec 2020-03-17 14:34:08 +02:00
.gitignore sensitive variables here 2020-03-06 15:57:11 +02:00
Dockerfile upgrade pkgs during build 2020-04-12 09:30:43 +03:00
Dockerfile.rpi add iperf 2020-04-16 11:04:49 +03:00
Makefile build for raspberry pi 2020-04-15 23:03:26 +03:00
README.md link to monitoring readme 2020-03-06 15:59:10 +02:00
build-rpi.sh notes 2020-04-16 11:04:57 +03:00
ipv6.md
monitoring.md
openwrt.conf.example add some notes to conf example 2020-04-16 11:04:40 +03:00
openwrt.service network must be up 2020-03-12 19:07:21 +02:00
run.sh wait just a little more 2020-04-17 13:47:50 +03:00
vpn.md

README.md

OpenWRT in Docker

Inspired by other projects that run hostapd in a Docker container. This goes one step further and boots a full network OS intended for embedded devices called OpenWRT, so you can manage all aspects of your network from a user-friendly web UI.

I only tested this on x86_64, but it might work on ARM too with some minor tweaking.

Dependencies

  • docker
  • iw
  • iproute2
  • envsubst (part of gettext or gettext-base package)
  • dhcpcd

Build

$ make build

If you want additional OpenWRT packages to be present in the base image, add them to the Dockerfile. Otherwise you can install them with opkg after bringing up the container.

A searchable package list is available on openwrt.org.

Configure

Initial configuration is performed using a config file, openwrt.conf. Values read from this file at runtime are used to generate OpenWRT format config files.

To add or change the base configuration, modify the config templates in etc/config/<section>.tpl.

You can of course make persistent changes in the UI and download a backup of your full router configuration by navigating to System > Backup / Flash Firmware and clicking Backup.

Run

$ make run

If you arrive at * Ready, point your browser to http://openwrt.home (or whatever you set in LAN_DOMAIN) and you should be presented with the login page. The default login is root with the password set as ROOT_PW.

To shut down the router, press Ctrl+C. Any settings you configured or additional packages you installed will persist until you run make clean, which will delete the container.

Install / Uninstall

$ make install

Install and uninstall targets for systemd have been included in the Makefile.

Installing will create and enable a service pointing to wherever you cloned this directory and execute run.sh on boot.

Cleanup

$ make clean

This will delete the container and all associated Docker networks so you can start fresh if you screw something up.


Notes

Hairpinning

This took a couple of tries to get working. The most challenging issue was getting traffic from WLAN clients to reach each other.

In order for this to work, OpenWRT bridges all interfaces in the LAN zone and sets hairpin mode (aka reflective relay) on the WLAN interface, meaning packets arriving on that interface can be 'reflected' back out through the same interface. OpenWRT is not able to set this mode from inside the container even with NET_ADMIN capabilities, so this must be done from the host.

run.sh tries to handle this, and prints a warning if it fails.

Network namespace

For hostapd running inside the container to have access to the physical wireless device, we need to set the device's network namespace to the PID of the running container. This causes the interface to 'disappear' from the primary network namespace for the duration of the container's parent process. run.sh checks if the host is using NetworkManager to manage the wifi interface, and tries to steal it away if so.

Troubleshooting

Logs are redirected to stdout so the Docker daemon can process them. They are accessible with:

$ docker logs ${CONTAINER} [-f]

As an alternative to installing debug packages inside your router, it's possible to execute commands available to the host inside the network namespace. A symlink is created in /var/run/netns/<container_name> for convenience:

$ sudo ip netns exec ${CONTAINER} tcpdump -vvi any 

OpenVPN Howto

Bandwidth Monitoring Howto

Monitoring with InfluxDB + Grafana

IPv6 Notes