Whether it’s watching a video, sending an email, or simply surfing the web, all our interactions with the Internet are fundamentally data exchanges that go back and forth. To facilitate these exchanges, routers play an indispensable role in, well, routing data. In this article, I’m going to share exactly why you should consider building a custom Raspberry Pi Router – and more importantly, how!
What is a Router?
A router is a piece of hardware that connects a Local Area Network (LAN) to other networks. In most cases, this “other network” is known as a Wide Area Network (WAN), or none other than the Internet.
A router’s purpose is to serve as the bridge between the two networks, which is done by forwarding data packets that need to be transmitted “across borders”. To achieve this, devices are connected to the router either through a network cable like ethernet, or over a wireless connection like WiFi, As a result, local devices not only gain access to the Internet, but can also communicate with each other through the router – hence the term “Local Network”.
The router is very much the “administrator” of this local network, and plays an important role in managing connected devices. For instance, the router is responsible for assigning IP addresses to incoming connection requests, typically through DHCP (Dynamic Host Configuration Protocol). Thus, each device can be identified and managed individually.
However, the greatest potential of routers also lies in a prevalent misconception about them. While their primary role is indeed to simply coordinate connections and forward data, routers are very much small computers themselves. To deal with incoming and outgoing data, routers are equipped with CPUs and memory. In addition, they can also be fitted with an operating system like a computer.
Why build a Raspberry Pi Router?
So far, we’ve talked briefly about what routers were designed for, but it’s not yet clear why we would want to build a custom router with a Raspberry Pi. Before we get into it, let’s first take a look at what a Raspberry Pi offers.
Introducing the Raspberry Pi 4 Computer Model B
The Raspberry Pi 4 is a Single Board Computer offered by the Raspberry Pi Foundation. Designed in a compact form factor that’s just about the size of your credit card, the Pi 4 is powered by the Broadcom BCM2711 quad-core Cortex-A72 ARM SoC that runs at 1.5GHz – which is a lot of power for such a small computer!
This substantial computing power is accompanied by a generous suite of peripherals, including micro HDMI output, GPIO pins, and two ports each for USB 2.0 & 3.0. Most importantly, the Raspberry Pi 4 comes with built in WiFi, Bluetooth, and a Gigabit Ethernet port, which allows for the high speed connectivity required for fast internet.
With this, the potential of the Pi 4 in networking applications has become clear, and the stage for a Raspberry Pi Router has now been set!
1. Increase Network Bandwidth and Performance
It might come as a surprise, but the typical standard-issue routers that come along with our internet plan are often older and thus not as efficient. In fact, if you’re experiencing slow network speeds, it’s highly likely that your hardware no longer carries the computing capacity to keep up with the demands of modern network bandwidths.
While the Raspberry Pi is definitely weaker in comparison to a full-fledged desktop or laptop, its Broadcom CPU is certainly more than enough when it comes to network routing. Furthermore, you can opt for more powerful versions of the Pi with up to 8GB of RAM! Thus, a Raspberry Pi router will surely be a boost to your network and give you greater internet speeds!
2. Improve Network Security
Minimally, routers must come with firmware, which is backbone software used to achieve network routing. In most cases, such firmware is proprietary and thus closed source – meaning that there is no way to inspect the code that handles all communications in your network!
While I’m sure that router providers do put in the effort to keep their software safe for use, there’s nothing quite as comforting as deciding exactly what goes into your router. With a Raspberry Pi Router, you’ll be able to choose from free, open-source operating systems like OpenWrt that are community reviewed and maintained for security!
3. Enjoy Additional Features
With the accompanying hardware and I/O, using a Raspberry Pi as a router grants you flexibility in adding more features. For example, you could double it up as a server cum router, or even add an external drive to create a network attached storage. Furthermore, a custom router can also carry a custom operating system with additional features, like custom firewalls, VPNs or advertisement blocking services!
Introduction to OpenWrt
OpenWrt is a free, open-source project that aims to create custom embedded operating systems for routers. It is open-source, based on Linux, and a highly popular choice when building Raspberry Pi routers.
Designed by network professionals, OpenWrt incorporates many recent bufferbloat control algorithms to perform efficient and effective routing. Hence, apart from stability, it also offers reduced latency and increased network throughput for faster internet speeds! You’ll also enjoy improvements with network security, thanks to frequent updates that quickly address any vulnerabilities.
In total, you can take advantage of more than 3000 OpenWrt packages for additional functionality, including:
- Blocking advertisements directly on the router
- Encrypting your internet connection for greater privacy
- Setting quotas on download volume or bandwidth
- Creating a guest network to to allow access to internet but not local devices
- Establishing the router as a central for home automation
Like other Linux operating systems, OpenWrt is extremely configurable, so you can choose to include only what you want for your router!
There’s a lot to learn about OpenWrt and what it offers, so be sure to visit their official site for more details!
Factors to Consider for your Raspberry Pi Router
Apart from choosing appropriate software, there are also many additional challenges to getting the most of your router. Here are some questions that you should definitely ask yourself when designing your Raspberry Pi Router!
How many Gigabit Ethernet ports or USB ports do you need? How about other additional peripherals? Are you intending to utilise your router to fulfill other functions? Does your router also require wireless access point capabilities? Every setting has its unique network requirements, so it’s important to first decide upon the basic functions that your router should perform.
Like any computer, high performance and workloads generate heat. Without proper cooling, the performance of even the most powerful CPUs will be drastically limited. If your Raspberry Pi router will be working with extremely high bandwidths, you may even consider overclocking your CPU. In that case, it’s a necessity to consider either a heatsink or a fan to keep your router cool.
Routers are often left to work in the background, either in a cabinet or in the corner of a room. Hence, it’s an important consideration that routers shouldn’t occupy too much space or result in messy wiring. Thus, when picking an enclosure for your Raspberry Pi router, be sure to keep the resulting form factor and wiring arrangements in mind.
Introducing the CM4 Dual Gigabit Ethernet Board
At this point, all these considerations for a Raspberry Pi router do seem rather overwhelming, especially if we’re only just taking a first step into the world of routers. Fortunately for all of us, that’s exactly why Seeed has designed the Raspberry Pi Compute Module 4 Dual Gigabit Ethernet Board – to simplify the creation of your very own Raspberry Pi router!
What is the Raspberry Pi Compute Module?
For our friends who are unfamiliar, the Raspberry Pi Compute Module 4 is essentially a modularised Raspberry Pi 4 in a compact form factor for deeply embedded applications. This smaller yet equally powerful version of the most popular single board computer is highly flexible and convenient for building custom applications, especially if paired with a suitable carrier board.
For more information on the Compute Module 4 and how to purchase, please visit the Seeed Online Store.
The Dual Gigabit Ethernet Carrier Board for the Raspberry Pi Compute Module 4 was designed with soft router applications in mind, featuring dual Gigabit Ethernet ports and dual USB 3.0 ports. In addition, it has a rich set of I/O peripherals such as MIPI CSI, DSI and micro-HDMI for display and camera connectivity, a standard 9-pin USB 3.0 for further USB expansion, microSD card slot and FPC connector.
Despite this, the board maintains a small form factor of 75 by 64 by 21 mm that’s small enough to fit in the palm of your hand! You might also notice that it has been carefully designed to house all primary interfaces on a single side of the board, which makes plugging in wires convenient and neat for a compact Raspberry Pi router solution.
Quite simply, the Dual Gigabit Ethernet Carrier Board is a specialised all-in-one solution for conveniently building a Raspberry Pi router that further enables virtually limitless possibilities with its rich I/O!
- Compact size (75x64x21mm) with rich I/O peripherals
- Dual Gigabit Ethernet connectors for soft router applications
- Camera/ display connectivity using MIPI CSI, MIPI DSI and micro-HDMI interfaces
- Onboard dual USB 3.0 with an additional USB 3.0 9-pin header for more external ports
- Micro-SD Card slot to load system image for non-eMMC version of CM4
- More Expandability via FPC Connector (I2C, SPI)
- External fan support with fan power connector
- Power over USB Type-C
Now for the moment that we’ve all been waiting for – I’ll show you exactly how you can set up your own Raspberry Pi router with the Compute Module 4 and Dual Gigabit Ethernet Board! If you wish, you can also read this tutorial on the Seeed Wiki, which also covers several alternative methods apart from the ones that I will go through.
To follow along with today’s tutorial, please ensure that you have prepare the following materials:
- Dual Gigabit Ethernet Carrier Board
- Raspberry Pi Compute Module 4
- 16GB (or more) micro-SD card
- Micro-SD card reader
- Computer (Windows/Mac/Linux)
- Power adapter (5V/3A)
- USB Type-C cable
1. Flashing Raspberry Pi OS to the CM4
The first thing that we will need to do is flash Raspberry Pi OS to run on our Raspberry Pi Compute Module 4. In this section, I will cover only the steps for flashing to the non-eMMC version. For flashing to eMMC storage, please refer here instead.
Step 1. Insert a micro-SD card to your computer using a micro-SD card reader, or a built-in card reader.
Step 2. Download the Raspberry Pi Imager for your operating system by visiting this link.
Step 3. Open Raspberry Pi Imager software
Step 4. Click CHOOSE OS and select the latest version of the Raspberry Pi OS (32-bit).
Step 5. Click CHOOSE STORAGE and select the connected micro-SD card.
Step 6. Finally, click WRITE.
Wait for a few minutes, and the flashing should then be complete.
2. Interfacing with the CM4 via SSH
Next, we will configure our Raspberry Pi Compute Module 4, so that we can communicate with it over SSH. This section will demonstrate how to enable SSH over ethernet on a Linux system. For other operating systems or methods, please visit the Seeed Wiki.
Step 1. Insert the micro-SD card (with Raspberry Pi OS installed) to your computer using a micro-SD card reader or a built-in card reader.
Step 2. Open Terminal and navigate to the micro-SD card.
Example: cd /media/user/boot
NOTE: In the above command, you should replace user with your PC username.
Step 3. Once you are inside the micro-SD card, create an empty file called SSH by typing typing the following:
This will now enable SSH on Raspberry Pi OS.
Step 4. Eject the micro-SD card from your computer and insert it into the Dual Gigabit Ethernet Carrier Board.
Step 5. Use a USB Typc-C cable and power adapter to supply power to the carrier board.
Step 6. Use an ethernet cable to connect the carrier board to your current router. Switch the board on.
Step 7. Open Terminal on the PC again and type the following:
ssh [email protected]local
Step 8. Type yes for the following message.
ECDSA key fingerprint is SHA256:XXXXXXX.Are you sure you want to continue connecting (yes/no/[fingerprint])?
Step 9. When it asks for the password, type the following.
Step 10. If you have successfully logged into the Raspberry Pi OS, you should see the following output.
3. Ethernet Ports Configuration
The final step is to prepare our ethernet ports on the dual gigabit ethernet carrier board to begin routing network data. Once you flash the Raspberry Pi OS onto the CM4 module, you will only get full Gigabit speeds on the left Ethernet port, which is connected to the Gigabit Ethernet PHY of the CM4 module. On the other hand, the left port which is connected to the Microchip’s LAN7800 USB 3.0 to GbE (Gigabit Ethernet Bridge) will not provide the full speed of 1Gbps because the lan78xx driver in the raspberry core is not up to date.
We will now take the following steps to install a script and fix this issue:
Step 1. Enter Raspberry Pi OS Terminal window.
Step 2. Type the following to download the required files:
git clone https://github.com/Seeed-Studio/seeed-linux-dtoverlays.git
Step 3. Enter the repo directory with the following command:
Step 4. Type the following to change the repo branch:
git checkout mipi_dsi
Step 5. Now, type the following to install the script.
Step 6. Reboot the carrier board
Step 7. Type the following to check the status of the installation
dmesg | grep lan
If you see the below output, your driver is successfully working now!
Congratulations, you’ve now set up your very own Raspberry Pi router! The Seeed Wiki also carries step by step instructions for setting up other features of the dual gigabit ethernet carrier board, such as USB and camera interfaces – be sure to check it out!
Summary & More Resources
Routers, while important to the way we experience the internet and transmit information, have now largely been taken for granted. Today, I hope that I have given you the reasons and steps to improve your local network with a brand new Raspberry Pi router, which will boost your internet speeds, improve security and let you take advantage of additional features!
To learn more about routers and embedded computing, be sure to read the following articles!
- OpenWrt for Routers! – Why & How to Get Started
- Building Edge GPU Clusters – Edge Computing Guide
- Edge AI – What is it and What can it do for Edge IoT?
- How Machine Learning has Transformed Industrial IoT