Home-made PC Router and NAS Server [Page 1] - Introduction and Hardware

Picture of server inside

UPDATE September 2023: This guide should generally work fine for Ubuntu Server LTS 22.04 as well as 20.04.

Many routers exist these days, as do many dedicated NAS systems. I, however, wanted to improve performance and reliability of these devices, and gain the know-how to build my own.

Over the years, this started as a NAS at first, and then recently evolved to become a router as well as a NAS.

The latest evolution brings my previous build up to date with Ubuntu's Long-term support offerings, version 18.04 and 20.04. This guide is applicable to both versions. It also uses the latest router/network options (netplan) and logical volume management for disk setup and snapshots.

In this write up - I'll take you through the complete build for both a router and a NAS built around a 64-bit Personal Computer and Open-Source software.

Before we start though - what would I consider the requirements for a router, and a NAS?

Router

Well, a router for me actually needs to be simple - it needs to be able to forward traffic from many Internet connected devices inside my home (on my Local Area Network or LAN) to my one outgoing cable to the Internet, via my Internet Service Provider (ISP).

Each of my devices (PCs, laptops, Phones, Smart devices etc.) have their own Internet Protocol (IP) address, but my Internet connection has only one, so to allow them access to the Internet, my router needs to do Network Address Translation (NAT).

Along with NAT, my router may also need to open pinholes (or ports) from my public IP address to specific services inside my LAN (such as telephone connection, which uses VOIP).

The one other thing I require from my router is an ability to dynamically assign unique IP addresses to everything that connects to my LAN. DHCP (Dynamic Host Configuration Protocol) can do this. Without DCHP, we'd need to enter a unique IP address, subset, gateway and DNS addresses into every device in order to access the Internet.

So, NAT (with port forwarding) and DHCP. That, in a nutshell, is all I really require from a router. And I suspect it is all most people need too. But it should be flexible for me to add things in future.

NAS

What do I need from a NAS? NAS is simply 'Network Attached Storage', and that is all I want to do at a basic level - make storage (disk space) available to my LAN. It should perform fast, be secure and be resilient.

Though if you spend decent money, you can get good commercial hardware, the curious brain inside me wanted to build a complete 'server', which has the flexibility to host services (such as a NAS service), as well as route traffic.

Why not just buy them?

Commercial routers and NAS systems are available cheap, but they are quite slow due to the lack of hardware capability. To get a good router, you need to spend upwards of £100, and the same again for a good NAS. Reliability can also be a problem - the router I replaced would sometimes stop working properly, losing Internet access, or failing to hand out IPs to devices.

Security is also a problem - I see increasing amounts of reports of all sorts of routers being hacked into, and it's often not automatic to keep them up-to-date and secure, and even when it is, that's another door a hacker could open.

Being a complete PC, I can also use it to perform other functions - such as hosting virtual machines, media servers and a VPN.

The other reason is the general DIY reason - learning, and a sense of achievement.

My Project

My project is very much a home solution - it is not for the office or commercial use, but you may feel free to attempt it. It's also very much my own consolidation of many articles I've read online.

This project came in two stages, and then was rebuilt for the most optimum configuration.

The first inspiration was to build a NAS and get some familiarity using Linux as a server. This started over three years before creating a router from it.

It ended up with a Linux desktop OS - Linux Mint, having Samba configured on it and a configuration of drives that let me store data and make it available to the LAN. I also added my own VPN later on to it, so I could access UK services (mainly TV!) whilst I was in Japan for a few months.

In early 2016, an article on how a homebrew router improved speed was also published on Ars Technica - one to the great tech sites I frequently read: http://arstechnica.com/gadgets/2016/01/numbers-dont-lie-its-time-to-build-your-own-router/

Articles followed later to help you build it and I had planned for many months to do the same with the hardware I already had.

My latest build had a complete hardware update and install of Ubuntu 20.04.

The hardware

In September 2020 I finally decided to modernise the hardware. The system is still built in the same InWin BM639 Mini ITX case, but now runs an Intel Core i7 10700 processor (2.90 GHz base, 4.80 GHz turbo, eight core, sixteen thread) with 32GB of DDR4 RAM running in a ASRock B460M-ITX motherboard, with an ADATA XPG SX8200 Pro 1TB SSD for OS and storage.

That sounds expensive, but still the complete system build wouldn't be much more than £700. No graphics card is required, which is the only reason I went for an Intel build over AMD - the equivalent Ryzen build would need a graphics card, which would occupy the only PCIe slot you can have on a Mini-ITX motherboard.

