### Programme * NFtables basics * How to debug network problems * Wireguard: easy to setup vpn * Ansible: how to manange many computers * Why have servers running at home * Internet connections technologies * How to build a linux home router --- ## Expected end result ![](assets/talosiannn.jpg) --- ## Enough joking A lot of what we are going to cover today has been done in depth in previous Linux courses (links in the relevant sections) This talk focuses more on how all these topics can come together ---- # NFtables --- ## NFtables vs IPtables vs firewalld vs others ---- # Debug network problems --- ---- # Wireguard [Link to Slides](https://slides.poul.org/2019/corsi-linux/3c_wireguard.pdf) [Link to Video](https://example.org) --- ### What is a VPN? A VPN is a piece of software that allows us to access a **Network** that is not publicly available (**Private**) and which we have no physical connection to (**Virtual**) --- ### Wireguard Project started in 2016 to replace OpenVPN, in terms of security and ease of configuration Strong Points: * Minimal codebase, ~40000 loc (originally 4000) vs 600000 for OpenVPN * Minimal configuration * Fail-open behavior, if misconfigured no packets are routed --- ### Step 1: Generating a key pair ```bash wg genkey > privatekey cat privatekey | wg pubkey > publickey ``` This needs to be done for every __host__ that wants to join the vpn --- ### Write server configuration ``` [Interface] Address = 192.168.10.1/24 ListenPort = 51820 PrivateKey = kIbuAUUbNZeC18onuKDtUui2Oa+l4/RrsU/sjcVKgmU= PostUp = nft add rule ip filter FORWARD iifname %i counter accept PostUp = nft add rule ip nat POSTROUTING oifname eth0 counter masquerade PostDown = nft del rule ip filter FORWARD iifname %i counter accept PostDown = nft del rule ip nat POSTROUTING oifname eth0 counter masquerade [Peer] PublicKey = yL4ajtwU9a2zP9vyVa5hdB5cSl/deLXv0Ldck1Y/FSU= AllowedIPs = 192.168.10.2/32 ``` --- ### Write client configuration ``` [Interface] Address = 192.168.10.2/24 PrivateKey = CCSq5ngQcIGjKS3qu5woC7tYVQM2zJhJVR4jQ9xrXUY= DNS = 192.168.10.1 [Peer] PublicKey = xopK6ZfGT0CAS8g8SXmEZf4Ppp3al5XkDJPCYl5Z8So= AllowedIPs = 0.0.0.0/0, ::/0 Endpoint = :51820 ``` --- ``` wg-quick server.conf ``` ``` wg-quick client.conf ``` --- # Done! --- ## Well not so fast Due to the fail-open nature, it is sometimes difficult to debug Some debugging techniques are shown in the previous sections. The linked slides offer a more in-depth explaination of the configuration that might help to debug problems. ---- # Ansible [Link to Slide](https://slides.poul.org/2019/corsi-linux/4b_ansible/) [Link to Video](https://example.org) --- ---- # Beyond the cloud ---- ## Why have a server at home? --- ### Server@Home * We have full control on the hardware * Advanced setups possible * Is better suited in some scenarios (eg. backup) * Usually cheaper than a server __*__ (eg. storage) --- ### Server * Usually have better uptime (much closer to 100%) * Storage has magic underneath * Usually have higher network bandwidth --- ### What to consider to do cost/benefit * On cloud servers the entire infrastructure is redundant, and if a component breaks the cloud provider replaces it free of charge, at home you have to pay for replacements * Magic ratio `kWh/Wy` -> `8.76` * High power consumption can lead to an expensive bill ---- # How to pick the hardware --- ### Storage technologies summary | | €/GB | Velocita R/W | Longevità | | - |:---- |:------------ |:--------- | | HDD | Low | Medium | Medium
(3-5 anni) | | SSD | Medium | High | High
(20+ anni) | | SD/eMMC | High | Medium-Low | Short
(1-2 anni)| | Cloud | - | Internet Speed | Infinite | --- ## SBC ARM/Router * Cost: 20-100€ * Computing power: Medium-Low * Storage: scarce (eccetto usb 3) * Power consumption: > 10W --- ## Things to consider before buying * Ethernet maximum speed (100 vs 1000) * How the ethernet chip is connected to the SoC * How the USB ports are connected to the SoC * CPU computing power * RAM quantity * Bootable storage (SD/eMMC vs USB 3/SATA) * Mainline linux support --- ## Why you shouldn't buy a RPi * 1-3 have usb ports behind an hub * 1-3 have ethernet behind an usb adapter
(guess where it is attached?) * Wifi tends to be very crappy without an u.FL connector and a proper antenna * Computing power is generally poorer than competitors for the same price point * RPi linux distributions tend to come with a lot of propietary broadcom blobs --- ## Laptop/Entry-level desktop *foto portatile nizzo* *foto router antisgamo* * Cost: 50-200€ * Computing power: Medium-High * Storage: sufficent * Power consumption: 10-50W --- ## High-End Desktop/Server *Foto server ribis here* * Cost: 100-2000€ * Computing power: High * Storage: sufficent-plenty (SAN) * Power Consuption: 200-2000W * Pros: no house heating costs --- ## I need to crunch numbers, what should I do? * Use a low-power device to trigger [Wake on LAN](https://en.wikipedia.org/wiki/Wake-on-LAN) for a more powerful device * Use a combination of Home+Cloud * Use spot/preemptible cloud VMs
(this depends on the workload) ---- # Internet connection technologies --- How do we connect to the internet? 3 main technologies: * *DSL * GPON (fiber) * Ethernet --- ## *DSL < Foto doppino telefonico > * Encompasses various technologies (ADSL/VDSL/VDSL2) * All of them use a copper medium (telephone line) to transmit data * Phone line length and EMF interference *matter* on transmission speed --- ## Router options for *DSL * Lantiq-based routers ( [list](https://openwrt.org/docs/techref/targets/lantiq) ) * No one else since the DSL chipset is usually custom-made and manufacturers don't relase the source code * Some routers allow enough configuration to be ISP-neutral, but that comes at a cost of old software * In theory _Modem Libero_ should allow the use of old ISP routers, but I wouldn't hold my breath on that --- ## GPON (fiber) < foto filo fibra > * New technology used for FTTH (1 GB/s internet) * There is a direct optical link between the end user and the ISP * Since the transmission is optical, no interference! * Optic fiber crimping has some tooling costs (~200€) --- ## ONTs < foto ONT padella > < foto ONT stick > A ONT is a device that bridges a fiber link to ethernet (allowing us to use any device we want as a router) AFAIK there is no ONT with OpenWRT support --- ## Raw Ethernet < foto cavo eth > Some provides (eg. Eolo) use alternative transmission mediums, usually these will have an ordinary ethernet cable attached to a mundane wifi router ---- # Deploying a FOSS router at home --- ## Materials needed: * A device to interface with your internet * Some ethernet cables (crimping tools recommended) * A device with 2+ ethernet ports (1 works on some setups but don't) * WiFi device --- ## Small digression: Modem Libero At the end of 2018 the AGCOM (italian telecomunications agency) approved a set of rules that force ISP to provide appropiate means to allow consumers to choose their own router (ONT are still part of the ISP's network) Obtaining the various settings for connecting to the ISP's network varies by difficulty and amount of call centers you have to contact based on the ISP you pick _(there was also a clause that allowed consumers to have a vendor-neutral firmware at the end of the contract, but everyone seems to have forgotten about that)_ --- ## Connecting to the ISP There are 2 main ways in which you connect to ISPs * PPPoE over VLAN: used by basically everyone * DHCP over raw ethernet: used only by Fastweb Obviously neither methods is within spec, both use some *slight* change in protocol parameters, which may need some fiddling --- ## IPv6 Currently (April 2020), only 2 ISPs provide IPv6 connectivity * Fastweb: via [6rd](https://en.wikipedia.org/wiki/IPv6_rapid_deployment) * Telecom Italia: via a separate PPPoE connection However do note that both these tunnels might not support the full bandwidth --- ## What software to use? * ppp for connecting to PPPoE * Systemd-networkd for managing connections (only network manager that supports most ISPs configurations fully)