There are a lot of articles on the Internet on how to make a Wi-Fi router from a Raspberry Pi (RPI), in this post I will briefly describe my method of creating a Wi-Fi router with a sing-box on board. The described method works at the current time, and a lot may change in the future. So use this note as a rough overview of what you’ll be up against.
SSH
For those who do not know how to work with OpenWrt, I recommend installing dietPI.
Connect RPI to your current router via eth0, then connect there via SSH. You can find out the RPI IP address in the dhcp panel of the router. Connect directly to root, for example like this:
ssh root@[IP_ADDRESS]
Wi-Fi adapter
The built-in RPI3 turned out to be frankly weak and does not support 5GHz. Therefore, I connected the RITMIX RWA-150 adapter on the Realtek RTL8811CU chipset via USB 2. The drivers were added to the Linux kernel which was in my dietPi version. Next, using dietpi-config, I turned off the built-in Wi-Fi completely. As a result, there was only one wlan0 USB adapter left.
Access point
The default dietPI password for root is dietpi. Once connected, you will be greeted by the dietPI installer/configurator. When finished, you will need to connect again due to the device rebooting.
First, you need to configure hostapd so that devices can see your access point. If hostapd is not installed, then install it via apk.
Next you will need to write a config for hostapd. Example of my config:
interface=wlan0
driver=nl80211
ssid=MyPiAP
hw_mode=a
channel=157
wmm_enabled=1
auth_algs=1
wpa=2
wpa_passphrase=your_password
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ieee80211n=1
ieee80211ac=0
ieee80211ax=0
country_code=RU
The meaning of the hostapd config can be found in the manual. However, what is important is to configure it for yourself – the channel (2.4GHz or 5GHz), the country code, otherwise without this your localized devices can work with the access point correctly, I have already done this and know, so set your country carefully.
DHCP
Next, install and configure dnsmasq to implement DHCP. This is necessary for the connected computers to determine the IP address and DNS server.
Example of my config:
interface=wlan0
dhcp-range=172.19.0.10,172.19.0.200,255.255.255.0,12h
dhcp-option=3,172.19.0.1
dhcp-option=6,1.1.1.1,8.8.8.8
no-resolv
server=1.1.1.1
server=8.8.8.8
This is the minimum config that will allow you to connect to an access point and get an IP address. Next you will need to configure routing and NAT. This is necessary so that connected computers can access the Internet.
Here the note goes into the category of typical routing setup on a regular Debian compatible system, about which there are a lot of articles on the Internet. Then it all depends on what goals you are pursuing, for example, connecting to an external server as a new interface in the system, or just doing wlan0 <-> eth0, this is where the RPI specifics end, then configure it to your taste.
I would also like to mention the need to configure custom system services via systemctl; there may be a need to connect services in a chain; all this is in the systemctl manuals on the network. If there are problems at the service level, then check the logs in journalctl.
Conclusion
From the speed measurements, we were able to squeeze out about 50Mbps from RPI3 over Wi-Fi (after connecting a 5GHz adapter), which means a loss of half the speed compared to connecting directly to the router. I admit that more productive RPI models will allow you to achieve better results, also specialized OpenWrt devices and ready-made solutions may be better for your needs.
Sources
https://forums.raspberrypi.com/viewtopic.php?t=394710
https://superuser.com/questions/1408586/raspberry-pi-wifi-hotspot-slow-internet-speed
https://www.youtube.com/watch?v=jlHWnKVpygw