You don't need to spend that much though. Prior to my upgrade, my old hardware was still well-up for the task of a router and NAS with some other services! I only upgraded for better virtual machine performance. My previous processor was a 2012 - Intel 'Ivy Bridge' Core i7 3770S. Having brought a Sandy Bridge laptop in 2011, I was always impressed in the great leap of performance this gave and continued to invest in that hardware platform by buying Mini ITX hardware. Ivy Bridge is a small evolution of Sandy Bridge and uses the same socket so with a BIOS upgrade, many motherboards are compatible. This server was originally running on a Core i3 2100T, and I only upgraded it because the Core i5 3475S and then an i7 3770S as these CPUs came from different desktops I upgraded!

Mini ITX is a great platform allowing you to build small machines, but still with a full-size processor, RAM and enough I/O ports. For the server build, I was unsure how well it would work so I brought the cheaper versions of most things originally!

So here is list of what I used:

Latest build:

  • CPU - Intel Core i7 10700 (64-bit octa core with hyperthreading, 2.9GHz processor, up to 4.8GHz, 16M cache). This has a default thermal limit of 65W which is a good limit for Mini-ITX systems. Many Mini-ITX cases and PSUs will only support 35W TDP processors, and my first CPU was an Intel Core i3 2100T.
  • Motherboard - ASRock B460M-ITX. Intel change their socket on every new generation, so I decided not to spend much on the board. To catch you out, boards with B460 chipsets limit the RAM speed. For i3, i5 processors, it's 2666MHz, but for i7 it's not too bad at 2933MHz. Get RAM with low latency (CL) to compensate! The board has a PCIe 3 NVMe slot for fast SSDs, and PCIe 16x slot for expansion (network card will go here) and four SATA ports to connect the rest of my drives
  • RAM - DDR4 Corsair CMK32GX4M2B3000C15 Vengeance LPX 32 GB (2 x 16 GB) DDR4 3000 MHz. It'll run a little less than 3000MHz due to Intel B460 limitations but still runs fast. 32GB gives plenty of RAM to allow me to run multiple VMs at the same time.
  • Drives - ADATA XPG SX8200 Pro 1TB M.2 for the OS and VM storage
  • Drives - Two 1TB Crucial MX500 SSD drives, and a 250GB MX500 SSD, all for files. 1x Seagate 2TB 2.5-inch hard drive for backup.
  • HP NC360T Dual-Port Gigabit NIC (low profile). These ex-server network cards are cheap second hand and are hardware accelerated meaning CPU usage is low when pushing lots of data in/out of the network ports.
  • Still in the InWin BM639 Mini ITX case

Previous build:

  • CPU - Currently Intel Core i7 3700S (64-bit quad core with hyperthreading, 3.1GHz processor, up to 3.9GHz, 8M cache), but previously Intel Core i5 3475S (64-bit quad core, 2.9GHz processor, up to 3.6GHz, 6M cache). Both 65W.
  • Motherboard - originally Gigabyte GA-H61N-D2V (cheapest at the time), but now an Intel DH61DL. These are socket LGA1155 Mini ITX sized motherboards, with two full size DDR3 RAM slots. For some amusing reason they come with plenty of hardware from the 00's and 90's - parallel port, serial port, PS/2 ports and the Gigabyte board also came with PCI (32 bit, not PCI-E) slot. USB 2.0 is there, but not USB 3.0. Importantly, both do have one 1Gbps LAN interface built in.
  • RAM - DDR3 Patriot Viper 2x8GB 1600MHz. This is the most the CPU/Motherboard supports. Previously Crucial dual channel 2x4GB sticks was used, so 8GB total. Before that I used only 2GB RAM for NAS duties, and for NAS/Router duties, you don't need more! Again, running Virtual Machines is why I wanted 16GB RAM.
  • Drives - A 120GB SSD from my laptop I used from 2011 to 2013 - this is an OCZ Agility 3. Also 2011 hardware, but still pretty fast and boots Linux in just a few seconds and still working fine in 2020.
  • Drives - Two 1TB Crucial MX500 SSD drives, and a 250GB MX500 SSD, all for files. 1x Seagate 2TB 2.5-inch hard drive for backup. Originally there was 2x Seagate 2TB drives (RAID 1 mirrored) but one failed
  • HP NC360T Dual-Port Gigabit NIC (low profile) now I have a PCIe motherboard, with the slot cut so it fits in a PCIe 1x slot. Originally had a D-Link DGE-528T Gigabit PCI (not PCIe!) 1Gbps Network Card for the Gigabyte board.
  • To get the extra SATA ports, a two port Mini-PCI-E to SATA converter fits nicely into where the Wi-Fi card is supposed to go in the Intel DH61DL. As this motherboard only has three SATA ports, this gives me a total of five.

