From b47e81791dbf2e02f04080ff0f09895783c89f1d Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 18 Jul 2024 17:26:12 +0200 Subject: [PATCH] feat: add IPv4 support for WireGuard configuration Updated configuration script to include IPv4 rules alongside existing IPv6 rules for iptables. This ensures that both protocols are properly handled, enhancing network versatility and compatibility. Enabled IPv4 forwarding in sysctl to support the new rules. --- worker.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/worker.py b/worker.py index f10e3c8..500c9dd 100644 --- a/worker.py +++ b/worker.py @@ -313,14 +313,17 @@ PersistentKeepalive = {persistent_keepalive} ssh_execute_command(server_ip, f"echo '{wg_config}' > /etc/wireguard/wg0.conf") ssh_execute_command(server_ip, "wg-quick up wg0") - # Configure ip6tables - ip6tables_rules = [ + # Configure ip(6)tables + iptables_rules = [ "ip6tables -A FORWARD -i wg0 -j ACCEPT", "ip6tables -A FORWARD -o wg0 -j ACCEPT", "ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE", + "iptables -A FORWARD -i wg0 -j ACCEPT", + "iptables -A FORWARD -o wg0 -j ACCEPT", + "iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE", ] - for rule in ip6tables_rules: + for rule in iptables_rules: ssh_execute_command(server_ip, rule) @@ -360,6 +363,7 @@ def main(provider, location, server_type): "apt update", "apt install -y wireguard", "echo 'net.ipv6.conf.all.forwarding=1' >> /etc/sysctl.conf", + "echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf", "sysctl -p", ]