Manually build a portable WiFI router/NAS/Docker on Raspberry Pi 4

; Date: Fri Jul 08 2022

Tags: Raspberry Pi »»»» RaspAP

Raspberry Pi OS (Linux) can be configured to support high end WiFi router configurations. No software like OpenWRT or RaspAP is required, if you have the patience to configure it all yourself using the command-line tools.

We recently went over using OpenWRT and RaspAP to build a WiFi router from a Raspberry Pi. Either of those software packages make it easy to configure router settings. It is possible to build most WiFi router configurations with a few clicks of the mouse. But, those packages are built on top of capabilities inherent to Linux, meaning we could do everything with the existing tools and not require addon software.

If you wish to learn the commands, you can custom build a router that exactly suits your needs. Both OpenWRT and RaspAP are limited in that you can only implement what the authors of each package believed you need. Using the command-line tools you can build any configuration you like.

For earlier articles:

Below is a video that goes over the Linux/Raspberry Pi OS commands required to setup a WiFi router on Raspberry Pi that has NAS capabilities. Our earlier article did this using RaspAP.

This is a summary of the commands:

  • Turn off rfkill to allow turning on the WiFi system
  • Install hostapd -- Allows WiFi antenna to host an access point
  • Install dnsmasq -- Allows services like DNS and DHCP to be installed
  • Run: sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent -- Sets up netfilter and iptables so their settings persist across reboots
  • Run: sudo systemclt unmask hostapd.service
  • Run: sudo systemclt enable hostapd.service -- Enable the WiFi access point service
  • Edit /etc/dhcpcd.conf -- to set up DHCP service for the subnet we want to support from this router. See the discussion and settings in the video.
  • Edit /etc/sysctl.d/routed-ap.conf and enter net.ipv4.ip_forward=1 to configure forwarding of IPv4 addresses. How will IPv6 addresses be handled?
  • Run sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE to set up NAT routing from WiFi to ethernet
  • Run sudo netfilter-persistent save -- to save things
  • Run sudo rm /etc/dnsmasq.conf -- To remove existing DNSmasq configuration
  • Run sudo touch /etc/dnsmasq.conf -- To start a new file
  • Edit /etc/dnsmasq.conf to add the configuration described in the video
  • Run sudo touch /etc/hostapd/hostapd.conf
  • Edit sudo touch /etc/hostapd/hostapd.conf to add the configuration described in the video

That much enables the WiFi router. The number of commands and files involve explains to me why software packages like OpenWRT or RaspAP are so valuable.

He then configured Samba but didn't show the Samba configuration in the video.

About the Author(s)

(davidherron.com) David Herron : David Herron is a writer and software engineer focusing on the wise use of technology. He is especially interested in clean energy technologies like solar power, wind power, and electric cars. David worked for nearly 30 years in Silicon Valley on software ranging from electronic mail systems, to video streaming, to the Java programming language, and has published several books on Node.js programming and electric vehicles.