
Installing OpenWrt on a Raspberry Pi 4 with ethernet dongle as WAN port and on board ethernet as LAN port.
Before we start, make sure that you have all the required packages installed. Take a look at https://openwrt.org/docs/guide-developer/toolchain/install-buildsystem.
First download the git repository.
# Download and update the sources
git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt
git pull
Now that we have the latest version of OpenWrt we select a version of choice.
# Select a specific code revision
git branch -a
git tag
git checkout v23.05.0
Next, we update and install the feeds. Also custom feeds can be added at this point.
# Update the feeds
./scripts/feeds update -a
./scripts/feeds install -a
At this point we configure the image. After running the following command we need to change a few settings. Enable settings by pressing space until a * appears.
- Target System should be
Broadcom BCM27xx. - Subtarget should be
BCM2711 boards (64 bit). (After selecting that you should see Raspberry Pi 4B in Target Profile.) - In Target Images, only
squashfsshould be enabled and the Root filesystem must be enlarged to fit the SD card. For example 12000 MiB for a 16 GB SD card. This can be automatically expanded after installation. - In Kernel modules, go to USB Support and select
kmod-usb-net-asix-ax88179orkmod-usb-net-rtl8150depending on your ethernet adapter. And selectkmod-usb2andkmod-usb3. - In LuCI, go to Collections and enable
luci,luci-ssl.
After that exit and save.
# Configure the firmware image
make menuconfig
One last step before we compile the system is to add some configuration files. This is the network file that indicates which IP range should be used, and which port should act as WAN and LAN. Do this by creating the following folders first.
mkdir -p files/etc/config/
And then add the following contents to the file: files/etc/config/network.
config interface 'loopback'
option device 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config globals 'globals'
option ula_prefix 'fd6e:bdeb:1e0c::/48'
config device
option name 'br-lan'
option type 'bridge'
list ports 'eth0'
config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.8.1'
option netmask '255.255.255.0'
option ip6assign '60'
list dns '1.1.1.1'
config interface 'WAN'
option proto 'dhcp'
option device 'eth1'
Next the DHCP file which makes it easy to connect to the network by giving us an IP instead of needing to manually configure that. Add the following section to the file files/etc/config/dhcp.
config dnsmasq
option domainneeded '1'
option boguspriv '1'
option filterwin2k '0'
option localise_queries '1'
option rebind_protection '1'
option rebind_localhost '1'
option local '/lan/'
option domain 'lan'
option expandhosts '1'
option nonegcache '0'
option cachesize '1000'
option authoritative '1'
option readethers '1'
option leasefile '/tmp/dhcp.leases'
option resolvfile '/tmp/resolv.conf.d/resolv.conf.auto'
option nonwildcard '1'
option localservice '1'
option ednspacket_max '1232'
option filter_aaaa '0'
option filter_a '0'
config dhcp 'lan'
option interface 'lan'
option leasetime '12h'
option start '100'
option limit '150'
option dhcpv4 'server'
option dhcpv6 'server'
option ra 'server'
list ra_flags 'managed-config'
list ra_flags 'other-config'
config dhcp 'wan'
option interface 'wan'
option ignore '1'
config odhcpd 'odhcpd'
option maindhcp '0'
option leasefile '/tmp/hosts/odhcpd'
option leasetrigger '/usr/sbin/odhcpd-update'
option loglevel '4'
And the last configuration file to creates a wireless network for us to connect to. Add the following bit to the file files/etc/config/wireless.
config wifi-device 'radio0'
option type 'mac80211'
option path 'platform/soc/fe300000.mmcnr/mmc_host/mmc1/mmc1:0001/mmc1:0001:1'
option channel '36'
option band '5g'
option htmode 'VHT80'
option cell_density '0'
config wifi-iface 'default_radio0'
option device 'radio0'
option network 'lan'
option mode 'ap'
option ssid 'Douwe'
option encryption 'psk2'
option key '0penWrt!!'
Now that we are done with the configuration files, is it time to build the image. We can do this in two steps. First we download all that is needed. and then we build.
make download
# Build the firmware image
make -j$(nproc)
Final stap is to put the image on a SD card. That can be done with balenaEtcher, or any program of your choice.
