acordier's personal website

How to configure a Ubuntu home server as a modem and router (1/3)

2023/08/11

Tags: networking, router, modem, server

In the past couple of weeks, I became interested in trying to understand what it would take to get rid of both my ISP modem (a Freebox Mini 4K) and my router.

Since I already own a server at home running Ubuntu Server for various services (website, media streaming), I wondered whether it could incidentally replace both my modem and my router, like schematized below:

Regarding the modem, things seem to be already well documented for my ISP (Free – see links below). The main trick here is to tag all incoming and outgoing packets with VLAN 836, which is required by my ISP to communicate. There is also a second trick specifically needed for IPv6 connectivity, since Free does not handle “true” IPv6. Instead, they use a IPv6-in-IPv4 tunnel-like implementation, which they call 6rd.

Once the server can directly access the internet, getting rid of the router should not be too difficult, since most of the task will consist in configuring internal routes within the server, so that IPv4 and IPv6 connectivity on the main interface can be shared to other interfaces, such as a home Wi-Fi network.

In this blog series, we will step-by-step

Going through the above and trying to grasp all of the concepts behind gave me a great introduction to the bases of setting up, configuring, and troubleshooting networks with Unix-based systems. Overall, I would say this was a very worthy experience, even though painful at times.

Part 1: replacing the Freebox and getting IPv4/IPv6 connectivity with netplan

Table of contents

The hardware side

Installing netplan

Configuring netplan for IPv4

Configuring netplan for IPv6

Troubleshooting

The hardware side

First of all, one should note that the Free ISP provides an optical fiber connection to my home. I used the SFP module originally provided with the Freebox modem with a TP-Link MC220L converter, since the Ubuntu computer I use does not have any SFP input. This way, the TP-Link converter “converts” the optical fiber signal to an RJ-45 (ethernet) signal, which can then be read the machine. If you already have a machine with SFP connectivity, there should be no need for such a converter.

If you plan on buying your own SFP module, I would strongly recommend first checking out whether it is compatible with your ISP provider or not.

Installing netplan

netplan is a recent network package for Ubuntu which allows to configure both the NetworkManager (for machines running regular Ubuntu) and the systemd-networkd (for machines running Ubuntu Server). If you are using an Ubuntu version higher than 18.04, netplan should already be installed and set as the default way to configure network interfaces.

Configuring netplan for IPv4

Edit the netplan .yaml configuration file located in /etc/netplan/. The top should look like the following:

/etc/netplan/00-installer-config.yaml

network:
  version: 2
  renderer: networkd

If for some reason you wish to use the NetworkManager instead of the systemd-networkd renderer, simply change the renderer parameter to NetworkManager.

Now, let’s start writing an actual configuration.

First, you will need to know the name of your main ethernet interface (the one connected to the outside network). To list all enabled (up) network interfaces of the machine, you can run: ifconfig

If the interface you are looking for is down, you can find it back with: ip a and enable it with: ifconfig <INTERFACE_NAME> up

Usually, the name for the main ethernet interface is either eth0 or eno1, though this may change depending on your hardware.

We will write the following configuration:

/etc/netplan/00-installer-config.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: true
  vlans:
    vlan1:
      id: 836
      link: eno1
      dhcp4: true

The above specifies that we want to use DHCPv4 for our eno1 interface. We do this because DHCP (Dynamic Host Configuration Protocol) is how Free ISP attributes IPv4 addresses. If your ISP instead works with a static IP configuration, you can set dhcp4: false and use the addresses and gateway4 properties. See the Netplan documentation for more details.

The configuration also specifies a VLAN which will be created on the eno1 interface, with ID number 836. Tagging packets this way is mandatory so that the server can communicate with Free. Note that different ISPs will have different VLAN IDs for tagging, so you should do your own research for that matter.

For some reason, you need to also specify dhcp4: true in the VLAN section. Furthermore, the VLAN (and bridges) section should be at the end because of a parsing bug in netplan.

When you’re done editing, save the file and run the following commands to:

sudo netplan generate
sudo netplan apply

Your server should now have access to the internet!

To make sure it is the case, you can ping Cloudflare: ping 1.1.1.1

Configuring netplan for IPv6

Configuring IPv6 with Free was more complicated than what I expected. IPv6 is the most recent version of the IP protocol, which is intended to replace IPv4.

You may be luckier than I am and have your ISP work with “true” IPv6, making this part much easier.

Free uses a technology called IPv6 rapid deployment or 6rd (a derivative of 6to4, which is itself a protocol that allows to make IPv6 packets transit through IPv4).

This means that the Freebox modem normally establishes a tunnel with a remote Free IP (the same for all Free ISP subscribers). Luckily, there’s a relatively simple way to make this work with netplan:

/etc/netplan/00-installer-config.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    eno1:
      dhcp4: true
  tunnels:
    tun0:
      mode: sit
      remote: 192.88.99.101
      local: <MY_PUBLIC_IPV4>
      mtu: 1480
      ttl: 64
      routes:
        - to: default
          via: <MY_IPV6_PREFIX>
  vlans:
    vlan1:
      id: 836
      link: eno1
      dhcp4: true
    vlan2:
      id: 836
      link: tun0

In the configuration above, we defined a new tunnel interface called tun0. We need to specify:

We also tag IPv6 packets with VLAN 836, similarly to what we did for IPv4.

Save the configuration file, run sudo netplan generate and sudo netplan apply once again. If everything went well, you should be able to ping Cloudflare via IPv6: ping6 2606:4700:4700::1111

Congratulations! If you’ve made it this far, the machine you configured now acts as a modem which can connects to the outside internet!

In part 2, we will see how to configure a light DHCP (for IPv4) and SLAAC (for IPv6) server in order to broadcast the internet connection to a home Wi-Fi network, using dnsmasq and hostapd.

In part 3, we will focus more on DNS resolution and how to set-up DNS-over-HTTPS.

Troubleshooting

If anything goes wrong, here are a couple commands you can try in order to get a better understanding of what’s happening.

To list enabled interfaces and their assigned IP (and MAC) addresses:

To assess the status and look at the last logs of networkd:

To ping an IP with a specific interface:

To trace the route of packets to a target IP:

To monitor packets (in and out) for a interface:

If you have any questions or wish to discuss a personal issue of your own, do not hesitate to contact me.

Massive thanks to the people who wrote the different guides in the links below. They helped me a lot.