Using Ubuntu Server as a Router (PPPoE Dial-Up)
Introduction
Typically, routers run specialized operating systems: for hardware routers like those from TP-Link, the firmware is custom-built and closely integrated with the hardware. For software routers, OpenWRT is a popular choice. However, these dedicated router operating systems often have limited functionality and are difficult to extend. The hardware of traditional routers can also impose limitations, making it challenging to meet specific needs. Recently, the performance of small devices like NUCs and Raspberry Pis has improved to the point where they can serve as routers. Combined with mainstream Linux distributions, they allow for more flexibility and elegance in implementing router functionalities, with the added advantage of customizability. This guide demonstrates how to use Ubuntu Server as a router to achieve PPPoE dial-up, DHCP (IPv4/v6), and other functionalities, creating a reliable home router.
Installing Ubuntu Server
First, install Ubuntu Server. Download the latest Ubuntu Server ISO from the official website, create a bootable USB, and install it on your NUC or Raspberry Pi. In this guide, I used the LTS 24.04 version. The installation process is straightforward and will not be covered here.
Preparing the Network Interfaces
Assume the server has two network interfaces: enp1s0 and enp2s0. enp1s0 connects to the ISP’s modem, while enp2s0 connects to the home network.
Configuring the Network Interfaces
Ubuntu Server uses netplan by default to configure the network. Edit (or create) the /etc/netplan/01-netcfg.yaml file to configure the interfaces. Here’s a reference configuration, where the interfaces are matched by their MAC addresses to ensure stable naming:
1 | network: |
Configuring PPPoE
To optimize performance, it’s better not to use the ISP modem for PPPoE dialing, as modems typically lack performance and manageability. First, set the modem to bridge mode and delegate PPPoE dialing to the Ubuntu Server. Refer to online resources for instructions on enabling bridge mode. Install pppoeconf, a simple PPPoE configuration tool:
1 | sudo apt install pppoeconf |
Run the tool to configure PPPoE:
1 | sudo pppoeconf |
Follow the prompts to enter your ISP username and password.
Enabling IPv6 for PPPoE
By default, pppoeconf configures PPPoE for IPv4 only. To enable IPv6, manually edit the configuration file. Edit /etc/ppp/peers/dsl-provider and add the following:
1 | +ipv6 |
Dialing
Start the PPPoE connection:
1 | sudo pon dsl-provider |
Stop all PPPoE connections:
1 | sudo poff -a |
Configuring DHCP
The PPPoE connection will acquire an IPv4 address. For IPv6 support, configure DHCP. Install dhcpcd:
1 | sudo apt install dhcpcd5 |
Edit /etc/dhcpcd.conf to include the following:
1 | # Enable DHCP only on the ppp0 interface; other interfaces are managed by NetworkManager |
Start and enable the dhcpcd service:
1 | sudo systemctl enable dhcpcd |
Configuring the Firewall
To enable internet access for devices on the home network, configure NAT to forward packets from the home network to the PPPoE interface. Edit /etc/sysctl.conf and uncomment the following lines:
1 | net.ipv4.ip_forward=1 |
Apply the changes:
1 | sudo sysctl -p |
For firewall rules, we use nftables. If you’re more familiar with iptables, you can use that instead. Below is an example configuration:
1 | # /etc/nftables.conf |
Apply the firewall rules:
1 | nft -f /etc/nftables.conf |
Configuring DNS
Since DHCP is disabled on the interfaces, you must manually configure DNS to resolve domain names. Ubuntu Server uses systemd-resolved by default. Disable it and set DNS manually:
1 | sudo systemctl disable systemd-resolved |
Create a new /etc/resolv.conf file with the following content:
1 | nameserver 119.29.29.29 |
Final Steps
At this point, the router is configured. For simplicity, I opted to let a downstream WiFi router handle DHCP for the LAN. The configuration is as follows:
- Modem -> Server (WAN: public IP, LAN: 192.168.0.1)
- Server -> WiFi Router (WAN: 192.168.0.2, LAN: 192.168.1.1, DHCP)
- WiFi Router -> Devices
Improving Stability
Network disruptions or ISP issues can cause disconnections. Use a watchdog script with crontab to monitor the PPPoE service: Crontab entry:
1 | */1 * * * * bash /usr/local/bin/pppoe_watchdog.sh >> /var/log/pppoe_watchdog.log 2>&1 |
Watchdog script (/usr/local/bin/pppoe_watchdog.sh):
1 |
|
Conclusion
You now have a functional home router configured with PPPoE dial-up, DHCP (IPv4/v6), and basic firewall rules. You can further extend this setup with:
- VPN for remote access
- DNS services for LAN name resolution or ad blocking
- Advanced firewall rules for granular access control
- Traffic interception, analysis, or transparent proxying
- … and more!
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Link to this article: https://blog.axell.top/archives/using-ubuntu-server-as-a-router-pppoe-dial-up/
