OpenWRT Raspberry Pi Docker & VLAN Project

tl;dr Turn your Raspberry Pi into a router, managing devices and running services through Docker and VLANs! 😮

OpenWRT🥧 on PoE!
Overall Design Layout

Installing the PoE Hat

Download & Install OpenWRT

opkg update
opkg install cfdisk resize2fs
cfdisk /dev/mmcblk0
resize2fs /dev/loop0

VLAN Setup

Managed Switch

OpenWRT

config interface 'loopback'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
option device 'lo'
config interface 'lan'
option proto 'static'
option netmask '255.255.255.0'
option ipaddr '192.168.0.1'
option device 'eth0.1'
config interface 'wan'
option proto 'dhcp'
option device 'eth0.2'

WiFi Access Point

Adding the USB Drive & Creating Samba Shares

opkg update
opkg install ntfs-3g
mkdir -p /mnt/1TB && \
ntfs-3g /dev/sda1 /mnt/1TB -o rw,lazytime,noatime,big_writes && \
ls -la /mnt/1TB
sleep 1
ntfs-3g /dev/sda1 /mnt/1TB -o rw,lazytime,noatime,big_writes
exit 0
opkg install samba4-server samba4-client luci-app-samba4

Docker

Install Docker

opkg update
opkg install dockerd docker-compose luci-app-dockerman kmod-macvlan

Install Plex

docker run --detach \
--name plex \
--net=host \
--restart unless-stopped \
-e PGID=1000 \
-e PUID=1000 \
-e UMASK=022\
-e VERSION=docker \
-v /mnt/1TB/dMusic:/data/dmusic \
-v /mnt/1TB/docker/plex:/config \
-v /mnt/1TB/docker/plex:/transcode \
-v /mnt/1TB/Music:/data/music \
linuxserver/plex

Install PiHole …and do the other networking stuff to support it

config route
option interface 'macvlan'
option target '192.168.30.3'
option netmask '255.255.255.255'
#!/usr/bin/with-contenv bash
set -e
echo "fixing routes"
ip route del default
ip route add default via 172.18.0.1
config interface 'vlan20'
option proto 'static'
option ipaddr '192.168.20.1'
option netmask '255.255.255.0'
option device 'eth0.20'
config device
option type 'macvlan'
option ifname 'eth0'
option mode 'bridge'
option name 'eth0.20'
option acceptlocal '1'
option ipv6 '0'
version: "3.3"
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
hostname: pihole.lan
environment:
TZ: 'Europe/London'
WEBPASSWORD: 'asdf'
volumes:
- '/mnt/1TB/docker/pihole/pihole/:/etc/pihole/'
- '/mnt/1TB/docker/pihole/dnsmasq.d/:/etc/dnsmasq.d/'
cap_add:
- NET_ADMIN
restart: unless-stopped
networks:
lan20:
ipv4_address: 192.168.20.3
networks:
lan20:
name: lan20
driver: macvlan
driver_opts:
parent: eth0.20
ipam:
config:
- subnet: 192.168.20.0/24
gateway: 192.168.20.1
iptables -t nat -A PREROUTING -i eth0 -p udp --dport 53 -j DNAT --to 192.168.20.3
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 53 -j DNAT --to 192.168.20.3

DNS over HTTPS

opkg update
opkg install https-dns-proxy luci-app-https-dns-proxy

Docker #2

Install Transmission …and do the other networking stuff to support it

version: "3.3"
services:
transmission:
container_name: transmission
image: linuxserver/transmission:latest
hostname: transmission.lan
environment:
TZ: 'Europe/London'
volumes:
- '/mnt/1TB/docker/transmission/config/:/config'
- '/mnt/1TB/docker/transmission/downloads/:/downloads'
- '/mnt/1TB/docker/transmission/watch/:/watch'
cap_add:
- NET_ADMIN
restart: unless-stopped
networks:
internal:
lan30:
ipv4_address: 192.168.30.3
networks:
internal:
name: transmission_internal
driver: bridge
lan30:
name: lan30
driver: macvlan
driver_opts:
parent: eth0.30
ipam:
config:
- subnet: 192.168.30.0/24

Install OpenVPN

TORVLAN
TORVPN
LAN2TOR

Policy Based Routing

END

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store