How to self-host servers in your living room on static IPs - Leah Rowe's Sleepless Rants
Return to index
Article published by: Leah Rowe
Date of publication: 29 November 2022
Next >
>>
Introduction<br>[link]
Most people assume that a router is a piece of hardware, but that’s not true. The router is actually software, and the hardware is just what that software runs on. Almost anything can be a router, just like anything can be on a cob in that one episode of Rick and Morty. The laptop in the photo is my router, configured in exactly the way this guide describes.
Have you ever wanted to host a server at home or in your office, but you can’t because the ISP won’t give you static IPs? Are you behind a CGNAT? This guide is for you. It will teach you how to route static IPv4 and (native) IPv6 addresses to your network, with hosts directly pingable on the internet and all ports open. With this guide, you won’t need to host your software project on github anymore, because you can instead install gitea/cgit with a mailing list on your raspberry pi and host it in your basement or living room!
I recently moved libreboot.org hosting to a much faster network than what it had before, but the new ISP doesn’t assign static IPv4 or IPv6 subnets on the line, and it has all kinds of restrictions, though speed, uptime and latency are all excellent. I decided therefore to set up a tunnel connection using Andrews & Arnold Ltd (A&A) L2TP tunnel service. This is basically similar to most VPN services, but you get a lot more freedom and flexibility e.g. IPv4 subnets (for example, you could host your own DNS on this).
It could also just be used for normal day to day internet tasks. A&A provide you with an unfiltered service, unshaped and unthrottled in any way.
Brief technical overview<br>[link]
Adapt this guide according to your distro. Basically all we want to do is do PPP via L2TP and enable packet forwarding in Linux, so that packets can pass between two interfaces. We then set routes. We will have these interfaces:
WAN port (ethernet) - upstream ISP
tunnel port (ppp over l2tp) - physically via WAN port
LAN port (ethernet) - packets ONLY routed between it and the tunnel, NOT the WAN port directly. Routes set accordingly.
L2TP is a protocol used for to tunnel traffic on the internet. It’s quite commonly used by ISPs to connect customers up to their backend, where they then provide a PPP login.
So long as you have an ethernet port available to use for internet, your tunnel router can work nicely. If you need to, you could set up a WiFi connection or 4G tether on another machine, sharing that over an RJ45 ethernet port for your L2TP router to connect to; for example, raspberry pi USB tethered to 4G LTE service via dongle, assigned IPs presumably on NAT+DHCP, via ethernet.
Traffic will be forced, via static route, to A&A’s L2TP tunnel server. In this way, all traffic will go through L2TP and nothing else. It is completely isolated from your main network. With this setup, you can host your servers anywhere, and move them very easily.
Preparation<br>[link]
Hardware<br>[link]
You need a computer with 2 ethernet interfaces on it (RJ45). You then need to run either Linux or BSD on that. For the purpose of this tutorial, I will tell you how to configure Debian Linux, but the information here can be adapted for any other system. I really only recommend hosting this on BSD or Linux.
Interface names<br>[link]
In my case, I had these physical interfaces:
enp14s0 is configured via NAT address to normal ISP router, and static route to A&A’s L2TP server. Client-side L2TP shall connect through this
eno0 is for routing IPs from the L2TP, to a switch. this is basically my LAN port
Yours may differ, so adapt accordingly.
Getting started<br>[link]
When you first install Debian on the router, you might aswell just use the net installer. Install only the base system (Standard system utilities selected in tasksel). You might also enable SSH, if you wish.
Before you actually configure the routing, your Debian machine must have internet so that you can download packages. Alternatively, you might have apt configured to fetch them from installation media. It’s up to you, really.
You must install these packages:
apt-get install ppp pppoe xl2tpd iproute2 tcpdump net-tools resolvconf
You should install these packages BEFORE doing anything else. Just connect via DHCP or something and install these. You could also grab them from Debian installation media.
If you need a decent text editor, might I suggest Vim. As scandalous as it may seem, Debian doesn’t install it by default!
Network configuration<br>[link]
MAKE SURE you have the packages installed, as listed above, before continuing. At this point, we dive straight in and configure everything.
For our purposes, the WAN side on the router will connect to the internet via NAT, through the main ISPs network, but we will not use DHCP. Instead, a static (NAT) IP address will be specified, but with...