Enabling IP forwarding and redirecting ports with firewalld
On this page
Goal
The goal is to use a VPS as the entry point for the homelab network flows that must be reachable from the internet. Since the homelab connects to the VPS through WireGuard, there is no need to open any ports on the router / firewall at home.
Architecture
flowchart LR
Internet([Internet])
subgraph VPS["VPS (Point d'entrée Public)"]
Firewall[firewalld]
WG_Server[WireGuard Server]
end
Internet ---|TCP 80, 443| Firewall
Firewall ---|Forward| WG_Server
WG_Server ---|Tunnel Chiffré WireGuard UDP| WG_Client
subgraph Home["Homelab (Réseau Privé)"]
WG_Client[WireGuard Client]
Services[Services Internes]
end
WG_Client --- Services Configuration steps
1. Enable IP forwarding (sysctl)
Check the current state:
cat /proc/sys/net/ipv4/ip_forwardIf the command returns 0, enable it in /etc/sysctl.conf:
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p2. Install and configure firewalld
apt install firewalld
sudo firewall-cmd --permanent --zone=public --add-forwardEdit the active zone (/etc/firewalld/zones/public.xml), adding the masquerade and the required forward-port rules, then reload:
firewall-cmd --reload
sudo systemctl start firewalldTest that the redirections work before enabling the service at boot:
sudo systemctl enable firewalldExample firewalld configuration
The homelab has no publicly routable IP address. A VPS at an external hosting provider acts as a relay: it receives incoming traffic on its public ports and forwards it, through a WireGuard tunnel, to the server at home.
firewalld config on the VPS side:
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="dhcpv6-client"/>
<service name="https"/>
<service name="http"/>
<port port="53478" protocol="udp"/>
<port port="25565" protocol="tcp"/>
<masquerade/>
<forward-port port="80" protocol="tcp" to-port="80" to-addr="10.0.3.2"/>
<forward-port port="443" protocol="tcp" to-port="443" to-addr="10.0.3.2"/>
<forward-port port="443" protocol="udp" to-port="443" to-addr="10.0.3.2"/>
<forward-port port="25565" protocol="tcp" to-port="25565" to-addr="10.0.3.2"/>
<interface name="eth0"/>
<forward/>
</zone>WireGuard config on the VPS side (the UDP port 53478 above is the WireGuard listening port):
[Interface]
PrivateKey = <>
Address = 10.0.3.1/24
ListenPort = 53478
[Peer]
PublicKey = <>
PresharedKey = <>
AllowedIPs = 10.0.3.2/32The homelab (10.0.3.2 on the tunnel side) thus receives the traffic forwarded by the VPS as if it were directly exposed to the internet, without needing to use its router’s public IP address, or a static IP.