If you're buying the hardware now, you probably be able to get new hardware that is power efficient. Equally, if you already have even older stuff, it could already work well! Carefully consider the right value for your project - don't spend too much! But be wary of soldered (non-upgradeable), low power processors such as Intel Atom, Celeron, and AMD AM1 - the 2012 Core i5 I was using would outperform these! A Core i3 2nd generation or later is ideal, and modern Celerons are also fine. If you're using a Micro ATX case, an AMD Ryzen build with a cheap graphics card will work well. Even a Mini-PC with two network ports would work well too (Zotac ZBOX CI640 or similar), but you'll need USB hard drives/SSDs for the NAS part.

The InWin BM639 case is fairly large for Mini ITX (and will even take Mini DTX, as known as some very small micro-ATX motherboards) but is a good compromise. This server has been in three cases - the first one was far too large, second was too small and got uncomfortably warm. The case has lots of room for drives too - if I brought the right adaptors, I'd be able to squeeze six 2.5" hard drives! Many cases were also not an option due to the absence of PCI/PCIe card slots (something I needed to install an extra network adaptor).

The case has been tweaked with a different outlet fan at the top of the case (since the cheap one that came with the case failed!), and a smaller 60mm intake fan at the back was added so there is some airflow over the motherboard itself.

Network Connections

It is important that you have two network ports. You cannot make a router otherwise! Most motherboards come only with one, so if you don't get one with two, make sure you have a PCI or PCI-express spare to use. A USB network port adaptor might work too, but latency and throughput could be worse, especially if its USB 2.0 or worse.

For me, I had the ancient PCI slot originally - these were around in 1992! They can reach 133 MB/s though, so a Gigabit Network Interface Controller card (NIC) does work, but under testing I discovered it is limited to about 500MBit/s in reality, and hence I originally used it for my Internet connection (which is max 150MBit/s). A PCIe (PCI Express) slot will work better if your hardware has it instead.

If you're building a small system in a case like mine, get a low-profile card. Do also check there is good support for Linux. As mentioned, I recommend the HP NC360T or similar Intel 82571EB card. It's a PCIe 4x card, but if you have only a PCIe 1x slot - cut the connector with a junior hacksaw and it'll work fine still!

A PICe 4x card can be cut to fit a 1x slot

For cabling, here is what you should aim for:

network-cabling-final.png

In its final configuration, your PC will have two LAN ports - one will be considered a WAN port, where the Internet connection is plugged in, the other is a LAN port. This will lead a to Network Switch (I use a 5 port D-Link Go) and the rest of your LAN.

Wi-Fi?

This is one thing pretty much all commercial / home routers come with - Wi-Fi support. My home build will not though. PC Wi-Fi cards are not designed to accept multiple connections, acting as an access point, so you're better off getting real hardware to do it.

Given I was to swap out my existing router, I decided to jump to a more professional wireless access point, and I recommend the Ubiquiti Unifi AP-AC Lite.

This I mounted on the ceiling in the hallway of my flat and I get a full signal on every device in every room. It doesn't create split 2.4GHz and 5GHz networks either - all 5GHz compatible clients will automatically connect at the higher speed.

Any other wireless access point with a LAN port should also work well. Make sure you get wireless AC (aka Wi-Fi 5, or wireless AX aka Wi-Fi 6) and forget Wireless N (Wi-Fi 4), especially if you live in flats where the airwaves are congested from everyone else's Wi-Fi - it is not fast enough!

You can also use an existing router, just disable everything else on it so it behaves like a Wi-Fi access point. Plug your LAN into the LAN ports, not the WAN.

Software - Operating System

I used the latest LTS (long term support) edition of Ubuntu for the Operating System (O/S), version 20.04. Linux has a huge community following and is extremely popular. It is also open-source and free to use, updates quicker and is generally considered to be more secure than Windows.

Linux has a vast number of distributions. A lot of the steps here are applicable to most of them, but there are variances I won't cover. Installing software will be one such variations where I will show commands for 'apt' which will apply to Debian, Ubuntu, Linux Mint and others, but not to Slackware, CentOS, Arch, Mandriva, Clear or many others. I picked Ubuntu as it's got a huge community around it, making it easier to find solutions to problems.

The key services, my host would contain are:

  1. IPTABLES - to perform NAT, forwarding and firewall duties, acting as a router
  2. DHCP - provides IP addresses for any laptops, phones, TVs, consoles etc connected to my LAN
  3. Samba - this is the NAS element and allows me to share my hard drives to LAN PCs (mostly Windows), easily and with password security
  4. SSH - for administration
  5. OpenVPN - for connecting remotely, securely and masking my location

In my original build, I used a separate VM for routing duties, however this was sometimes unreliable and was inconvenient to patch. In the original build I also used a desktop flavour of Ubuntu (with GUI).

In this build, all services are on the bare-metal machine, and I'm using a Server Edition of Ubuntu 18.04 Long-term support, with no GUI.

Read on...

You can find more details of the build, on these pages: