How to turn anything into a router

A guide on repurposing old hardware or mini-PCs into functional Linux-based routers, demonstrating that specialized hardware isn't always necessary for networking.
How to turn anything into a router
I don’t like to cover “current events” very much, but the American government just revealed a truly bewildering policy effectively banning import of new consumer router models. This is ridiculous for many reasons, but if this does indeed come to pass it may be beneficial to learn how to “homebrew” a router.
Fortunately, you can make a router out of basically anything resembling a computer.
I’ve used a linux powered mini-pc as my own router for many years, and have posted a few times before about how to make linux routers and firewalls in that time. It’s been rock solid stable, and the only issue I’ve had over the years was wearing out a $20 mSATA drive. While I use Debian typically, Alpine linux probably works just as well, perhaps better if you’re familiar with it. As long as the device runs Linux well and has a couple USB ports, you’re good to go. Mini-PCs, desktop PCs, SBCs, rackmount servers, old laptops, or purpose built devices will all work.
To be clear, this is not meant to be a practical “solution” to the US policy, it’s to show people a neat “hack” you can do to squeeze more capability out of hardware you might already own, and to demonstrate that there’s nothing special about routers - They’re all just computers after all.
Hardware selection
My personal preference is a purpose-made mini PC with a passively cooled design.
However, basically anything will work. It should have two Ethernet interfaces, but a standard USB-Ethernet dongle will also do the trick. It won’t be as reliable as an onboard interface, but will probably be good enough. For example, this janky pile of spare parts can easily push 820-850mbps on the wired LAN and ~300 mbps on the wireless network.
This particular device is a Celeron 3205U dual core running at a blistering 1.5 GHz. Even that measly chip is more than capable of routing an entire house or small business worth of traffic.
Going back even further, this was my setup for the first couple weeks of the fall 2016 semester:
- A ThinkPad T60, trash picked from my previous job
- An ExpressCard-PCIe bridge in the ThinkPad’s expansion bay
- A trash-picked no-name Ethernet card in the PCIe slot, missing its mounting bracket
- An ancient Cisco 2960 100 mbit switch, purchased for $10 from my college
- A D-Link router acting as an access point (“as-is” thrift store find with a bad WAN port)
Yes, this is indeed a router! It probably looks like a pile of junk, because it is, but it’s junk that’s perfectly able to perform the job I gave it!
How does it get configured?
When set up, the system will be configured like this:
| Interface | Network | |---|---| | eth0 | WAN | | eth1 | LAN (Wired) | | wlan0 | LAN (Wireless) |
Both LAN interfaces will be bridged together, meaning that devices on the wired and wireless networks will be able to communicate normally. If one LAN port isn’t enough, you can plug in as many USB Ethernet dongles as you need and bridge ’em all together.
As mentioned before, this will run Debian as the operating system, and uses very few pieces that don’t come with the base install:
hostapd: For creating the Wi-Fi networkdnsmasq: For DNS & DHCPbridge-utils: For combining ports into a common network
Also, I should mention that I’ll only be setting up IPv4 here. IPv6 works great for stuff like mobile devices, but I still find it too frustrating inside a LAN.
Install & Setup
Overall, it’s a pretty standard Debian install. A couple things I should mention:
- Disable PXE network boot in the BIOS/UEFI setup.
- If you can, set the device to the lowest clock speed, but disable any power management for USB or PCI devices.
- Find the option like “Restore after AC Power Loss” and turn it ON.
- Some devices won’t properly power up if there’s no display connected. If your device is like this, stick a “dummy dongle” into the HDMI port.
Install the required packages
After the initial install is done, there are some additional utilities to install:
sudo apt install bridge-utils hostapd dnsmasq
Name the interfaces properly
In modern Linux systems, the network interface names are named based on physical connection and driver type, like enp0s31f6. I find the old format, like ethX much simpler, so each interface gets a persistent name.
For each network interface, create a file at /etc/systemd/network/10-persistent-ethX.link:
[Match]
MACAddress=AA:BB:CC:DD:00:11
[Link]
Name=ethX
Configure the interfaces
The “outside” interface will be the WAN, and the “inside” will be the LAN. Note that the LAN interface does not get a default gateway.
/etc/network/interfaces:
allow-hotplug eth0
allow-hotplug eth1
auto wlan0
auto br0
iface eth0 inet dhcp
iface br0 inet static
bridge_ports eth1 wlan0
address 192.168.1.1/24
IP Forwarding
Create /etc/sysctl.d/10-forward.conf and add this line to enable IP forwarding:
net.ipv4.ip_forward=1
Firewall rules
The firewall rules and NAT configuration are both handled by the new netfilter system in Linux. We manage this using nftables.
Source: Hacker News












